3.5.38 · D3Guidance, Navigation & Control (GNC)

Worked examples — PID control — proportional, integral, derivative terms

2,856 words13 min readBack to topic

This page is the drill-ground. The parent note built the three terms and told you why each exists. Here we hit every case a PID problem can throw at you — every sign, every degenerate input, every limiting value, a real-world word problem, and an exam trap. Work each one with the forecast covered first.

Before line one, one reminder in plain words. The controller watches an error — the gap between where we want to be (the setpoint ) and where we actually are (the process variable ). We write that gap as

If we are below target; if we have overshot; if we are exactly on target. The controller turns into a command using three ingredients — the error's value now (P), its running total (I), and its slope (D):

Everything below is just this one line, pushed into every corner. A key fact we will lean on repeatedly: the three terms simply add — this is linear superposition, so once each term is computed the final command is their plain sum, and each term's contribution can be read off independently.


The scenario matrix

Every PID exercise lives in one of these cells. The examples that follow are labelled with the cell(s) they cover, so by the end no cell is empty.

# Case class What makes it tricky Covered by
A Error positive, falling (approaching target) D term goes negative — sign confusion Ex 1, Ex 4
B Error negative (overshot the target) P and I flip sign; must "push back" Ex 2
C Zero instantaneous error, but stored history Only I survives — proves I "remembers" Ex 3
D Constant disturbance, pure P vs P+I Steady-state offset vs Ex 5
E Limiting values: , , What each term does in its extreme Ex 6
F Degenerate: constant error (flat), or noisy spike D of a flat line ; D of a spike blows up Ex 7
G Real-world word problem (drone altitude) Translate physics → Ex 8
H Exam twist: same error, opposite trend Same , different → different Ex 9

Worked examples

Fixed gains for the discrete examples unless stated otherwise:

Recall the discrete law that actually runs on the flight computer:

Here is the running sum of error rectangles — the digital echo of the integral. See Laplace transforms & transfer functions for the continuous view.


  1. Integral update. . Why this step? We must fold the newest error rectangle into memory before using it.
  2. P term. . Why? React to the present gap — we are still below target, so push up.
  3. I term. . Why? The accumulated history adds a steady extra shove.
  4. D term. . Why? Error fell by in one step — a steep negative slope. D reads this as "we're rushing in, start braking," so it pulls down.
  5. Sum. . Why? By linear superposition the command is just the three contributions added — no interaction terms.

Verify: Units all in output units, consistent. Sanity: even though , the fast approach () made D dominate, flipping the total negative — the controller eases off before overshoot. Exactly what "anticipate the future" means.


  1. Integral update. . Why? A negative error subtracts from the accumulator — the integrator starts unwinding its old positive charge.
  2. P term. . Why? Negative error means "you're too high," so P pushes down. Sign flips automatically.
  3. I term. . Why? Still positive because the stored history is still positive, even though the present error is negative — memory lags reality.
  4. D term. . Why? Error dropped further (), so the slope is negative: D pushes down too, fighting the runaway.
  5. Sum. . Why? Linear superposition again — add the three contributions to get the single command sent to the wheel.

Verify: P and D both negative (both say "come back down"), while I still positive from its backlog — a textbook picture of why overshoot with a wound-up integrator is sluggish to recover. Total is strongly negative: the corrective push points the right way.


  1. Integral update. . Why? Zero error adds no new rectangle — the memory holds.
  2. P term. . Why? P reads the present value, which is zero, so it contributes nothing right now.
  3. I term. . Why? The integrator's stored charge is unchanged, so its output survives even with zero present error — this is memory in action.
  4. D term. . Why? The error is not changing, so its slope is zero — D has nothing to anticipate.
  5. Sum. . Why? Linear superposition: with P and D both zero, the whole command is exactly the I term.

Verify: This is the whole reason integral exists. With zero instantaneous error the command is still — precisely the force needed to cancel the disturbance while holding . A pure-P controller here would output and immediately drift off. See Steady-state error and system type.


