The integral term in a PID controller accumulates the error over time, which can help correct for consistent, steady-state errors. However, when you make significant changes to the system, such as doing an early frame exit (skipping a frame) or introducing sleeping (waiting before processing the next frame), you need to consider how these actions affect the accumulated error and, consequently, the integral term.
Early Frame Exit (Skipping a Frame):
When you skip a frame, you’re making a significant corrective action. If you don’t adjust the integral term, the accumulated error may cause the controller to overcompensate, leading to instability or oscillations—this is known as “integral windup.” To prevent this, you may choose to:
- Reset the Integral: Set the integral term to zero after skipping a frame. This is a simple way to prevent windup but may not always be ideal since it disregards the history of the error, which might still be relevant.
- Reduce the Integral: Subtract the corresponding error value for one frame duration from the integral term. This mitigates the impact of the skipped frame on the accumulated error but maintains the error history.
- Limit the Integral (Clamping): Instead of resetting, you can clamp the integral term to prevent it from exceeding certain bounds. This keeps the error history but prevents excessive accumulation.
Introducing Sleep (Waiting after a Frame Finishes Too Fast):
If the frame finishes too fast and you introduce a sleep to delay the next frame, the situation is a bit different:
- Maintain the Integral: Since you’re not skipping frames, the error is not being forcefully corrected in a way that could lead to windup. Instead, you’re allowing the process to pause, which keeps the system in its current state. In this case, you don’t necessarily need to reset the integral term because the error isn’t being artificially reduced; you’re just synchronizing the timing.
- Consider the System’s Behavior: If your system tends to oscillate or become unstable with a large integral term, even without skipping frames, you may still want to limit the integral term’s growth to prevent windup.
The decision to reset, reduce, or maintain the integral term depends on the specific behavior of your system and the desired performance. Resetting the integral term can lead to a more aggressive approach to error correction, while maintaining it can provide a more smooth and steady response. The best approach often comes down to empirical testing and tuning based on how your system responds in practice.