Visual walkthrough — PID tuning — Ziegler-Nichols, loop shaping
This page assumes you have never seen a Bode plot, a complex number, or the letter . We build all of it. Prerequisites we lean on but re-explain: PID controller basics, Bode plot & frequency response, Stability margins (gain & phase margin), and Nyquist stability criterion.
Step 1 — What "sustained oscillation" even means
WHAT. Picture a loudspeaker held near the microphone that feeds it. A tiny hum enters the mic, gets amplified, comes out the speaker, re-enters the mic, gets amplified again... If each trip around makes the sound exactly as loud as before, you get a steady screech that never grows and never dies. That is a sustained oscillation.
WHY. Ziegler-Nichols pushes a control loop to that exact edge on purpose. Just below it, the loop is stable but sluggish to name. Just above it, it explodes. Right at the edge the plant rings at one clean frequency — and that frequency is a fingerprint of the plant's own timing.
PICTURE. Three fates of a wobble sent once around the loop:

- Red, growing: each lap is louder → unstable.
- Teal, shrinking: each lap is quieter → stable, wobble dies.
- Plum, constant: each lap identical → the knife-edge we hunt for.
Step 2 — Why we test the loop with a pure sine wave
WHAT. To probe "how does one trip around the loop change a wobble?", we feed the plant the simplest possible wobble: a pure sine wave , where
- is time in seconds,
- (Greek "omega") is the angular frequency — how fast the sine spins, in radians per second. Big = fast wiggle, small = slow sway.
WHY. A linear plant has a beautiful property: feed it a sine of frequency , and after transients die you get back a sine of the very same frequency — only scaled (louder or softer) and shifted (delayed in time). No new frequencies appear. So a plant's entire personality is captured by two numbers per frequency: a size and a shift. This is exactly why we reach for frequency response and not, say, a differential-equation solver — sines diagonalise linear systems.
PICTURE. Input sine (teal) in, output sine (orange) out: same frequency, smaller, and lagging.

Step 3 — Meet : the bookkeeping trick for "size and shift"
WHAT. Tracking a size and a shift together is clumsy with two separate numbers. Mathematicians bundle them into one complex number. Think of a point on a flat map: how far it is from the origin encodes the size, and the angle it makes encodes the shift.
The symbol is just the name of the point one unit "north" (straight up) on that map — the purely rotational direction. (Electrical engineers write ; mathematicians write .) Writing means "spin at rate in that rotational direction."
WHY. With this trick, to find a plant's gain and phase at frequency you literally take its transfer function and substitute . Out pops a single map-point whose length is the gain and whose angle is the phase. One substitution replaces a whole sine experiment.
PICTURE. The complex map: length = gain, angle = phase.

Step 4 — The knife-edge condition: gain and phase
WHAT. Send a wobble around the loop once. The controller here is pure proportional, , so the open-loop response is . One lap multiplies the wobble's size by and shifts it by .
In a feedback loop the signal comes back subtracted (error reference output). Subtraction is itself a flip — an extra of shift. So the wobble reinforces itself perfectly when:
Here is the special frequency where both hold at once.
WHY. If the size returned is exactly (gain condition) and the shift lines the wobble back up with itself (phase condition), the wobble is copied perfectly forever — that is the plum curve of Step 1. Bigger → returns larger → growing (red). Smaller → shrinking (teal).
PICTURE. The phase clock swings from down to as grows; the crossing point is .

Step 5 — Building the phase of from one triangle
WHAT. Our test plant is . Substitute (Step 3):
Look at one building block, . On the complex map (Step 3) that is the point east and north — the corner of a right triangle with base and height .
WHY a triangle, and why ? The angle of that point is what we need for phase. In a right triangle, the ratio is the tangent of the corner angle — tangent measures the triangle's steepness. To invert "this steepness belongs to which angle?", we use (the undo button for tangent). That is the one and only tool that turns a side-ratio back into an angle. So:
Three copies, and a flip. The plant is that block cubed and in the denominator:
- multiplying three copies adds their angles → ;
- being in the denominator (a ) negates the angle → minus sign.
PICTURE. The base-, height- triangle, its angle , and the three copies stacking.

- base (the "+1" real part), height (the "" imaginary part);
- corner angle , and we take three of them, then flip the sign.
Step 6 — Solve for : the angle that hits
WHAT. Set the phase to the knife-edge value radians:
Dividing by : each triangle must contribute exactly . Now undo the arctan — ask "which has angle ?" — by taking the tangent of both sides:
WHY. The phase started at (no wiggle → no lag) and slides down without bound as grows, because climbs toward and we have three of them (toward total). Somewhere in between it must pass through — and it does so exactly once, at . Single crossing = single ultimate frequency = one clean period. (Degenerate check: a plant with only one or two poles, phase or only in the limit, never truly reaches at a finite — so pure-P cannot oscillate; there is no finite . We need three lags here, which is why the test plant is cubed.)
PICTURE. The phase curve crossing the line once, at .

