I wanted to share my two wheeled balancing robot. It’s my first robot and took way more effort than I anticipated. But It’s pretty robust against disturbances so I’m quite happy with the result. I’ll write up and open-source the design considerations and built process, and source code, in a blog post soon.
Height: 37cm / Weight: 3kg
Video 1: https://youtu.be/vIddskon6ic
Video 2: https://youtu.be/s3aa-ipn5Z0
Video 3: https://youtu.be/rJf3yibiXUA
Will write a blog post soon but for now, here is a summary of hardware and software design.
Hardware:
- Brushed motors with 27:1 planetary gear boxes with quadrature encoders (https://www.robotshop.com/en/12v-313rpm-4166oz-in-hd-premium-planetary-gearmotor-encoder.html)
- IMU: 9DOF NXP precision (FXOS8700 accelerometer+magnetometer, FXAS21002 gyroscope): https://www.adafruit.com/product/3463
- MPU: Three Teensy 4.0 microcontrollers. One for the AHRS algo (attitude estimation) at 400Hz, one for the balancing control logic at 200Hz, one for the speed/steering/motor control at 40Hz. Communication over serial ports. (https://www.robotshop.com/en/teensy-40-usb-microcontroller-development-board.html)
- Remote control: Bluetooth Low Energy (https://www.adafruit.com/product/2479) and custom IOS app.
- LCD display: DFRobot I2C LCD (https://www.robotshop.com/en/dfrobot-i2c-twi-lcd1602-module.html)
- Logic Level converter (3.3V->5V for LCD and LEDs): https://www.adafruit.com/product/757
- 5V power supply: Switching buck convertor: https://www.velleman.eu/products/view/?id=435566
- Smart led strips: https://www.adafruit.com/product/1506
- Battery: 4S Hardcase LIPO (14.8V, 6750mAh, 70C burst capacity): https://www.gensace.de/gens-ace-6750mah-14-8v-70c-4s1p-hardcase-lipo-battery-14.html
- Motor controller with regenerative braking support: https://www.robotshop.com/en/sabertooth-dual-2x32a-6v-24v-regenerative-motor-driver.html
- Lots of decoupling capacitors all over the place
- Frame: 2mm thick aluminium plate and U-brackets, 3mm thick acrylic
- JST connectors for PCB connections, XT90 connectors for high voltage/motors/battery
- 20A slow-blowing fuse
- 2.8’’ Talon Tires for Traxxas RC cars (https://www.robotshop.com/en/28-talon-tires-pair.html)
- PCBs: solder-able breadboards: https://www.sparkfun.com/products/12070
Software:
Cascaded PID controller. The outer loop runs a PID controller at 40Hz to control the speed, and another PID controller to control the steering angle (wheel RPM difference). The latter makes sure that the robot can drive straight, even if the two motors are not identical.
The output of the outer loop, is a target angle, that the robot needs to lean into to obtain the desired speed. This is the setpoint for the inner loop, which runs a PID controller to do the actual balancing at 400Hz, and takes input from a sensor fusion algorithm running at 400Hz too.
Sensor fusion runs at 400Hz on a Teensy 4.0. Attitude estimation is based on Madgwick’s complementary filter (https://github.com/xioTechnologies/Fusion - note, this is not his older gradient based implementation that many still use.).
Output is sent over Serial to a second Teensy 4.0 MPU which runs the main balancing algorithm. This one communicates over Serial with a third Teensy 4.0 which runs the velocity and steering controllers, takes care of deadzone compensation, and communicates with the Sabertooth.