PID Controller — Hovering a Drone
Three knobs decide how a controller closes the gap between where it is and where it wants to be. PID, made tactile by hovering a drone with sliders.
Three knobs that close a gap
PID is widely used in industrial control systems and other feedback applications (Wikipedia: PID controller) — cruise control and robotic-arm positioning are two textbook examples. The job is always the same: there's a thing you want (the setpoint, ), there's where you actually are (the process variable, ), and there's the gap between them (the error, ). The controller's only output is a push — and PID decides how hard to push from three pieces of information about the error.
Source: Wikipedia — PID controller; LibreTexts — Introduction to Control Systems §3.3.
The three terms each look at the same error in a different way:
- — proportional, the "right now" knob. How big is the gap this instant? Push proportional to that. More → faster response, more overshoot, eventually instability if you crank it too far.
- — integral, the "stuck offset" knob. How long have we been off-target, summed up? Eliminates stubborn steady-state error (P alone often settles slightly below the target). Too much causes "wind-up" overshoot.
- — derivative, the "anticipation" knob. How fast is the gap closing? Damps the response so it doesn't overshoot or ring. Sensitive to noise in real systems.
What to try
Open the visual above and start with a preset:
- P only, soft. The drone climbs slowly and never quite hits the target.
- P only, hard. The drone overshoots, comes back, overshoots, comes back — pure proportional has no way to bleed off oscillation.
- PD tuned. Add some derivative; the wobble dies. Clean step response.
- PID tuned. Add a little integral too; any leftover offset gets eaten away. Hit the Wind gust button to disturb it — the controller fights back.
- Integral wind-up. Crank way up and watch the classic disaster.
Then drag the gain sliders manually. The drone is always running; the response shape changes under you.
Where the formal math comes back
If you turn off integral () and use a unit-mass plant, the closed loop is exactly a second-order system — the same one as the spring-mass-damper concept in this site. The controller gains map onto the familiar parameters:
So the predicted overshoot, time-to-peak, and settling time follow the standard underdamped formulas (see Wikipedia: Damping ratio). With integral on, the loop becomes third-order and these are approximations — but the intuition still holds.
- Natural frequency of the closed loop (PD-only on a unit-mass plant)
- Damping ratio of the closed loop (PD-only)
- Damped natural frequency (zero if ζ ≥ 1)
- Predicted peak overshoot for a step (PD-only, ζ < 1)
- Time-to-peak (PD-only, ζ < 1)
- Approximate 2% settling time (PD-only)
For the PD-on-unit-mass closed loop with K_p = 4 and K_d = 2 (m = 1), the equivalent natural frequency is ω_n = √4 = 2 rad/s and the damping ratio is ζ = 2/(2·√4) = 0.5. These are direct evaluations of the cited harmonic-oscillator formulas with k → K_p and c → K_d.
| Quantity | Expected | Computed | Δ |
|---|---|---|---|
| omega_n | 2 | 2 | 0 |
| zeta | 0.5 | 0.5 | 0 |
For ζ = 0.5 the standard underdamped second-order step-response peak overshoot is %OS = 100·exp(−π·0.5/√0.75) ≈ 16.30 % (Hallauer §9.8 Eq. 9.37 / Wikipedia: Damping ratio), with time-to-peak t_p = π/ω_d = π/(2·√0.75) ≈ 1.814 s (Hallauer §9.8 Eq. 9.36). The model should reproduce both within rounding.
| Quantity | Expected | Computed | Δ |
|---|---|---|---|
| overshoot_pct | 16.3 | 16.3 | 3.535 \times 10^{-4} |
| tp | 1.814 | 1.814 | 2.006 \times 10^{-4} |
- [1] Wikipedia — Proportional–integral–derivative controller, eq. u(t) = K_p e(t) + K_i ∫₀ᵗ e(τ) dτ + K_d de(t)/dt; e(t) = r(t) − y(t); table of effects of increasing K_p, K_i, K_d on rise time, overshoot, settling, SS error, stability (en.wikipedia.org)
- [2] A. Iqbal. LibreTexts — Introduction to Control Systems §3.3 PI, PD, and PID Controllers, eq. K(s) = K_p + K_d s + K_i / s (transfer-function form) (eng.libretexts.org)
- [3] Wikipedia — Harmonic oscillator (mass-spring-damper), eq. ω_0 = √(k/m); ζ = c/(2√(mk)); for closed-loop PD on unit-mass plant: k_eff = K_p, c_eff = K_d (en.wikipedia.org)
- [4] W. L. Hallauer. LibreTexts — Introduction to Linear Time-Invariant Dynamic Systems §9.8 Step-Response Specifications for Underdamped Systems, eq. t_p = π/ω_d (Eq. 9.36); peak overshoot exp(−ζπ/√(1−ζ²)) (Eq. 9.37); settling time t_s = 4/(ζ ω_n) (Eq. 9.40) (eng.libretexts.org)
- [5] Wikipedia — Damping ratio, eq. ζ = c/c_c with c_c = 2√(km); peak overshoot PO = 100 exp(−ζπ/√(1−ζ²)) (en.wikipedia.org)
- Parallel (ideal) PID form: u(t) = K_p·e + K_i·∫e dt + K_d·de/dt; error sign convention e = r − y (Wikipedia: PID controller).
- Plant in the visualization is a unit-mass double integrator (drone vertical motion with thrust correction around hover): m·ẍ = u, where u is the controller output added to the hover thrust.
- No actuator saturation, no measurement noise, no input lag — idealised conditions to expose the gain-effect intuition (real PID design must handle all three).
- Predicted overshoot, t_p, t_s formulas use the PD-only (K_i = 0) closed loop, where the system is exactly second-order. With K_i > 0 the loop becomes third-order and these closed-form predictions are approximations.