Balance Bot PID Tuning

Hey, so I am working on a Self Balancing Bot with a ATmega2560 microcontroller. I'm using 12V 200 RPM motors with built in 840 PPR quadrature encoders. The torque rating is as follows:

  • Rated Torque: 2.4 Kg-cm
  • Stall Torque: 6 Kg-cm

As of now I've implemented a simple PID controller (based on Brett Beauregard's PID library) to minimise only the tilt angle error. Still haven't implemented PID using the encoder for the position error.

I've tried a lot to tune the PID values. The robot is quite stable when it is standing its own. However, here's the issue, when the robot tilts by an angle greater than 7-8 degrees (or when it is pushed slighlty) from its stable position, the motors start rotating at the maximum speed (PWM: 255) and the robot still doesn't seem to recover back and just keeps running and then finally falls down in the direction in which it was moving. It doesn't seem to recover at all.

Is it just a problem with the PID tuning? As I said earlier, it's stable for the range -5 to +5 degrees (0 degrees is the upright position) without oscillating much. However it is not able to revover for errors greater than 7 degrees.

Or could this be an issue with the robot being too heavy and insufficent counter motor toruque? Total weight of the robot is around 1 kg (including the motors). I'm using 2200 mAh LiPo battery and have placed it at the highest level so as to decrease the angular acceleration.

PID tuning

I had similar problems and chased some to the integral term. Once it passes the zero (vertical) point I immediately negate the “I” term. You do not want it take time to cancel out what is obviously a useless value. Then again, mine likes to fall hard and often.