One Sampled Update, With Anti-Windup
Ada re-derives this chapter’s own numbers step by step, at full precision
ADA · CALCULATION AUDIT
One Sampled Update, With Anti-Windup
A pump controller leaves manual mode and returns to automatic mode after the actuator was saturated for several minutes, and the first automatic command overshoots badly. The chapter’s implementation trace calls for exactly the fields that failure needs — the integral accumulator, the saturation flag, and the manual-to-automatic reset rule — but never runs those fields through one sampled update. This audit asks the question that trace requirement invites: does holding the integral term while the actuator is pinned at its limit actually prevent the overshoot, or does the stored error keep climbing every saturated tick?
Companion to the chapter Lab: PID Implementation — every number here comes from that chapter.
Ada: This chapter gives the PID recurrence symbolically and no universal gains, which is correct — a book cannot tune your loop. But the arithmetic of a single sample tick is worth pinning down, so here is one pass with clearly illustrative values (not tuning advice): Kp = 5.0, Ki = 0.8, Kd = 0.2, sample_period = 0.1 s, setpoint = 80, measured = 62, previous_error = 15, prior integral = 20, and actuator range 0 to 100.
- Error:
error = 80 - 62 = 18. - Proportional:
proportional = 5.0 x 18 = 90.0. - Integral candidate:
integral_candidate = 20 + 18 x 0.1 = 21.8. - Derivative (raw):
derivative = (18 - 15) / 0.1 = 30.0. - Unconstrained output:
90.0 + 0.8 x 21.8 + 0.2 x 30.0 = 90.0 + 17.44 + 6.0 = 113.44. - Clamp to the actuator range:
clamp(113.44, 0, 100) = 100.0, sosaturation = true. - Anti-windup: because the output is pinned at the maximum and the error would push it higher, the guarded update rejects the
21.8candidate and holdsintegral = 20.
The audit conclusion is what the chapter’s structure protects: without that last step the integral would climb to 21.8 this tick and keep climbing every saturated tick, so when the process finally caught up the stored term would command a large overshoot. Freezing accumulation while the actuator is saturated is the difference between a bounded recovery and a wind-up spike — and none of these numbers is a recommended gain, only a demonstration of the bookkeeping.
Every number above is taken from the chapter’s own material and re-derived step by step.