Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions PID.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,7 @@ float PIDController_Update(PIDController *pid, float setpoint, float measurement
*/
pid->integrator = pid->integrator + 0.5f * pid->Ki * pid->T * (error + pid->prevError);

/* Anti-wind-up via integrator clamping */
if (pid->integrator > pid->limMaxInt) {

pid->integrator = pid->limMaxInt;

} else if (pid->integrator < pid->limMinInt) {

pid->integrator = pid->limMinInt;

}
/* Anti-windup moved below */


/*
Expand All @@ -60,10 +51,14 @@ float PIDController_Update(PIDController *pid, float setpoint, float measurement

if (pid->out > pid->limMax) {

/* Anti-wind-up for over-saturated output */
pid->integrator += pid->limMax - pid->out;
pid->out = pid->limMax;

} else if (pid->out < pid->limMin) {

/* Anti-wind-up for under-saturated output */
pid->integrator += pid->limMin - pid->out;
pid->out = pid->limMin;

}
Expand Down