-
Notifications
You must be signed in to change notification settings - Fork 48
Arduino
The default configuration uses an Arduino Pro Mini connected to a custom PCB.
The PCB is designed to connect the Raspberry Pi, Arduino, servos and MPU6050 to the power management board safely. See the Electronics section for more information.
The arduino sketch is designed to run independently of the Raspberry Pi, and is responsible for controlling the servos and reading the MPU6050 and battery voltage.
The connection to the Raspberry Pi is optional, but allows servo positions to be set and the battery voltage to be read as required. In the absence of a connection, the arduino will continue to run the servos and animate the robot independently. This is useful if the Raspberry Pi is not available, or if the robot is being used in a 'headless' mode (no pun intended) for demonstration or to prolong battery life.
The Config.h
file contains the configuration for the arduino sketch. This includes the servo ranges, initialisation positions, and pin assignments.
The servo ranges are defined in both the modules/config.py
file and the arduino_sketch/Config.h
file. These must match your hardware setup.
Once the servos have been initialised, the arduino software prevents the servos to move outside of these ranges. This is to prevent damage to the servos and robot.
Can be installed via the arduino IDE:
- Servo
- ServoEasing
- Adafruit_MPU6050
The arduino sketch is split into modules, each of which is responsible for a specific task. This allows the sketch to be easily extended and modified.
-
arduino_sketch.ino
- The main sketch file. This contains the setup and loop functions, and initialises the modules. -
ServoManager.h
- The servo controller module. This is responsible for initialising and controlling the servos. -
InverseKinematics.h
- The inverse kinematics module. This is responsible for calculating the servo positions for a given set of angles. -
PiConnect.h
- The Raspberry Pi connection module. This is responsible for initialising the serial connection to the Raspberry Pi, and reading and writing data to the serial port. -
Order.h
- Required by the PiConnect module. -
Config.h
- The configuration file. This contains the servo ranges, initialisation positions, and pin assignments.
The IK module is relatively simple, currently only a single axis is calculated (leg height between angle and hip). These values are then updated with offsets to convert the angle calculations to actual servo positions taking into account the range and initial position.
Because of the safety checks in the servo manager, the IK module is not able to move the servos to an invalid position that will damage the robot.
In both Archie and Buddy, the pi connection used a serial management library.
This module uses the Order.h
constants to determine the type of data being sent between the arduino and pi and what type of value to expect.
Due to a voltage divider on the custom PCB, the A0 pin of the arduino is fed the current supply voltage from the robot. If this is a battery the value will fluctuate between a min and max range mapped between 0 and 1024 in code.
To utilise the battery monitor in the python software, this range can be updated in the battery.py
module. See the Software section for more information.
The MPU6050 support enhances the capabilities of the project by incorporating the MPU6050 sensor. This feature provides the ability to integrate motion sensing and orientation detection into the sketch, enabling a wide range of possibilities for balance improvements.
Getting Started: In the sketch's Config.h file, developers have the flexibility to enable or disable the feature by commenting out the MPU6050_ENABLED option (enabled by default). The MPU6050 can be connected in the custom PCB below the arduino using the i2c interface.
Debugging: For easy debugging and visualization, developers can enable the serial plotter by using the MPU6050_DEBUG option. This enables real-time monitoring of sensor data, aiding in fine-tuning and optimization.
Functionality and Usage: The current version of the MPU6050 Support feature primarily focuses on utilizing the pitch value for balance-related applications. However, it is important to note that a roll value is also generated, hinting at the potential for expanded functionalities in future releases.
The core functionality of the feature involves the continuous operation of the MPU6050 sensor, which tracks motion and orientation. By integrating this data into the Arduino loop, the feature automatically compensates for any tilting by adjusting hip offset and moving servos.
The arduino sketch is configured to allow random animations to take place in the absence of any serial commands. This includes looking around randomly and adjusting the leg position slightly to compensate.
Connect the Pi GPIO 14 & 15 (tx & rx) to the arduino tx & rx (tx -> rx in both directions!) via a logic level shifter, as the Pi is 3v3 and the arduino is (most likely) 5v.
The sketch on the arduino can be updated directly from the Raspberry Pi using the Arduino IDE.
To upload over serial pins, press the reset button on the Arduino at the point that the IDE starts 'uploading' (after compile), otherwise a sync error will display.
A custom PCB has been designed to connect to the Arduino. This is available in the circuits folder.
Buddy arduino PCB gerber for printing. Send this to your PCB printing service.
- A0 - Battery voltage (via voltage divider)
- D2-D11 - Servo PWM
- A4 - MPU6050 SDA
- A5 - MPU6050 SCL
- TX - Serial TX (to Pi)
- RX - Serial RX (from Pi)
- Power (labeled with 5v), input of 5v power supply (bottom pin), ground (middle pin) and the input voltage (top pin) from the battery or power source.
- Bridge - Two pins that connect the 5v power rail to the Arduino's RAW pin. This allows the Arduino to be powered from the 5v rail, or from the USB port if the bridge is disconnected.
- OUT - For the external voltage monitor component. Outputs the input voltage (top pin) and ground (bottom pin).
- Pi - Passes input voltage (NOT 5V!) and serial connection to the pi. Pins from top to bottom: Arduino TX, Arduino RX, GND, VIN.
Releases:
- Cody (preview)
- Buddy (current)
- Archie (legacy)