Chapter 12
Back to the Shower
Why did we oscillate, and how close to the edge are we?
Chapter 12: Back to the Shower ↗
The shower, with new eyes
June: I put our drone PID on the shower (same snappy feel, scaled to knob units). It swung hot, cold, hot… just like Mika in Chapter 0. The drone never did that!
Theo: The drone has no big delay. The shower has 2.5 seconds of pipe. Let's finally work out what a delay does.
The shower has two slow parts: the pipe, a pure 2.5 s delay, and the smoother, the head and pipe walls warming up with Chapter 3's time constant, s (after 1 s it has closed 63 % of the gap to a new temperature).
First, a confession about Chapter 0's "normal hand". It turned the knob at a speed proportional to how wrong the water felt: knob speed , with of the knob per second per °C. A speed proportional to the error means the knob position is the pile of past error. That's an I controller, with .
Mika: Wait, so in Chapter 0 I was a PID controller? Well, an I controller. An over-eager one.
Delay is a lag in the wiggle
Theo: I still think a delay just makes everything slower. It shouldn't be able to make anything unstable.
Let's isolate the pipe's pure delay first. Imagine a sine wave at the pipe's input travelling to the showerhead with no smoothing: the output has the same shape, 2.5 s late. How late is that, compared with one wiggle?
Chapter 12: Back to the Shower ↗
Theo: Wait. At a 5-second wiggle the hot water arrives exactly when the knob asks for cold. That's not slower. That's backwards.
The pipe delay stays at 2.5 s, but its phase lag depends on how fast the wave wiggles. Call the lag and the delay . If one wiggle takes seconds (here is a time, not a temperature), its angular speed is radians per second. A positive lag means the output trails the input. Engineers write a lag as a negative angle, so the plots below go downwards.
One whole wiggle is one full turn of Chapter 5's spinner: 360°, or 2π radians. So what matters is what fraction of a wiggle the delay covers: .
Chapter 12: Back to the Shower ↗
For a 5-second wiggle, 2.5 s is half a wiggle: 180°. In this pure-delay model, each output crest lines up with an input trough. The shower's smoother also shrinks fast wiggles; we'll add that next.
Mika: So the same 2.5 s is a nudge for a lazy wiggle and a full flip for a quick one. The pipe never changes. The wiggle does!
Measuring the shower one wiggle at a time
Now add the smoother to the pipe delay. The head and the pipe walls take time to warm up, so the full shower both delays and smooths knob changes. Here's the plan: wiggle the knob at one speed, wait for a steady rhythm, and measure two numbers:
- Gain (the same word as the controller's gain: size out ÷ size in): how big the temperature wiggle is, compared with the wiggle in the water mix we asked for.
- Phase: how far behind it is, as an angle: its share of a whole wiggle, times 360°.
Each measurement drops a dot on two plots. Measure at least five speeds, slow and fast.
Chapter 12: Back to the Shower ↗
The smoother shrinks fast wiggles, while the pipe keeps adding phase lag. These gain and phase curves against wiggle speed form a Bode plot. Together they are the shower's frequency response: how it treats each wiggle speed. Here the input is the temperature of the mixed water, so slow wiggles have gain 1. If we used knob fraction as input, the gain would be 45 times larger. To get the frequency response from the formula, set : the same trick that found Chapter 11's edge. (It works because the shower on its own is stable, so its wiggles settle into a steady rhythm we can measure.)
What the smoother does to a spinner
Theo: Chapter 4's trick again: guess the answer is the same spinner, just a different size and angle.
Put the spinner into the smoother's rule and the arrow must satisfy . Chapter 7's arrows: has length and points up at the angle . Dividing by it shrinks by that length and turns back by that angle. Slow wiggles barely notice. Fast ones get squashed and lag towards a quarter-turn, but never past it.
Chapter 12: Back to the Shower ↗
June: Found it! Near 0.95 rad/s the shower on its own turns a wiggle upside down. Remember that speed.
How close to the cliff?
Now close the loop: hand → knob → pipe → skin → hand. Follow a wiggle all the way around. For the Chapter 0 hand, the trip around the loop is (a little circle for loop, because is already the delay):
The pile of a wiggle
Mika: My hand piles up error. What does a pile do to a wiggle?
The area under a cosine is a sine, a quarter-wiggle behind: 90° of lag, at every speed. And the pile is bigger for slow wiggles, because each hump lasts longer before it cancels: the size goes like . Chapter 5 said velocity is times position. Piling up is the reverse: divide by . That's the in the loop.
Feedback subtracts (error = target − temperature). That's a ×(−1), Chapter 5's half-turn, so the wave flips once. If the trip around the loop also delays it by exactly 180°, the two flips cancel, and every correction arrives perfectly in step with the swing, like pushing a playground swing at just the right moment. If the loop returns the wave at full size (gain 1), the swing keeps itself going; bigger than 1, it grows. That's Chapter 10's again, on the line : a lap that comes back flipped and full size is .
June: For this simple shower loop, the phase falls through −180° at one relevant wiggle speed. Find that speed on the phase plot, then read the loop gain at the same speed on the gain plot. Is it below or above 1?
Chapter 12: Back to the Shower ↗
Slide until the total passes 180°, between 0.45 and 0.46 rad/s. At the exact crossing, about 0.457 rad/s, the swing comes back 0.72 times as big, so the hand could be about 1 ÷ 0.72 ≈ 1.4 times stronger before reaching the edge.
New words
- Gain margin
- How many times you could multiply the controller's gain before the loop gain reaches 1 at the −180° speed. Below 1 = over the cliff.
- Phase margin
- At the speed where the loop gain is exactly 1, how much extra lag it would take to reach −180°. More is safer; 45°–60° is a common target (the side trip below says why).
Phase margin is damping in disguise
June: Why 45° to 60°? Who picked that?
For the simple loops of Chapter 7, phase margin and damping ratio move together. About 43° goes with ζ = 0.4 (25 % overshoot), 52° with ζ = 0.5 (16 %), and 59° with ζ = 0.6 (under 10 %). These pairs are exact for Chapter 7's simplest loop, . So a margin of 45°–60° means ζ ≈ 0.4–0.6: bouncier than Chapter 7's 0.7–1. It is a common target anyway, because a margin is also a safety distance from the cliff (how wrong the model may be), not only a promise about overshoot. With a pipe in the loop it is a good guide, not an exact law.
For our shower, the phase of hits −180° at rad/s, a wiggle period of about 13.8 s. The normal hand () has a gain margin of only about 1.4, and a phase margin of about 22° (where its loop gain is 1, at 0.34 rad/s, the phase is −158°). Close to the edge! The harder hand doubles the gain: 1.4 ÷ 2 = 0.7, over the cliff. That's exactly why it never settled.
Predict first! Suppose the pipe were twice as long (a 5 s delay). What happens to the largest hand gain that's still stable?
Chapter 12: Back to the Shower ↗
Chapter 12: Back to the Shower ↗
Mika: Twice the pipe, about half the hand. And the swings at the edge get slower too: almost 24 seconds!
Theo: Okay, I take it back. A delay doesn't just make things slower: it eats phase margin, and phase margin is the only thing between you and an oscillation.
Your Chapter 0 shower, explained
Here's your own run from Chapter 0. If your swings were near the edge, their period should be close to what the loop predicts. There's a twist: people are not all the same kind of controller.
Chapter 12: Back to the Shower ↗
A speed hand (turn the knob while it feels wrong) is an I controller: its edge is at 13.8 s swings. A position hand ("it's too hot, put the knob here") acts like a P controller: . A position hand has no pile, so no 90° of its own: the pipe and smoother alone must reach 180°, which happens at a faster wiggle, rad/s (June's upside-down speed). That means 6.6 s swings, for any above about 0.031 knob per °C. Most people are a mix. (The normal robot hand swings a bit slower than 13.8 s, about 15.5 s, because it sits just inside the edge; the harder hand's swings, about 11.6 s, are squashed by the knob hitting its ends.)
Chapter 12: Back to the Shower ↗
Mika: So when I jerked the knob straight to a spot, I was a position hand. My six-second swings were the pipe and the smoother, not clumsy fingers.
Design a robot shower
Now let’s beat our own hands. The robot uses PI: P reacts to the current temperature error, and I remembers accumulated error. Together they let the knob respond promptly while I finds the right lasting setting.
June: Easy. I'll use big gains, like on the drone: fast and snappy. They're already dialled in. Watch this!
Chapter 12: Back to the Shower ↗
June: …it hunts, hot–cold–hot, every 6 seconds, like a position hand in Chapter 0. Big gains pushed the gain-of-1 speed past the −180° speed. No phase margin at all.
10 s on paper, 6 s in the shower
June's gains have per second, which is exactly . The PI's zero sits on the smoother's pole and cancels it, leaving . On paper that loop reaches −180° at , a 10 s swing. But her loop is far past the edge, so the knob slams from end to end, and those slammed swings come about every 6.3 s: close to the position hand's 6.6 s.
Theo: The drone could take big gains because it had almost no lag. Here, robust means gentle: leave margin for the delay. Try my gentle gains, about and .
P reacts to now, I to the pile. Adding a little now moves the knob a little earlier, which gives back phase: phase lead, about 37° at the old −180° speed with Theo's gains.
A well-margined PI gets comfortable in about 9.4 seconds, without repeated large swings. That beats the normal hand (which spent most of a minute swinging before it calmed down) and most humans. It can't beat physics, though: nothing can react to water that hasn't arrived yet. Engineers do have a trick for long delays, a Smith predictor, which runs a little simulation of the pipe inside the controller. That's a story for another notebook.
Robustness is the real lesson. Your model of the shower is never perfect: the pipe might be longer, the heater weaker. A margin says how wrong the model may be, as a number you can feel. The phase margin (in radians) divided by the gain-of-1 speed is a delay margin: how many seconds of extra pipe the loop can take.
Chapter 12: Back to the Shower ↗
Theo: The normal hand survives only about 1.1 s of extra pipe. My gentle robot survives 3.5 s. That's what robust means.
Shorter pipe or faster heater?
Mika: Can we just buy a faster heater?
Halving the smoothing time (τ = 0.5 s) lifts the speed hand's edge only from 1.12 to 1.21 %/(°C·s). Halving the pipe (1.25 s) lifts it to 2.06. For a position hand, the faster heater is even worse: its edge drops from 0.031 to 0.025 knob per °C, because the smoother was quietly shrinking fast wiggles. Delay is the enemy, not sluggishness.
How the robot actually turns the knob
The robot code writes PI as a knob speed: I keeps moving the knob while error remains, and P responds to a change in error. At startup, P also gives the knob an immediate move based on the current error. This matches the position rule, except when the knob reaches an end stop.
What we understand now
What we figured out
- A delay lags a wiggle by : nothing for slow wiggles, a lot for fast ones.
- A pile (I) lags every wiggle by 90°; a smoother by up to 90°; a pipe by , without limit.
- Feeding in sine waves and measuring gain and phase gives the frequency response; plotted, it's a Bode plot, and it's just .
- For this simple shower loop, self-sustained oscillation begins when the loop reaches −180° phase with gain 1; larger gain makes the swings grow until limits intervene.
- Gain and phase margin measure the distance to that cliff. Longer delay means less margin, so you need gentler control.
- Our Chapter 0 swings were a controller (us) with too little margin.
We have every tool now: feedback, PID, poles, margins. Time for the real test: wind, a package drop, and a noisy sensor. Can you keep the drone at 2 m?