2 Wheel Self-Balancing
Robot
Eric Wang
Segway
Handle (Boston Dynamics)
Development Board: WiPy 2.0
● ESP32 dual core microcontroller
● Wifi
● MicroPython
Sensors: MPU9250
● Accelerometer
● Gyroscope
● Magnetometer
Motor Controller: DRV8833
2 H-Bridges - can drive 2 DC motors or
1 stepper motor
Circuit Diagram
Esp 32
Balancing
Move motors in direction of tilt
1. Determine tilt angle
2. Balance by correcting tilt angle
Determining Tilt Angle With Gyroscope
● Gyroscope has noise and θ will drift over long periods of time
Determining Tilt Angle With Accelerometer
Accelerometer coord system
accel z
accel y +z
θ
+y
Inaccurate when other forces are present
Complementary Filter
● Combines accelerometer
and gyroscope data to give
a good estimate for angle
Modified
Complementary Filter
Change the weight of
accelerometer data based on
how close it is to 1g
PID Controller
Control loop feedback mechanism
Proportional, integral, and derivative
terms
PID constants
1. Make Kp, Ki, and Kd equal to zero.
2. Adjust Kp. Too little Kp will make the robot fall over, because there's not enough
correction. Too much Kp will make the robot go back and forth wildly. A good enough
Kp will make the robot go slightly back and forth (or oscillate a little).
3. Once the Kp is set, adjust Kd. A good Kd value will lessen the oscillations until the robot
is almost steady. Also, the right amount of Kd will keep the robot standing, even if
pushed.
4. Lastly, set the Ki. The robot will oscillate when turned on, even if the Kp and Kd are set,
but will stabilize in time. The correct Ki value will shorten the time it takes for the robot
to stabilize.
https://maker.pro/projects/arduino/build-arduino-self-balancing-robot
Placement of Parts
● Heaviest part on top
○ Reduces angular acceleration due to gravity - slower fall
○ PID controller can make adjustments before robot has tilted too far
Demo Video