PID control theory
A compact companion to the interactive simulator: what a plant is, what each PID term does, how to read a step response, and how Bode-like margins relate to stability.
1. The feedback idea
A controller compares a desired value (reference r) with the measured output
y, and produces an actuation command u that drives the plant so that
y tracks r.
e = r − y (error)
u = C{e} (controller)
y = G{u} (plant)
With unity feedback, the open-loop transfer function is L(s) = C(s) G(s), and the closed-loop map from
reference to output is approximately T(s) = L / (1 + L) when sensor dynamics are neglected.
2. Plant models in the simulator
First order
G(s) = K / (τ s + 1)
Common for thermal systems, simple RC-like processes, and many “lag” plants. One energy storage element.
Second order
G(s) = ωₙ² / (s² + 2 ζ ωₙ s + ωₙ²)
Captures oscillation and damping. ζ < 1 underdamped (rings), ζ = 1 critically damped, ζ > 1 overdamped.
Integrating + lag
G(s) = K / [s (τ s + 1)]
Models level control, some motion/position chains, or type‑1 processes that keep integrating a constant input. Steady-state error to a step often needs integral action in the controller.
3. The PID controller
u(t) = Kp · e(t) + Ki · ∫ e(τ) dτ + Kd · de/dt
C(s) = Kp + Ki/s + Kd · s
= (Kd s² + Kp s + Ki) / s
| Term | Gain | Effect (intuition) |
|---|---|---|
| Proportional | Kp |
Immediate reaction to error. Higher Kp → faster, but can overshoot/oscillate. |
| Integral | Ki |
Removes steady-state offset by accumulating past error. Too much → slow windup/oscillation. |
| Derivative | Kd |
Damps change (anticipates). Helps reduce overshoot; sensitive to noise in real sensors. |
4. Reading the step response
For a unit step reference, the simulator reports classical time-domain metrics:
- Overshoot (%) — how far the first peak exceeds the final value.
- Rise time — time from 10% to 90% of the final value.
- Settling time (2%) — time after which |y−1| stays within 2%.
- Steady-state error — |1 − y(∞)| on the simulated horizon.
- Peak time — time of the first peak (if any).
A “good” loop is rarely the absolute fastest: it is fast enough, well damped, and robust to plant uncertainty.
5. Bode-like view and margins
The simulator plots the open-loop frequency response of L(jω) = C(jω) G(jω):
- Magnitude (dB) —
20 log₁₀ |L(jω)| - Phase (deg) —
arg L(jω)
Approximate stability margins:
- Gain crossover ωgc — frequency where |L| ≈ 1 (0 dB).
- Phase margin (PM) — how far the phase at ωgc is from −180°. Rule of thumb: often ≥ 30–60° for comfortable damping.
- Phase crossover ωpc — frequency where phase ≈ −180°.
- Gain margin (GM) — how far |L| is below 1 at ωpc (in dB). Positive GM and PM suggest stability for linear loops.
Margins here are numerical estimates on a frequency grid — excellent for teaching and tuning intuition, not a substitute for formal analysis of every industrial plant.
6. Practical tuning sketch
- Start with Ki = 0, Kd = 0, raise Kp until the response is reasonably fast with limited oscillation.
- Add Ki slowly to remove offset; watch overshoot and windup-like sluggish recovery.
- Add a little Kd to shave overshoot and settle faster (if the signal is clean).
- Check Bode margins: if PM collapses, reduce gains or rebalance Ki/Kd.
Classical recipes (Ziegler–Nichols, SIMC, lambda tuning, etc.) give starting points; the simulator is ideal for feeling how each gain moves the response.
7. What the simulator intentionally simplifies
- Ideal derivative on error (real systems filter D-term / use measurement derivative).
- No sensor delay, quantization, or sticky valves — those dominate many real loops.
- Soft actuation limits only; no full anti-windup architecture.
- Linear plant models — real plants can saturate, backlash, or change with operating point.
Try it
Open the PID Controller Simulator, pick a second-order plant with low damping, and sweep Kp / Ki / Kd while watching overshoot and phase margin move together.