Personal Project: Self Balance Bot

I. Intro

Date: April 2024 – June 2024

Since there’s not much progress in tuning the PID of the quadcopter, I decided to leave it for the summer and start the self balance bot project. Many people did this, so I think this project is one of the “I must do it” projects.

The reason that the first self balance bot failed was because the friction was too large, or the start-up voltage was very high. The PWM signal ranges from 0 to 4096, and the motor from myRIO robot requires 2500 to start spinning. That’s about 61%. In contrast, the new motor only requires 500 to spin. However, I didn’t use the friction compensation because the balancing result was much better without it. Strange.

Honestly, this self balance bot has the best looking on YouTube in my opinion.

The final product.

II. Building Process

The first generation used the myRIO power system. A super large and heavy 3S Li-ion battery, two old super-large-friction motor with new encoders (old ones were broken), and a circuit board with two motor drives. ESP32 and MPU6050 were soldered onto the PCB breadboard. This whole setup was used in the ROS bot.

Since the friction of the motors was very large, the bot either behaved overshoot and divergence or overdamped and fell down, no matter how I tuned it.

Figure 1: the first self balance bot
Media 2: it’s overshoot and not having enough proportional control at the same time

If the hardware is trash, there’s no way it’s gonna work.

In summer, I built a much better one. The circuit was connected on a PCB, motor and motor drive were much better. The center of gravity was much lower, mass was lower, the height is lower, and the rotational inertia was much smaller. There were two ways to install the motor, one with a higher axel and one with a lower axel. The one with a higher axel can lower the CG a lot, and it should be easier to control, but what’s the fun of that configuration? Another configuration also worked for a lot of people, so I chose the one with higher CG.

This self balance bot used a cascade PID control system. The inner control loop is a PD control system for standing. The actual value comes from the pitch angle, and the error change comes from the pitch angular speed. Since the bot is an inverted pendulum, adding the integral to the standing control loop is pointless.

The outer loop is a PI control system for wheel speed. The actual value comes from the 10 times the sum of the two encoder values after a complementary filter. The output value of this controller is the input value of the PD controller.

Figure 3: the schematic when I am modifying the second version
Figure 4: the PCB design when I am modifying to the second version
Figure 5: design the frame based on the PCB design
Figure 6: testing the circuit before finalizing the schematic and PCB.
Figure 7: building the PCB
Figure 8: The day before the PCB arrives, I start working on the frame.
Figure 9: install the 180-degree servos
Figure 10: install the stand for the PCB
Figure11: install the magnets
Figure 12: install the motor mounts
Figure 13: connecting the wires based on the schematic. The motor doesn’t have the 6pin connector with it, so I need to solder it anyway.
Figure 14: do the same thing on another motor
Figure 15: install the battery mount. The 3M foam double sided tape provide enough friction to secure the battery by deforming, so the tolerance is not a big deal.
Figure 16: The encoder on the right motor was taken out, rotate 180 degrees, and reinstalled because the wire was not long enough.
Figure 17: pull the wires through holes.
Figure 18: waiting for the PCB to arrive.
Figure 19: PCB arrived on the second day.
Figure 20: electronics were installed. Good news, no smoke came out.
Figure 21: install the PCB to the frame
Figure 22: and solder the ultra sonic sensor onto the PCB.
Figure 23: connect the wires.
Figure 24: back view
Figure 25: top view. Button functions from left: enable basketball, set medium angle, and change mode.
Figure 26: IMU was secured by nylon spacer and anti-slipping nut.
Figure 27: assembly was done.
Figure 28: I change the foam tape to the top so the main power wires have some space to slide in.
Figure 29: voltage monitor calibration curve, actual battery voltage vs analogRead() returned value.
Figure 30: bluetooth control panel. It shows the medium angle, battery voltage, control mode, wheel speed, pitch angle, distance from ultra sonic sensor, a button to set the med angle (top), a button to turn on/off the basketball (left), and a button to switch control mode.
Figure 31: test drive
Figure 32: the servo finally worked. The servo library was broken, and ESP32 was not outputting any signal, so I have to do the same thing I did in the flight controller.
Figure 33: start-up demo
Figure 34: mode 1 demo
Figure 35: mode 2 demo. Normal control with bluetooth, but it will stop if it’s too close to the wall. You can only reverse if it’s too close. You can’t turn if it’s too close because the wheel will hit the wall.
Figure 36: follow mode
Figure 37: stability test. The motor will be disabled if the angle is too large.

Leave a Reply

Your email address will not be published. Required fields are marked *