Inverted pendulum
A cart on a track, a pole balancing on top, and a controller trying to keep the pole vertical. Start with the gains at zero and watch gravity win. Then turn up Kp and Kd, and a small miracle happens: the system becomes stable.
Try Kp=0, Ki=0, Kd=0 to watch gravity win. Then slide Kp and Kd up.
What's happening under the hood
The plant is the canonical cart-pole: a cart of mass M = 1 kg on a frictionless track, with a pole of mass m = 0.1 kg and half-length L = 0.5 m attached at the top. A horizontal force F is applied to the cart. The dynamics come from the standard Lagrangian derivation and are integrated with semi-implicit Euler at dt = 1/240 s.
The controller is a PID on the pole angle θ (target: zero), plus a small position-regulation term so the cart doesn't drift off the track:
F = Kp·θ + Ki·∫θ dt + Kd·θ̇ − 1.0·x − 1.5·ẋForce is saturated to ±20 N. Try pushing Kp past ~100 with no Kd — the closed loop oscillates. Add derivative action and the oscillation dies. That's the "D" part earning its place.
Things to try
- Turn the controller off entirely. The pole falls, the cart rolls; welcome to open-loop instability.
- Kp only: set Kd=0 and watch the pole oscillate forever (undamped).
- Too much Kp: crank it to 150 and watch the cart slam into the track edges.
- Nudge: kick the pole mid-flight and see how fast the controller recovers at different gains.