Libary for control.

Dependencies:   FastPWM

Dependents:   RT2_Cuboid

Committer:
pmic
Date:
Thu Apr 22 06:57:43 2021 +0000
Revision:
4:1cbd6af9836c
Succsellfully tested IIF_Filter-class and PID_Cntrl-class.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pmic 4:1cbd6af9836c 1 #ifndef IIR_Filter_H_
pmic 4:1cbd6af9836c 2 #define IIR_Filter_H_
pmic 4:1cbd6af9836c 3
pmic 4:1cbd6af9836c 4 #include "mbed.h"
pmic 4:1cbd6af9836c 5
pmic 4:1cbd6af9836c 6 class IIR_Filter
pmic 4:1cbd6af9836c 7 {
pmic 4:1cbd6af9836c 8
pmic 4:1cbd6af9836c 9 public:
pmic 4:1cbd6af9836c 10
pmic 4:1cbd6af9836c 11 IIR_Filter(float T, float Ts); // G(s) = s/(T*s + 1)
pmic 4:1cbd6af9836c 12 IIR_Filter(float T, float Ts, float K); // G(s) = K/(T*s + 1)
pmic 4:1cbd6af9836c 13 IIR_Filter(float w0, float D, float Ts, float K); // G(s) = K*w0^2/(s^2 + 2*D*w0*s + w0^2)
pmic 4:1cbd6af9836c 14 IIR_Filter(float wz, float Dz, float wp, float Dp, float Ts, float K); // G(s) = K * wp^2/wz^2 * (s^2 + 2*Dz*wz*s + wz^2)/(s^2 + 2*Dp*wp*s + wp^2)
pmic 4:1cbd6af9836c 15 IIR_Filter(float *b, float *a, int nb, int na); // G(z) = B(z) / A(z) = (b_0 + b_1*z^-1 + ... + b_nb*z^-nb) / (1 + a_1*z^-1 + ... + a_na*z^-na)
pmic 4:1cbd6af9836c 16
pmic 4:1cbd6af9836c 17 IIR_Filter() {};
pmic 4:1cbd6af9836c 18
pmic 4:1cbd6af9836c 19 virtual ~IIR_Filter();
pmic 4:1cbd6af9836c 20
pmic 4:1cbd6af9836c 21 void setup(float T, float Ts); // G(s) = s/(T*s + 1)
pmic 4:1cbd6af9836c 22 void setup(float T, float Ts, float K); // G(s) = K/(T*s + 1)
pmic 4:1cbd6af9836c 23 void setup(float w0, float D, float Ts, float K); // G(s) = K*w0^2/(s^2 + 2*D*w0*s + w0^2)
pmic 4:1cbd6af9836c 24 void setup(float wz, float Dz, float wp, float Dp, float Ts, float K); // G(s) = K * wp^2/wz^2 * (s^2 + 2*Dz*wz*s + wz^2)/(s^2 + 2*Dp*wp*s + wp^2)
pmic 4:1cbd6af9836c 25 void setup(float *b, float *a, int nb, int na); // G(z) = B(z) / A(z) = (b_0 + b_1*z^-1 + ... + b_nb*z^-nb) / (1 + a_1*z^-1 + ... + a_na*z^-na)
pmic 4:1cbd6af9836c 26
pmic 4:1cbd6af9836c 27 void reset(float u);
pmic 4:1cbd6af9836c 28 void reset(float u, float y);
pmic 4:1cbd6af9836c 29
pmic 4:1cbd6af9836c 30 void set_limits(float yMax);
pmic 4:1cbd6af9836c 31 void set_limits(float yMin, float yMax);
pmic 4:1cbd6af9836c 32
pmic 4:1cbd6af9836c 33 float filter(float u);
pmic 4:1cbd6af9836c 34
pmic 4:1cbd6af9836c 35 float get_output();
pmic 4:1cbd6af9836c 36
pmic 4:1cbd6af9836c 37 float operator()(float u)
pmic 4:1cbd6af9836c 38 {
pmic 4:1cbd6af9836c 39 return filter(u);
pmic 4:1cbd6af9836c 40 }
pmic 4:1cbd6af9836c 41
pmic 4:1cbd6af9836c 42 void print_filter_coeff();
pmic 4:1cbd6af9836c 43
pmic 4:1cbd6af9836c 44 private:
pmic 4:1cbd6af9836c 45
pmic 4:1cbd6af9836c 46 uint8_t nb, na;
pmic 4:1cbd6af9836c 47 float *B;
pmic 4:1cbd6af9836c 48 float *A;
pmic 4:1cbd6af9836c 49 float *uk;
pmic 4:1cbd6af9836c 50 float *yk;
pmic 4:1cbd6af9836c 51 float K;
pmic 4:1cbd6af9836c 52 float yMin, yMax;
pmic 4:1cbd6af9836c 53
pmic 4:1cbd6af9836c 54 float saturate(float y, float yMin, float yMax);
pmic 4:1cbd6af9836c 55
pmic 4:1cbd6af9836c 56 };
pmic 4:1cbd6af9836c 57 #endif