SpaceHAL Robotics and Arduino Documentation
website·Indexed 29 days ago
https://spacehal.github.io/Educational documentation covering Arduino programming, robotics fundamentals, and the Pololu Zumo 32u4. Includes guides on PWM, IMUs, gyroscopes, line sensors, and motor control, featuring specific API references such as readBatteryMillivolts(), getCountsLeft(), and setLeftSpeed().
What's inside SpaceHAL
- The Zumo32u4 features three IR proximity sensors (Left, Front, Right) used to detect nearby objects or obstacles. Unlike line sensors, these do not have integrated IR senders; instead, they detect reflected IR light emitted by four IR-LEDs on the mainboard (Front-Left, Front-Right, Middle-Left, and Middle-Right). To avoid interference from ambient light, the IR light is modulated at approximately 38 kHz. These sensors can also be used to receive commands from standard IR remote controls.
Understand the interaction between current-carrying wires (Ampère's Law)
André Marie Ampère expanded on Oersted's work in 1820, demonstrating that two wires carrying electrical currents exert forces on one another, causing them to either attract or repel each other.Control DC motors using the L293 motor driver
The L293 is a motor driver IC containing two H-bridges, allowing it to control two DC motors independently. It requires two separate power supplies: Vcc1 for the internal control logic and Vcc2 for the motors themselves. Speed is controlled via the enable pins (EN1,2 and EN3,4), while direction is determined by the input pins (1A, 2A and 3A, 4A).Understand IR sensor principles for obstacle and line detection
An infrared (IR) sensor detects obstacles or lines based on the reflection of light. An IR light source emits light, and a receiver detects the intensity of the reflected light. The amount of reflected light depends on the distance to the surface, the surface material, color, and orientation. Because of these variables, simple IR sensors are primarily suitable for obstacle or line detection rather than precise distance measurement. IR light (typically around 950 nm) is used to minimize interference from other light sources like sunlight or artificial lighting.Understand the basic components of a Control System (Regelkreis)
A control system is used to maintain a system at a desired target value. It consists of the following key components:
- Setpoint (Sollwert) $w(t)$: The desired target value (e.g., a specific sensor value for a line edge).
- Measured Value (Messwert) $y(t)$: The actual current value measured by the sensor.
- Control Deviation (Regelabweichung/Error Term) $e(t)$: The difference between the setpoint and the measured value, calculated as $e(t) = w(t) - y(t)$.
- Controller (Regler): Determines the manipulated variable based on the error term.
- Manipulated Variable (Stellgröße): The output from the controller that acts upon the system.
- Plant/System (Regelstrecke): The physical system being controlled (e.g., the robot).
Understand Arduino Analog-to-Digital Conversion (ADC)
Arduino boards feature analog inputs (labeled
A0,A1, etc.) that use an Analog-to-Digital Converter (ADC) to convert voltage between 0V and 5V into discrete integer values. For the Arduino UNO, the 10-bit ADC converts the input voltage into a range from 0 to 1023. The sampling rate is approximately 10,000 conversions per second.Warning: The input voltage at analog pins must not exceed 5V.
Implement Object-Oriented Programming (OOP) in Arduino
Object-Oriented Programming allows developers to create 'Classes' as blueprints for 'Objects'. This is particularly useful for managing multiple similar hardware components (e.g., multiple LEDs) without declaring numerous global variables for each pin and state. Each object can hold its own attributes (variables) and methods (functions).Understand basic odometry principles for differential drive
Odometry determines a robot's position $(x, y)$ and orientation $\vartheta$ based on propulsion system data (wheel encoders).
- Position and orientation can only be determined relative to the last known state $P = (x, y, \vartheta)$.
- The orientation $\vartheta$ is relative to the x-axis (e.g., North = $90^\circ$ or $\pi/2$).
- New position $P' = (x', y', \vartheta')$ is calculated by adding the change in position $(\Delta x, \Delta y, \Delta \vartheta)$ to the origin position.
Understand switch bouncing in Arduino
Switch bouncing occurs when a mechanical button is pressed; the contacts do not make a clean connection immediately but instead 'bounce' rapidly between HIGH and LOW states for a short period (typically around 30ms). This can cause a microcontroller to register multiple presses for a single physical action. To prevent this, a 'debounce' mechanism is used to ignore rapid state changes and ensure only one action is triggered per press.Understand the fundamental principle of electric motors (Oersted's Discovery)
The basic principle of the electric motor is based on Hans Christian Oersted's 1820 experiment, which demonstrated the fundamental relationship between electricity and magnetism. Oersted observed that an electrical conductor carrying a current deflects a compass needle; the strength of the deflection increases proportionally with the amount of current flowing through the conductor.Determine rotation direction using a Quadrature Encoder
A quadrature encoder uses two sensors (A and B) offset in space to determine the direction of rotation based on which sensor triggers first.
- Clockwise Rotation: Sensor A detects the state change first. When sensor B changes state, the condition
B = !Ais true. - Counter-Clockwise Rotation: Sensor B detects the state change first. When sensor B changes state, the condition
B = Ais true.
- Clockwise Rotation: Sensor A detects the state change first. When sensor B changes state, the condition
Understand Finite State Machine (FSM) concepts for Arduino
A Finite State Machine (FSM) models behavior based on a finite number of states, actions, and transitions.
- States: Store information or status (e.g., a variable indicating if an LED is ON or OFF). States alone do not change the system; an action is required.
- Actions: The operations that change the state of the FSM (e.g., calling
digitalWrite()to change an LED's status). - State Transitions: The logic (usually
if-elseorswitch-caseblocks) that defines the conditions under which the system moves from one state to another.