Skip to content

Commit e6836b3

Browse files
committed
antiwindup update Foxboro type simplefoc#59
1 parent f927db2 commit e6836b3

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/common/lowpass_filter.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ float LowPassFilter::operator() (float x)
1313
unsigned long timestamp = _micros();
1414
float dt = (timestamp - timestamp_prev)*1e-6f;
1515

16-
if (dt < 0.0f || dt > 0.5f)
17-
dt = 1e-3f;
16+
if (dt < 0.0f ) dt = 1e-3f;
17+
else if(dt > 0.3f) {
18+
y_prev = x;
19+
timestamp_prev = timestamp;
20+
return x;
21+
}
1822

1923
float alpha = Tf/(Tf + dt);
2024
float y = alpha*y_prev + (1.0f - alpha)*x;
21-
2225
y_prev = y;
2326
timestamp_prev = timestamp;
2427
return y;

src/common/pid.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ float PIDController::operator() (float error){
2828
float proportional = P * error;
2929
// Tustin transform of the integral part
3030
// u_ik = u_ik_1 + I*Ts/2*(ek + ek_1)
31-
float integral = integral_prev + I*Ts*0.5f*(error + error_prev);
31+
// method uses the antiwindup Foxboro method : https://core.ac.uk/download/pdf/289952713.pdf
32+
float integral = integral_prev + I*Ts*0.5f*(error + error_prev) + integral_antiwindup_prev*I;
3233
// antiwindup - limit the output
33-
integral = _constrain(integral, -limit, limit);
34+
float integral_constrained = _constrain(integral, -limit, limit);
35+
integral_antiwindup_prev = integral - integral_constrained;
3436
// Discrete derivation
3537
// u_dk = D(ek - ek_1)/Ts
3638
float derivative = D*(error - error_prev)/Ts;

src/common/pid.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ class PIDController
3030
float output_ramp; //!< Maximum speed of change of the output value
3131
float limit; //!< Maximum output value
3232

33-
protected:
33+
float output_prev; //!< last pid output value
3434
float integral_prev; //!< last integral component value
35+
36+
protected:
37+
float integral_antiwindup_prev; //!< last integral antiwindup component value
3538
float error_prev; //!< last tracking error value
3639
unsigned long timestamp_prev; //!< Last execution timestamp
37-
float output_prev; //!< last pid output value
3840
};
3941

4042
#endif // PID_H

0 commit comments

Comments
 (0)