This is the arduino code for an autobalancer that drifts no more than 15cm in any direction for at least 2 minutes. 

Pololu MC33926 motor shield, MPU-6050 breakout IMU from sparkfun, and Pololu Quadrature encoders are the main electrical components needed to implement this code.