Intuition The big picture (WHY this exists)
A spacecraft (or drone, or thermostat) has a goal — a target attitude, altitude, or speed.
The real system is always slightly off. The gap between "where I want to be" and "where I am" is the error .
A controller is a machine that turns error into corrective action. PID is the simplest, most-used recipe: it looks at the error's present (P), its past (I), and its future (D), and blends all three into one command.
WHY three terms? Because one term alone always fails in a predictable way — and each new term is the cure for the previous term's disease.
Definition Core quantities
Setpoint r ( t ) r(t) r ( t ) : the desired value (target).
Process variable y ( t ) y(t) y ( t ) : the measured actual value.
Error e ( t ) = r ( t ) − y ( t ) e(t) = r(t) - y(t) e ( t ) = r ( t ) − y ( t ) : how far off we are.
Control signal u ( t ) u(t) u ( t ) : the command we send to the actuator (thruster, motor, valve).
The controller is a function u = f ( e ) u = f(e) u = f ( e ) . PID chooses a specific, physically-motivated f f f .
HOW do we build f f f ? We ask: what information does e ( t ) e(t) e ( t ) carry?
Its value now → how big is the mistake right now?
Its accumulated history → have we been consistently off in one direction?
Its rate of change → is the mistake growing or shrinking?
These are exactly value, integral, derivative — the three things calculus lets you extract from a function.
Intuition WHY proportional
If you're far from target, push hard; if you're close, ease off. The correction is proportional to the error — like steering harder the more you've drifted from your lane.
u P ( t ) = K p e ( t ) u_P(t) = K_p\, e(t) u P ( t ) = K p e ( t )
K p K_p K p = proportional gain (bigger = more aggressive).
Common mistake Steel-man: "Just crank
K p K_p K p up and we'll hit the target perfectly."
Why it feels right: bigger K p K_p K p ⇒ bigger push ⇒ faster response. Seems like more is better.
The flaw — steady-state error. Suppose gravity or drag constantly opposes you (a constant disturbance d d d ). At equilibrium the control must exactly cancel it: K p e s s = d K_p\, e_{ss} = d K p e ss = d , so
e s s = d K p ≠ 0. e_{ss} = \frac{d}{K_p} \neq 0. e ss = K p d = 0.
With pure P you can shrink the leftover error by raising K p K_p K p , but never kill it — because zero error would give zero output, and then nothing fights the disturbance. Worse, huge K p K_p K p makes the system oscillate / go unstable .
Fix: you need a term that keeps pushing even when the instantaneous error is tiny → the integral.
The integral remembers . Even a tiny error, if it persists, piles up in the accumulator until the output grows large enough to eliminate it. It kills the steady-state offset that P leaves behind.
u I ( t ) = K i ∫ 0 t e ( τ ) d τ u_I(t) = K_i \int_0^t e(\tau)\, d\tau u I ( t ) = K i ∫ 0 t e ( τ ) d τ
HOW it removes steady-state error (derivation): In steady state e e e is constant = e s s =e_{ss} = e ss and u u u is constant. But d u I d t = K i e \frac{du_I}{dt} = K_i\, e d t d u I = K i e . For u I u_I u I to be constant we need d u I d t = 0 ⇒ K i e s s = 0 ⇒ e s s = 0 \frac{du_I}{dt}=0 \Rightarrow K_i\, e_{ss} = 0 \Rightarrow e_{ss}=0 d t d u I = 0 ⇒ K i e ss = 0 ⇒ e ss = 0 . So as long as any error remains, the integrator keeps changing the output , and the only resting state is zero error.
Common mistake Steel-man: "Integral only helps, so use a big
K i K_i K i ."
Why it feels right: more memory = faster elimination of offset.
The flaw — integral windup & overshoot. If the actuator saturates (max thrust reached) while error is large, the integral keeps accumulating a huge stored value. When you finally reach target, that stored value overshoots you far past it before it unwinds.
Fix: keep K i K_i K i modest, and use anti-windup (clamp/stop integrating when saturated).
The derivative predicts . If the error is falling fast, you're about to overshoot — so start braking now . It adds damping, like a shock absorber that resists rapid change.
u D ( t ) = K d d e ( t ) d t u_D(t) = K_d\, \frac{de(t)}{dt} u D ( t ) = K d d t d e ( t )
HOW it damps: if y y y is rushing toward r r r , then e e e is dropping, e ˙ < 0 \dot e<0 e ˙ < 0 , so u D < 0 u_D<0 u D < 0 pulls back the command, softening the approach and reducing overshoot/oscillation.
Common mistake Steel-man: "Derivative sees the future, so add lots of it."
Why it feels right: more anticipation = smoother landing.
The flaw — noise amplification. Differentiation multiplies high-frequency measurement noise. A jittery sensor with small fast wiggles produces enormous e ˙ \dot e e ˙ , so large K d K_d K d makes u u u chatter violently.
Fix: small K d K_d K d , and low-pass filter the derivative (use a filtered derivative).
Worked example Example 1 — Attitude hold, pure P vs P+I
A reaction wheel controls a satellite's pitch angle. Target r = 0 ∘ r = 0^\circ r = 0 ∘ , a constant solar-torque disturbance d = 2 d = 2 d = 2 (in output units). Plant at equilibrium needs u = d u=d u = d .
Pure P , K p = 4 K_p = 4 K p = 4 : steady error e s s = d / K p = 2 / 4 = 0.5 ∘ e_{ss} = d/K_p = 2/4 = 0.5^\circ e ss = d / K p = 2/4 = 0. 5 ∘ . Why this step? At rest u = K p e s s u=K_p e_{ss} u = K p e ss must equal d d d .
Add I: now the integrator ramps until u = 2 u=2 u = 2 with e s s = 0 e_{ss}=0 e ss = 0 . Why? Steady state forces u ˙ I = K i e = 0 ⇒ e = 0 \dot u_I = K_i e = 0 \Rightarrow e=0 u ˙ I = K i e = 0 ⇒ e = 0 . Offset gone.
Worked example Example 2 — Discrete step (compute one control update)
Given K p = 2 , K i = 0.5 , K d = 1 , Δ t = 0.1 K_p=2,\ K_i=0.5,\ K_d=1,\ \Delta t=0.1 K p = 2 , K i = 0.5 , K d = 1 , Δ t = 0.1 . Suppose e k − 1 = 1.0 e_{k-1}=1.0 e k − 1 = 1.0 , e k = 0.8 e_k=0.8 e k = 0.8 , and running integral before this step I p r e v = 0.3 I_{prev}=0.3 I p r e v = 0.3 (already includes past ∑ e j Δ t \sum e_j \Delta t ∑ e j Δ t ).
Integral: I k = I p r e v + e k Δ t = 0.3 + 0.8 ( 0.1 ) = 0.38 I_k = I_{prev} + e_k\,\Delta t = 0.3 + 0.8(0.1) = 0.38 I k = I p r e v + e k Δ t = 0.3 + 0.8 ( 0.1 ) = 0.38 . Then u I = K i I k = 0.5 ( 0.38 ) = 0.19 u_I = K_i I_k = 0.5(0.38)=0.19 u I = K i I k = 0.5 ( 0.38 ) = 0.19 .
Why: accumulate the newest error rectangle.
Proportional: u P = K p e k = 2 ( 0.8 ) = 1.6 u_P = K_p e_k = 2(0.8) = 1.6 u P = K p e k = 2 ( 0.8 ) = 1.6 . Why: react to now.
Derivative: u D = K d e k − e k − 1 Δ t = 1 ⋅ 0.8 − 1.0 0.1 = − 2.0 u_D = K_d \frac{e_k-e_{k-1}}{\Delta t} = 1\cdot\frac{0.8-1.0}{0.1} = -2.0 u D = K d Δ t e k − e k − 1 = 1 ⋅ 0.1 0.8 − 1.0 = − 2.0 . Why: error is dropping, so brake.
u k = 1.6 + 0.19 − 2.0 = − 0.21 u_k = 1.6 + 0.19 - 2.0 = -0.21 u k = 1.6 + 0.19 − 2.0 = − 0.21 . Interpretation: even though error is positive, the strong falling-rate makes D dominate → we ease/reverse to avoid overshoot.
Worked example Example 3 — Tuning intuition
System oscillates and never settles: increase K d K_d K d (damping). System settles but always a bit off target: increase K i K_i K i (kill offset). System responds too sluggishly: increase K p K_p K p (speed). Why: each symptom maps to the term whose job it is.
Recall Explain it to a 12-year-old (click to reveal)
Imagine steering a toy boat to a dot in a pond.
P: the farther the boat is from the dot, the harder you turn the wheel.
I: if the wind keeps nudging it off and P keeps leaving it just short, you get annoyed and add extra turn for how long it's been wrong — until it finally sits on the dot.
D: when the boat is zooming toward the dot, you start un-turning early so it doesn't shoot past.
Present, past, future — three helpers steering one boat.
Mnemonic Remember the three jobs
"P-I-D = Push, Integrate the past, Damp the future."
Or: P = Present, I = Is-history, D = Destiny.
Symptoms: P ush too weak → slow; no I → offset; no D → overshoot.
What is the error signal in a control loop? e ( t ) = r ( t ) − y ( t ) e(t)=r(t)-y(t) e ( t ) = r ( t ) − y ( t ) , setpoint minus measured process variable.
Write the continuous PID control law. u = K p e + K i ∫ 0 t e d τ + K d e ˙ u=K_p e + K_i\int_0^t e\,d\tau + K_d\,\dot e u = K p e + K i ∫ 0 t e d τ + K d e ˙ .
Why does a pure-P controller leave steady-state error under a constant disturbance? At equilibrium
u = K p e s s u=K_p e_{ss} u = K p e ss must equal the disturbance
d d d , so
e s s = d / K p ≠ 0 e_{ss}=d/K_p\neq0 e ss = d / K p = 0 ; zero error would give zero output and nothing cancels
d d d .
Which term eliminates steady-state error, and why? The integral: steady state needs
u ˙ I = K i e = 0 ⇒ e = 0 \dot u_I=K_i e=0\Rightarrow e=0 u ˙ I = K i e = 0 ⇒ e = 0 , so the loop can only rest at zero error.
Which term adds damping / reduces overshoot? The derivative — it responds to
e ˙ \dot e e ˙ , resisting fast change.
What practical problem does a large K d K_d K d cause? It amplifies high-frequency sensor noise, causing control chatter (fix: filter the derivative).
What is integrator windup and its fix? Integral keeps accumulating while the actuator is saturated, causing large overshoot; fix with anti-windup clamping.
Give the discrete PID update equation. u k = K p e k + K i ∑ j e j Δ t + K d e k − e k − 1 Δ t u_k=K_p e_k + K_i\sum_j e_j\Delta t + K_d\frac{e_k-e_{k-1}}{\Delta t} u k = K p e k + K i ∑ j e j Δ t + K d Δ t e k − e k − 1 .
Map symptom → term: system never settles / oscillates. Increase
K d K_d K d (damping).
Map symptom → term: system settles but with constant offset.
Feedback control loops — PID is one choice of the controller block.
Steady-state error and system type — why I raises the "type number."
Stability & the Routh–Hurwitz criterion — how gains affect stability.
Laplace transforms & transfer functions — C ( s ) = K p + K i / s + K d s C(s)=K_p+K_i/s+K_d s C ( s ) = K p + K i / s + K d s .
Ziegler–Nichols tuning — systematic gain selection.
Reaction wheels & attitude control — GNC actuators PID commands.
Sensor noise & filtering — why derivative needs a low-pass filter.
Integral term Ki integral e
Intuition Hinglish mein samjho
Socho tumhe ek satellite ko sahi angle par point karna hai. Jahan tum le jaana chahte ho (setpoint) aur jahan wo abhi hai (measured value) — dono ka difference hai error e = r − y e = r - y e = r − y . Controller ka kaam hai is error ko dekh kar command banana jo actuator (thruster ya reaction wheel) ko bhejein. PID bas isi error ka teen tareeke se istemaal karta hai: present, past, aur future .
P (Proportional): jitna zyada error, utna zyada push — K p e K_p e K p e . Problem yeh hai ki agar koi constant disturbance ho (jaise gravity ya solar torque), to sirf P se ek chhota sa error hamesha bacha reh jaata hai, kyunki output tabhi banega jab thoda error hoga. Isse bolte hain steady-state error .
I (Integral): yeh error ko time ke saath jodta rehta hai — K i ∫ e d t K_i\int e\,dt K i ∫ e d t . Agar chhota error bhi lambe time tak rahe, integral badhta jaata hai aur push tab tak barhta hai jab tak error bilkul zero na ho jaaye. Yani I offset ko khatam karta hai. Lekin zyada K i K_i K i se windup aur overshoot hota hai.
D (Derivative): yeh error ki speed dekhta hai — K d e ˙ K_d\,\dot e K d e ˙ . Agar tum bahut tezi se target ki taraf ja rahe ho, D pehle se brake lagata hai taaki overshoot na ho — shock absorber jaisa damping. Lekin zyada K d K_d K d sensor noise ko badha deta hai. Toh yaad rakho: P = speed, I = accuracy, D = stability. Teeno milke ek smooth aur accurate control dete hain — isiliye PID har jagah, drones se lekar spacecraft tak, use hota hai.