File tree Expand file tree Collapse file tree 3 files changed +14
-7
lines changed Expand file tree Collapse file tree 3 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -13,12 +13,15 @@ float LowPassFilter::operator() (float x)
13
13
unsigned long timestamp = _micros ();
14
14
float dt = (timestamp - timestamp_prev)*1e-6f ;
15
15
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
+ }
18
22
19
23
float alpha = Tf/(Tf + dt);
20
24
float y = alpha*y_prev + (1 .0f - alpha)*x;
21
-
22
25
y_prev = y;
23
26
timestamp_prev = timestamp;
24
27
return y;
Original file line number Diff line number Diff line change @@ -28,9 +28,11 @@ float PIDController::operator() (float error){
28
28
float proportional = P * error;
29
29
// Tustin transform of the integral part
30
30
// 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;
32
33
// 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;
34
36
// Discrete derivation
35
37
// u_dk = D(ek - ek_1)/Ts
36
38
float derivative = D*(error - error_prev)/Ts;
Original file line number Diff line number Diff line change @@ -30,11 +30,13 @@ class PIDController
30
30
float output_ramp; // !< Maximum speed of change of the output value
31
31
float limit; // !< Maximum output value
32
32
33
- protected:
33
+ float output_prev; // !< last pid output value
34
34
float integral_prev; // !< last integral component value
35
+
36
+ protected:
37
+ float integral_antiwindup_prev; // !< last integral antiwindup component value
35
38
float error_prev; // !< last tracking error value
36
39
unsigned long timestamp_prev; // !< Last execution timestamp
37
- float output_prev; // !< last pid output value
38
40
};
39
41
40
42
#endif // PID_H
You can’t perform that action at this time.
0 commit comments