br3ttb / Arduino-PID-Library

1.93k stars 1.11k forks source link

Backcalculate integral sum into feasible range #116

Open drf5n opened 2 years ago

drf5n commented 2 years ago

Remove excess integral windup per Astrom, K.J. and Rundqwist, L. (1989). "Integrator windup and how to avoid it" (PDF). Proc. 1989 Am. Control Confi.: 1693–1698. through using code by Will posted in Brett Beauregard's forum at http://brettbeauregard.com/blog/2011/04/improving-the-beginner%e2%80%99s-pid-reset-windup/#comment-18721

drf5n commented 1 year ago

In https://controlguru.com/integral-reset-windup-jacketing-logic-and-the-velocity-pi-form/ it discusses this:

One approach to creating anti-windup jacketing logic is to artificially manipulate the integral sum of error itself. With our controller properly initialized, the approach is to flip the algorithm around and back-calculate a value for the integral sum of error that will provide a desired controller output value (COdesired), or:

image

Another way to think of it is if you are operating so far from Setpoint that kp*error exceeds the limits, than you shouldn't be banking more integral to wind down in the future. Dynamically limiting the integral sum to the slack between the kP and kD contributions and the Control Output automatically inhibits integration outside the proportional region. See the refs in https://github.com/br3ttb/Arduino-PID-Library/issues/76#issuecomment-1445273655