Skip to content
Tutorials Center
My learning

Topics

Lesson 26 of 37 · PID and Compensators

Practical PID: Windup, Filters and Limits

Make a PID controller work on real hardware: integrator anti-windup, derivative filtering, setpoint weighting, output limits and bumpless transfer, all simulated.

The textbook PID equation runs perfectly in a simulator and badly in a factory. Real actuators saturate (a valve cannot open past 100%), real sensors are noisy, setpoints jump, and operators switch between manual and automatic. Each of these breaks a naive implementation. This lesson covers the five fixes that every production PID has: anti-windup, derivative filtering, setpoint weighting, output limiting, and bumpless transfer.

All of them are small additions to the loop you wrote in PID basics, and all are visible in simulation.

Integrator windup

When the actuator saturates, the loop is effectively open: the output stays at its limit however large the error becomes. The integral term does not know this. It keeps accumulating, "winding up" to a huge value. When the setpoint finally becomes reachable, the stored integral must be unwound first, and the actuator stays pinned at its limit long after it should have backed off. The result is large overshoot and long recovery.

Anti-windup by back-calculation feeds the saturation difference back into the integrator:

TEXT
I' = Ki·e + Kt·(u_sat - u_unsat)

When the controller is not saturated the extra term is zero and nothing changes. When it saturates, the term pulls the integral back toward a value that agrees with the limit. Kt is a tracking gain, commonly 1/Ti up to 10/Ti. The simpler alternative, clamping, stops integrating whenever the output is saturated and the error has the same sign as the saturation.

Python Windup with and without back-calculation

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

For 15 s the setpoint (2.0) cannot be reached, so y sits at 1.0 with the output pinned at 1. The error stays at 1, so the integral grows without bound. After the setpoint drops to 0.5, the plain PI keeps the actuator at its limit for another 34 seconds while the integral unwinds; the back-calculating controller recovers in a fraction of a second.

Derivative filtering

An ideal differentiator has gain growing without bound with frequency. Sensor noise, quantization steps, and sampling jitter all contain high frequencies, so the D term turns them into violent output twitching. The standard fix is a first-order low-pass on the derivative path:

TEXT
D(s) = Kd·s / (1 + s·Td/N)

N (also written as the filter coefficient) typically lies between 5 and 20: the derivative acts as a true differentiator up to roughly N/Td rad/s and then flattens to a gain of Kp·N.

Python Noise through a raw and a filtered derivative

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A 1% sensor noise makes the raw derivative about twice as noisy as the real signal's own derivative, and its error against the true derivative is about eight times that of the filtered one. The filter's price is a small lag (Td/N seconds) on the derivative action.

Setpoint weighting and prefilters

A step in the setpoint hits the proportional term all at once. Two-degree-of-freedom PID separates how the loop reacts to setpoint changes from how it rejects disturbances:

TEXT
u = Kp·(b·r - y) + Ki·∫(r - y)dt - Kd·dy/dt

With b = 1 you have a normal PID; with b < 1 (say 0.5 to 0.8) the setpoint jump enters the proportional term only partially, which lowers overshoot without making the disturbance response any slower. Derivative-on-measurement is the same idea with c = 0 on the derivative.

Python Setpoint weighting reduces overshoot

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Lower b gives lower overshoot at the cost of a slower rise. The tuning of Kp, Ki and Kd (which governs disturbance rejection) never changes.

Output limits and rate limits

Always clamp the final output to the physical range of the actuator, and consider a rate limit if the actuator cannot move faster than a given speed (valves, heaters with thermal stress). Never rely on the plant's own saturation to do it: the controller must know the actual applied value so back-calculation works. If a lower-level layer (a driver, a servo amplifier) clips the signal, read the clipped value back and use it for tracking.

Bumpless transfer and manual mode

When an operator hands a loop from manual to automatic, the controller output should not jump. Two conventions:

  • Tracking mode: while in manual, set the integrator so that u_pid equals the manual output: I = u_manual - Kp·e. At the switch, the controller starts exactly where the operator left it.
  • Velocity (incremental) form: compute Δu each sample and add it to the previous output. The same trick falls out naturally; see digital PID.

A checklist for a production PID

  1. Derivative on measurement, filtered with N in 5 to 20.
  2. Anti-windup (back-calculation or clamping) with the actual actuator value.
  3. Output clamp and optional rate limit.
  4. Setpoint weighting or a reference prefilter.
  5. Fixed, known sample time (or compute with the measured dt).
  6. Bumpless transfer for mode changes.
  7. Sensible initial conditions at start-up: preload the integral so the first output is reasonable.

Anti-windup is not optional. A loop that works perfectly in small-signal tests can lock up for minutes the first time a large disturbance saturates the actuator. Test the saturated case deliberately.

Check your understanding

Quick check · 5 questions

of 5 answered You scored / 5 · perfect!

  1. 1. What causes integrator windup?

    With the actuator at its limit the loop is effectively open, so the error persists and the integral term grows without bound.
  2. 2. What does back-calculation do?

    The term Kt(u_sat - u_unsat) bleeds the integrator toward a value consistent with the saturated output.
  3. 3. Why filter the derivative term?

    A pure differentiator amplifies high frequencies; the first-order filter limits the high-frequency gain to about Kp N.
  4. 4. Setpoint weighting b < 1 changes which behavior?

    b scales the setpoint in the proportional term only, so feedback properties like disturbance rejection stay unchanged.
  5. 5. In which situation is bumpless transfer needed?

    At the switch the controller output should continue from the manual value rather than jump.

Summary

  • Saturation makes the loop open; anti-windup keeps the integrator honest (back-calculation or clamping).
  • Filter the derivative: Kd·s/(1 + s·Td/N) with N of 5 to 20.
  • Setpoint weighting reduces overshoot without changing disturbance rejection.
  • Clamp and rate-limit the output, and feed back the actual applied value.
  • Provide bumpless transfer for manual/auto changes and sensible start-up initialization.

Next: State-Space Models