The PID Controller
Loading simulation…
flagWhat you'll discover
- arrow_forwardExplain what the P, I and D terms each contribute
- arrow_forwardReproduce overshoot and oscillation by over-tuning Kp
- arrow_forwardUse Kd to damp oscillations and Ki to remove steady-state error
- arrow_forwardTune the controller to recover quickly from a disturbance
Proportional: push harder when farther
The P term outputs a force proportional to the error: output = Kp × error. Far from the target, it pushes hard; close to it, gently. It is intuitive and forms the backbone of nearly every controller.
But P alone has two flaws you can reproduce in the sim: crank Kp high and the cart overshoots and oscillates like a pendulum; keep Kp low against a constant disturbance and the cart settles slightly off-target, never quite arriving.
Derivative: the brake pedal
The D term watches how fast the error is changing and pushes against that motion: it is a brake. Approaching the target quickly? D pushes back early, so the cart glides in instead of slamming past.
Adding Kd to an oscillating P controller visibly calms it — engineers call this damping. Too much Kd, though, makes the system sluggish and twitchy against sensor noise, since the derivative amplifies rapid little changes.
Integral: the grudge holder
The I term accumulates error over time. If the cart sits even slightly off-target for a while, the integral grows and grows until the push is strong enough to close that last stubborn gap. This eliminates steady-state error.
The risk is integral windup: during a long disturbance the accumulated sum becomes huge, then overshoots wildly once released. Real implementations clamp the integral — the simulation does too.
PID runs the world
PID control, invented for ship steering over a century ago, now lives in drones (three nested PID loops per axis), 3D printer hotends, car cruise control, water treatment plants and the temperature controller in an electric rice cooker.
Tuning is a craft: a common recipe is to raise Kp until oscillation appears, add Kd to damp it, then add just enough Ki to erase the residual offset. Try exactly this sequence with the presets in the simulation.