Figure — PID control — proportional, integral, derivative terms
Figure dd-physics-3.5.38-d3-s01.png — one sample of the error curve . Observe three things: the yellow dot's height () that the P term reads, the green shaded rectangle () whose area the I term accumulates, and the red dashed line whose downhill steepness () the D term reads. One curve, three features.

  1. P reads the height. The yellow dot's height is ; . Why? P is proportional to the value — literally the vertical position.
  2. I reads the shaded area. The green rectangle has area ; added to old memory it becomes , so . Why? An integral is area under the curve; the running sum stacks these thin rectangles.
  3. D reads the slope. The red line's steepness is ; . Why? A derivative is the slope of the tangent — here a downhill line, so negative.
  4. Sum. . Why? Linear superposition: the single command is the three read-off features added.

Verify: Same numbers as Example 1 (, ), now seen rather than computed. Height, area, slope — three different features of one curve.


  1. Pure-P equilibrium. At rest, and this must equal : Why? If the wheel is at rest the command is constant, and the only source of that command is the P term.
  2. Shrink but not kill. Doubling to gives — halved but still nonzero. Why? Zero error would give zero output, and then nothing cancels . P can never win this.
  3. Add integral. The integrator's state obeys , and its output is . In steady state the output must stop changing, i.e. , which forces . Why? The only resting state where memory stops growing is exact zero error — the integrator ramps until it alone supplies .

Verify: : , . Halving the error by doubling the gain confirms the law. With I, exactly. Compare against Ziegler–Nichols tuning for choosing these gains.


  1. . . Why? Infinitely stiff spring — but in reality huge makes the loop oscillate/go unstable (see Stability & the Routh–Hurwitz criterion). Accuracy in the limit, chaos in practice.
  2. . The integral term vanishes; you are back to pure P with its offset . Why? No memory means the past is forgotten — the disease P alone suffers returns.
  3. . No damping. Response overshoots and rings. Why? Nothing reads the trend, so nothing brakes early. Conversely would freeze the system and scream at every noise spike.

Verify: (accuracy), while restores (offset back). Consistent with the parent's "each term cures the previous term's disease."


  1. (a) Flat error, D term. . Why? The slope of a flat line is zero — D says nothing when nothing changes. Only P and I act.
  2. (a) I keeps ramping. Each step adds to memory — the integrator never rests while error persists. This is exactly how it erases the offset. Why? Constant nonzero error is the integrator's fuel.
  3. (b) Noise spike, D term. . Why? A tiny fast wiggle (jump of in one short step) produces an enormous slope. D amplifies high-frequency noise — the classic failure. Fix: filter the derivative (see Sensor noise & filtering).

Verify: Flat line: D . Spike: D from a jump over — a blow-up from a unit-size glitch. Demonstrates why raw is dangerous with a jittery sensor.


  1. Translate the physics. ; previous . Why? Always convert the word problem to first; below target ⇒ positive error ⇒ need lift.
  2. Update integral. . Why? Add the newest error rectangle.
  3. P term. . Why? React to the present altitude gap — still low, so add lift proportional to that gap.
  4. I term. . Why? The accumulated history of being low adds steady extra throttle to erase any lingering offset.
  5. D term. . Why? Altitude rose () so error shrank — D cuts throttle to avoid ballooning past .
  6. Sum. throttle-units. Why? Linear superposition: the single throttle command is the plain sum of the three contributions.

Verify: Net positive (still climbing, correctly), but the negative D trims off the raw of P+I — a pre-emptive brake. See Feedback control loops for the loop this sits in.


  1. Shared P and I. ; . Same for both. Why? P and I read only the present value and the memory — identical here.
  2. Student A's D. . Total . Why? Error is falling fast → brake hard.
  3. Student B's D. . Total . Why? Error is growing → push harder to catch up.

Verify: vs — a swing of , all from the D term, despite identical instantaneous error. The trap: one snapshot of never determines ; you must know the trend. This is the single most common exam gotcha.


Recall Quick self-test (click to reveal)

Cell C — with but and , what is ? ::: (P and D contribute nothing). Cell D — pure P, , , find . ::: . Cell H — why can two identical give different ? ::: Because also depends on (the D term); same value, different trend. Cell F — D term of a perfectly flat error? ::: Zero; slope of a constant is zero.