PID Control
Three terms that run almost every machine you've ever touched
Your oven, your car’s cruise control, a drone holding altitude, the Mars rover aiming its camera: almost everything that holds a value steady runs the same three-term loop, invented to steer battleships a century ago.
It has a name that sounds like a chemical: PID.
The idea is almost insultingly simple. You have a thing you want at some value, a setpoint. You measure where it actually is. The gap between them is the error. A PID controller turns that error into an action using three terms, each answering a different question.
Drive the loop yourself
Below is the workhorse of every controls course: a springy second-order plant that lags and rings. Tap Replay and watch the Mass move toward the Target. Then tune the three gains and see what each one does.
Position 0.00 m Time 0.0 s Same steady load on both runs
Spring and damper model G(s) = 1 / (s² + 0.4s + 1)
- Try P only. Where does the mass stop?
- Pick PI. Watch the push build, then look for overshoot.
- Compare PID with Too much gain. Watch PID brake the mass and Too much gain make the swings grow.
Each term reacts to the error differently:
- P, Proportional (“how far off am I right now?”). Push in proportion to the error. Crank it up and the response gets snappy, but pure P always parks short of the target, leaving a stubborn steady-state offset, and too much makes it oscillate.
- I, Integral (“how long have I been off?”). Accumulate the error over time, so even a tiny lingering gap eventually builds enough push to kill it. I is what erases steady-state error, but it adds lag and overshoot.
- D, Derivative (“how fast am I approaching?”). React to the rate of change and brake early, before you slam into the target. D tames overshoot, but it amplifies sensor noise viciously (turn up Sensor noise with D enabled and watch the D: brake when closing fast bar judder).
The tuning dance
Tuning PID is a balancing act, and the demo lets you feel every trade-off:
- Pure P (set I and D to 0): fast, but it never quite reaches the target.
- Add I: it pulls all the way up, but overshoots and takes longer to settle.
- Add D: the overshoot calms down, because D brakes on approach.
- Turn on noise: the D-term explodes, jittering the output. Real sensors are noisy, which is exactly why the next lessons build observers to estimate a clean signal before differentiating it.
- Compare the two runs. Both With controller and No controller face the same steady load. Only the integral term can fully shrug it off.
The math: a second-order plant and the three-term law
The plant is the canonical damped second-order system, with natural frequency and damping ratio :
The controller closes the loop on the error (setpoint minus output):
Read it term by term: pushes proportional to the present error; integrates the past to erase any lingering offset; looks at the trend and brakes before overshoot. The demo integrates this by forward-Euler at . Switching on noise adds Gaussian to the measurement before the error is formed. Notice that the derivative reacts to the noisy measurement, not the smooth truth. That single fact is the seed of the entire state-estimation half of robotics.
Key takeaways
- P acts on the present error (snappy, but leaves offset), I on the accumulated past (kills offset, adds lag), D on the predicted future (tames overshoot, amplifies noise).
- Tuning is a trade-off between speed, overshoot, and stability; there’s no free lunch.
- Noise breaks the derivative term, which is why robots estimate state before they control it.
Run the controller yourself
This is a full PID loop driving a cold plant up to 100 degrees, and the three gains are yours. Bump Kp for a faster, twitchier response; add Ki to erase steady-state error; add Kd to damp the overshoot. Run it and read the overshoot straight off the numbers.
Three numbers. One loop. It steered a battleship in 1922 and it holds your quadcopter level today.
PID is the plainest possible answer to the deepest question in control: given the gap between where you are and where you want to be, how hard should you push? Everything fancier (pole placement, optimal control, the Kalman-filtered observers a few lessons from now) is just a more careful way of answering that same question.