Mastering Balance: PID Control of a Pendulum Cart

How three math terms, an encoder, and careful tuning turns a falling stick into a self-balancing system.