FEZ Cerbot - Balancing code
The attached project will help you get started with your own balancing code for your FEZ Cerbot. You will need the following for this project
- FEZ Cerbot
- Accelerometer - I used the Seeed module
- Gyroscope - I used the Seeed module
- Button module
- Stand-offs or some other means of mounting the modules to the FEZ Cerbot
The button module is used to initiate the balancing code once everything is calibrated and the FEZ Cerbot is in the upright position.
Look at the photo of the FEZ Cerbot with the modules mounted, you will notice the Gyro and the Accelerometer are mounted at the bottom of the board. This is particularly important for the Accelerometer because it minimizes the effect of the whipping motion on the accelerometer readings. The location of the gyro is less important, but for symmetry I mounted it at the bottom as well.
The balancing algorithm uses a Complementary Filter to combine the readings from the Gyro and the Accelerometer to get an accurate enough reading on the current angle of the bot. Using this angle and it’s deviation from the intended angle (upright), the data is fed into a Proportional-Integral-Derivative (PID) controller which calculates the direction and velocity that the motors need to be run to adjust for the deviation from the target angle.