The Pi takes accelerometer and gyroscope readings, and then controls the motor on the pendulum with a PID controller to keep the inverted pendulum upright. The video goes into a great deal of ...