Integral windup happens when a controller's output is stuck at a limit but its integral term keeps growing. When the error finally changes sign, the large stored integral makes the output stay saturated too long, which gives a big overshoot. Anti-windup methods stop the integral from growing when it cannot help. It is a practical problem of Proportional, PD and PID Control.

How Windup Happens

  • a motor is commanded faster than it can go, so the controller output hits its maximum (for example 100% duty)
  • the error stays large, so the integral keeps adding it up
  • when the target is finally reached, the integral is huge, so the output stays at maximum and the system overshoots
  • the integral then needs a long time to unwind

Integral Clamping

  • limit the integral itself to a range,
  • simple, but the limit must be tuned

Conditional Integration

  • stop adding to the integral while the output is saturated (or undo the last addition)
  • simple and effective for most robots

Back-Calculation

When the unclamped output exceeds the limit , remove the excess from the integral:

  • because the integral term is , this removes exactly the part that caused the excess
  • the integral then sits at the value that just reaches the limit

Other Good Practice

  • reset the integral when the target becomes zero or the controller is turned off
  • skip the derivative on the first step after a reset, so a stale previous error does not cause a spike
  • limit the controller's share of the output when a feedforward term already does most of the work

Example In Code

integral += error * dt;
integral = std::clamp(integral, -i_max, i_max);        // clamping
float u = kp * error + ki * integral + kd * d_error;
if (u > u_max) {
    if (ki > 1e-6f) integral -= (u - u_max) / ki;        // back-calculation
    u = u_max;
}