PID CONTROLLED Inverted Pendulum
OVERVIEW
An inverted pendulum is a naturally unstable system. In order to balance the system, a closed loop control algorithm must be used. My inverted pendulum is stabilized with a PID controller and two motorized wheels at the base. The PID controller recognizes an imbalance in the system and employs the wheels to torque the system back into equilibrium.
PID CONTROLLER
PID stands for "Proportional Integral Derivative". This means that the requested effort from the controller is a weighted sum between the three components.
The proportional component for my system is the offset angle from vertical. As the pendulum's tilt increases, a greater effort from the motors is requested. In the derivative component, the angular velocity of the system is used. As the pendulum rotates in any direction, an effort will be employed to nullify the movement. Finally, in the integral component, a time integral is taken of the offset angle values. The integral is used to keep track of and counter any steady state error. For my system, these errors look like a constant lean in one direction.
Tuning the weights for my system was done manually. I watched the system qualitatively and made adjustments according to the following rules. The proportional component must be strong enough to bring the system to vertical from a reasonable perturbation. The derivative component must be strong enough to nullify the overshoot from the proportional but weak enough to avoid reversing the effort of the proportional component. Finally, the integral component must be large enough to have a reasonable response time for a steady state error, yet be week enough so as to not cause overshoot.
HARDware
The hardware for my pendulum consists of an Arduino Micro, MPU-6050 Accelerometer + Gyro, and an H-bridge motor driver.
Accelerometer and gyro values are read from the MPU-6050 via an I2C communication. The accelerometer value is then normalized with gravity and converted to an offset angle using an arctanget. The gyro value is also normalized to zero angular velocity. These two measurements are then run through a moving average filter to remove noise.
The PID controller uses these values to calculate a requested effort. The direction of this effort is detected and transistors in the H-bridge are switched accordingly. A PWM signal is then sent to the H-bridge, which steps up the voltage and sends it to the motors. The end result is a PWM signal at the motor which has both the correct power and direction according to the requested effort from the controller.