Control Systems
What is integral windup, and how do you stop it?
Integral windup happens when a PID controller's output hits its limit, the motors at full power or the heater fully on, while the error stays large. The integral term keeps adding up error that the extra push can't fix. When the system finally reaches its target, that stored total is still there, so the controller keeps pushing and overshoots, sometimes by a lot. Anti-windup stops the integral growing while the output is saturated.
How it winds up
The integral is a running total of error over time:
Normally that's what you want: a small error that persists keeps adding up until the output is just right. But send a drone to 60 m when its motors max out at 30 units of thrust. For the whole climb the controller asks for far more than 30, gets 30, and the error stays big. Four seconds of an error averaging about 37 piles the integral up to roughly 150.
Paid back as overshoot
At 60 m the error reaches zero, but the integral still holds 150. With Ki at 1, that's 150 units of push the controller still thinks it owes, so the thrust stays pinned at the top and the drone sails up to about 109 m, almost 50 m past the target, before the integral unwinds.
Live experiment
Clamp the integral
A drone climbs to 60 m with PID (Kp 2, Ki 1, Kd 2) and motors that max out at 30. Unclamped, the integral piles up to about 150 during the climb and the drone sails to about 109 m. Clamp it to ±20, ±5 or ±1 and compare.
“Against the limit” is lesson 4 of 6 in Lag Lagoon, Control Systems World 2. Free with an account. Lessons unlock in order, so you’ll do the 10 before it first.
It's like a coffee shop with one barista and an order screen that keeps growing during a rush. When the rush ends, the barista still has forty coffees to make, and hands them out to an empty room.
Three cures
Clamp the integral. Right after adding to it, hold it between small limits:
integral = integral + error * 0.01;
integral = constrain(integral, -1.0, 1.0); // anti-windup
thrust = 9.8 + 2.0 * error + 1.0 * integral + 2.0 * d;
A clamp of ±1 can still trim a steady error, but it can never store a climb. The limits must be tight: at ±20 the drone still overshoots by about 7 m.
Conditional integration. Only add to the integral while the output isn't at its limit. When the motors are maxed, the total freezes.
Back-calculation. Bleed the integral down in proportion to how far the controller's request exceeds what the output can actually give.
Where you'll meet it
Cruise control on a steep hill, an oven heating from cold, a robot arm pushed against a wall, a valve that can only open so far: anywhere an actuator reaches its maximum, windup is waiting. Industrial PID controllers and most PID libraries include an anti-windup setting for exactly this reason.
Free lesson
Now build it yourself
Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.
“Against the limit” is lesson 4 of 6 in Lag Lagoon, Control Systems World 2. Free with an account. Lessons unlock in order, so you’ll do the 10 before it first.
Or start from the very first lesson, no account neededPractice questions
Three quick questions from the lessons. Pick an answer to check it.
Show the answer
Answer: The controller asks for more than 30, gets 30, and the integral keeps counting error the extra push can't fix. Windup only happens when the output is saturated. If the motors could give whatever was asked, the climb would end quickly and the integral would stay small.
- Why not “The drone gets heavier”? The drone's weight doesn't change. The integral grows because the thrust can't rise any higher.
- Why not “The sensor is late”? A late sensor causes swinging, a different problem. Windup comes from the output being stuck at its limit.
- Why not “The limit adds error”? The limit doesn't add error. It stops the motors delivering what the controller asks, so the error lasts longer.
Show the answer
Answer: The output is stuck at its limit and the integral keeps adding error. Saturation plus integration: the stored error comes back as overshoot.
- Why not “The gain is low”? A low gain makes a loop slow, but windup needs a saturated output and a growing integral.
- Why not “The drone is level”? Being level has nothing to do with it. Windup happens during a long push against a limit.
- Why not “The sensor is noisy”? Sensor noise troubles the D term most. Windup comes from the output being stuck at its limit.
Show the answer
Answer: Right after the integral is added to, before it's used. The thrust uses the integral; clamp it first or this pass uses the wound-up value.
- Why not “In setup()”? setup() runs once. The clamp has to act on every pass, right after the integral changes.
- Why not “After the thrust line”? After the thrust line is too late: this pass has already used the wound-up value.
- Why not “Anywhere”? Placement matters: the integral must be clamped before the thrust line uses it.
“Against the limit” is lesson 4 of 6 in Lag Lagoon, Control Systems World 2. Free with an account. Lessons unlock in order, so you’ll do the 10 before it first.
Questions people ask
What causes integral windup?
The output hitting a limit while the error stays large. The controller asks for more than the motor or heater can give, gets the maximum, and the integral keeps adding up an error the extra request can't fix. When the target is finally reached, that stored total keeps pushing.
How do you prevent integral windup?
Clamp the integral between small limits, stop adding to it while the output is saturated (conditional integration), or bleed it down by how far the request exceeds the limit (back-calculation). Most PID libraries and industrial controllers have one of these built in.
Does a PD controller have windup?
No. Windup is stored error, and only the integral term stores anything. A P or PD controller can still saturate during a big move, but it stops pushing as soon as the error shrinks.
Related topics
- PID control explainedWhat the P, I and D terms each do, shown on a drone climbing to 10 m.
- What is feedforward control?Put in what you already know the system needs, and let feedback fix the rest.
- How to tune a PID controller with Ziegler-NicholsFind the gain where it swings for ever, time the swing, and apply the recipe.
- Open-loop vs closed-loop controlSet and hope, or measure and correct: the idea behind every controller.