Step 7 — Solve for : the gain that makes the size exactly
WHAT. Now the size. The length of on the map is the triangle's hypotenuse, (Pythagoras). Cubing multiplies three lengths; the denominator inverts:
At we have , so :
The knife-edge (Step 4) demands , so
\boxed{\;T_u=\frac{2\pi}{\omega_u}=\frac{2\pi}{\sqrt3}\approx3.63\ \text{s}\;}$$ **WHY.** At $\omega_u$ the plant already shrinks a wobble to $1/8$ of its size per lap. To make the lap *break even* (size $\times 1$), the proportional knob must supply the missing factor of $8$. Turn $K_p$ past $8$ and every lap grows — instability. Below $8$, every lap fades — stable. Exactly $8$ is the plum curve. **PICTURE.** The hypotenuse $\sqrt{\omega^2+1}$, evaluated at $\sqrt3$ giving length $2$, cubed to $8$, inverted to $1/8$. ![[deepdives/dd-physics-3.5.39-d2-s07.png]] --- ## Step 8 — From $K_u,T_u$ to the three PID knobs **WHAT.** Feed our fingerprint $(K_u,T_u)=(8,\,3.63)$ into the classic ZN **PID** row (parent §2): $$K_p=0.6\,K_u=4.8,\qquad T_i=\frac{T_u}{2}=1.81\ \text{s},\qquad T_d=\frac{T_u}{8}=0.454\ \text{s}.$$ Convert integral/derivative *times* into the gains the code actually uses: $$K_i=\frac{K_p}{T_i}=\frac{4.8}{1.81}\approx2.65,\qquad K_d=K_p\,T_d=4.8\times0.454\approx2.18.$$ **WHY these fractions?** $K_p=0.6K_u$ backs the gain off from the unstable $8$ down to $4.8$, buying stability margin. Both time constants are tied to $T_u$ because $T_u$ *is* the plant's natural ringing period — integral acts over about half a ring, derivative over an eighth of one, so each term is scaled to the plant's own clock, not an arbitrary number. This is exactly the handoff to [[Stability margins (gain & phase margin)|margin]]-based checking and, if you want to go deeper, to [[Root locus method]] or [[Bode plot & frequency response]] loop shaping. **PICTURE.** The pipeline: phase eq → $\omega_u$ → gain eq → $K_u$ → table → three knobs. ![[deepdives/dd-physics-3.5.39-d2-s08.png]] > [!mistake] Forgetting which form the table uses > The ZN table gives $T_i,T_d$ (times), **not** $K_i,K_d$ (gains). Plug the times straight into a > $K_i,K_d$ controller and you will be off by factors of $K_p$. Always convert: > $K_i=K_p/T_i$, $K_d=K_pT_d$. --- ## The one-picture summary Everything above, on one canvas: the triangle that made the phase, the single $-180°$ crossing that fixed $\omega_u=\sqrt3$, the hypotenuse that fixed $K_u=8$, and the arrows into the three knobs. ![[deepdives/dd-physics-3.5.39-d2-s09.png]] > [!recall]- Feynman retelling — say it to a friend > We want to know the one speed at which our plant will "sing" if we push it. A plant reacts to a > pure wiggle by giving back the *same-speed* wiggle, just smaller and delayed. We bundle "smaller" > and "delayed" into a single point on a map (the $s=j\omega$ trick). Our plant is three identical > lag-blocks; each block is a right triangle with base $1$ and height $\omega$, and its angle is > $\arctan\omega$. Three of them, flipped negative, give the plant's delay $-3\arctan\omega$. A > feedback loop sings when the signal comes back the same size *and* lined up with itself; the > feedback subtraction already flips it $180°$, so we need the plant to add another $180°$ of delay. > Setting $-3\arctan\omega=-180°$ means each triangle is $60°$, so $\omega_u=\tan60°=\sqrt3$. At that > speed the plant shrinks the wiggle to $1/8$, so we must turn the P-knob up to $8$ to break even — > that is $K_u=8$. One wiggle takes $2\pi/\sqrt3\approx3.63$ s, that is $T_u$. Hand those two numbers > to the Ziegler-Nichols table and out come $K_p,K_i,K_d$. That is the whole trick: **find the sing, > read its pitch and loudness, look up the knobs.** > [!recall]- Numbers to remember > Plant $1/(s+1)^3$ ::: $\omega_u=\sqrt3$, $K_u=8$, $T_u\approx3.63$ s. > Why phase first? ::: The phase equation has no $K_p$, so it alone pins $\omega_u$. > Why does pure-P fail on a single-lag plant? ::: Its phase never reaches $-180°$ at finite $\omega$, so no finite $K_u$ exists.