-
Notifications
You must be signed in to change notification settings - Fork 9
/
PID_Cntrl.h
67 lines (49 loc) · 2.04 KB
/
PID_Cntrl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef PID_CNTRL_H_
#define PID_CNTRL_H_
#include <math.h>
#define M_PI 3.141592653589793238462643383279502884
class PID_Cntrl
{
public:
PID_Cntrl(float I, float Ts, float uMin, float uMax);
PID_Cntrl(float P, float I, float Ts, float uMin, float uMax);
PID_Cntrl(float P, float I, float D, float Ts, float uMin, float uMax);
PID_Cntrl(float P, float I, float D, float tau_f, float Ts, float uMin, float uMax);
PID_Cntrl(float P, float I, float D, float tau_f, float tau_ro, float Ts, float uMin, float uMax);
PID_Cntrl(){};
virtual ~PID_Cntrl();
void reset(float initValue = 0.0f);
void setup(float I, float Ts, float uMin, float uMax);
void setup(float P, float I, float Ts, float uMin, float uMax);
void setup(float P, float I, float D, float Ts, float uMin, float uMax);
void setup(float P, float I, float D, float tau_f, float Ts, float uMin, float uMax);
void setup(float P, float I, float D, float tau_f, float tau_ro, float Ts, float uMin, float uMax);
void setCoeff_P(float P);
void setCoeff_I(float I);
void setCoeff_D(float D);
void setCoeff_F(float F);
void scale_PIDT2_param(float scale);
float update(float e);
float update(float e, float y);
float update(float w, float y_p, float y_i, float y_d);
void setLimits(float uMin, float uMax);
void setIntegratorLimits(float uIMin, float uIMax);
float prewarp(float T, float Ts);
float get_ulimit();
float get_P_gain();
float get_bd();
float get_ad();
float get_current_output();
private:
float IPart, Dpart, d_old, u_old, uf;
float P, I, D, tau_f, tau_ro, Ts, uMin, uMax, uIMin, uIMax;
float bi, bd, ad, bf, af;
float P_init, I_init, D_init;
float F{0.0f};
void setCoefficients(float P, float I, float D, float tau_f, float tau_ro, float Ts);
void updateCoeff_I(float I, float Ts);
void updateCoeff_D(float D, float Ts, float tau_f);
void updateCoeff_RO(float Ts, float tau_ro);
float saturate(float u, float uMin, float uMax);
};
#endif /* PID_CNTRL_H_ */