Auto Balance for Tank Drive - Code Example?

Hi there! During the district event, I noticed that some folks had integrated an auto-balance feature for their Tank Drive robot. Since I’m currently programming a Tank Drive robot as well, I’m interested in implementing this feature too. However, I’m not sure how to get started with it.

Would you be able to provide me with a code sample and a basic explanation of how it works?

Additionally, I’m not sure if any extra tools are required to make it work, so any guidance on that would be appreciated. Thanks in advance!


We’ve been having difficulties with our auto code lately on a KoP tank chassis.

The latest iteration of it drives towards the charge station until the NavX detects a significant change in pitch, then drives up a bit more on a timer. We used to have a PID loop running on the pitch but that didn’t work so we went back to a janky time-based auto which did.

1 Like

I’m a mechanical mentor, but since I saw this, I think I’ll take a crack.

We use the ADIS16470 gyro to get pitch angle:

And use that pitch to set our drive train power as proportional to the pitch.

There’s more in there that I’m not too sure about, but this worked at competition last week. The auto code folder is a bit messy, but there’s good stuff in there! Have fun browsing.


Take a look at this post. I have not tried to implement it, but it looks pretty neat and uses only the build in accelerometer in the rio.

1 Like

Thank you so much, will do!

That’s a really nice tutorial, I will definitely check it out. Thank you!