Yet Another Balancing Robot Question

Hey guys, so over this summer I’ve been trying to implement a balancing robot. I am stuck on if its either the software or if its the frame I built. I even rebuilt the frame to be even lighter. Here are the specs

Robot: weight 1.13398 kg, height 0.2794 m, https://www.pololu.com/product/4752 motors. Wheels are scooter wheels 88mm in diameter. The design is just a 3 shelf design with the two motors on the very bottom shelf. I have the motor driver on the bottom, the blue pill and voltage regulators on the second, and the battery and MPU6050 on the very top shelf.

Software: I discretized the PID equation with a LPF for the D. I used symbolab to do all the math so I wouldn’t mess up any factoring. I then used said equation in Sci-lab with an arbitrary system, and it worked just fine. I am using a MPU6050 to calculate the pitch angle, using a complementary filter. The sampling rate of the MPU6050 is set to 200Hz, and I verified that the MPU6050 interrupt is firing at 203Hz. So that should be good enough. Then I run the Pitch Angle through the PID controller, with the set point at 0. The min and max are [-2999,2999], I take the absolute value and change the direction of the motors if need be and feed the absolute value into the PWM timer. The PWM timer is running at 20Khz, the max of the motor driver.

Testing: I’ve googled on how to tune a balancing robot and everyone says to start with the Kp and have all the other values set to 0. Similar to how you normally would tune a PID controller. The problem is I can’t find a value where it will oscillate back and forth without it just falling over after .5 seconds. I then change the Kd like they said, and it does oscillate more violently the higher the Kd, and the Ki does help smoothing it out. But I can’t find a good place to even get it to just wobble back and forth.

When I put one finger on the very top of the battery with slight pressure, the robot will actually balance and not fall over. So I tried adding a small weight but that did not help.

Main Question: If you made it this far I appreciate it very much, I really do. So I guess I don’t know if its just that I keep picking bad tuning values or if the inertia is just too much for the motors. I picked these motors because they were used in another balancing project, but unfortunately it didn’t have info on height and weight. How would I got about checking if the inertia is too much? Maybe there isn’t enough friction between the wheels and the floor? I’m confused on why the slight pressure helps but not weights. Thank you very much for any answer or guidance. Anything help is appreciated!

@SupItsChris Welcome to the RobotShop Community. Care to share some photos / videos? Troubleshooting an integration is not easy, and it seems you are taking the right approach, though “thinking outside of the box” might help a bit:

  • Are the motors fast enough to react? Is there play in the gears?
  • Is the program as a whole (and the processor itself) fast enough to react to changes in the angle, or is there a delay in the processing time?
  • By adding “training wheels” to either side which are just slightly off the ground, the robot would not fall over and you might see that it tries to recover.
  • Has anyone used the same MCU as you and provide the code for their balancing robot, where you can adapt the input from the sensor and output to the motor controller (and some other variables)?
1 Like