PID Control 1.0
Discrete time implementation of P, PI, PD, PID. Including derivative filter, integral clamping, feed-forward, gain scheduling in standard and parallel form.
Loading...
Searching...
No Matches
pi.tpp
Go to the documentation of this file.
2
3template <typename T>
5{
6 dt = 0.0;
7 Kp = 0.0;
8 Ki = 0.0;
9 u_k_1 = 0.0;
10 e_k_1 = 0.0;
11 start = true;
12}
13
14template <typename T>
15void control_system::pi::PI<T>::init(T dt_, T Kp_, T Ki_, T u_k_1_, T u_max_)
16{
17 set_param(dt_, Kp_, Ki_, u_k_1_, u_max_);
18 start = true;
19}
20
21template <typename T>
22void control_system::pi::PI<T>::set_param(T dt_, T Kp_, T Ki_, T u_k_1_, T u_max_)
23{
24 dt = dt_;
25 Kp = Kp_;
26 Ki = Ki_;
27 u_k_1 = u_k_1_;
28 u_max = u_max_;
29}
30
31template <typename T>
33{
34 T e_k = x_0 - x;
35 T u_k = 0.0;
36 if (start == true)
37 {
38 start = false;
39 u_k = u_k_1 + Kp * e_k;
40 }
41 else
42 {
43 u_k = u_k_1 + (Kp + Ki * dt) * e_k - Kp * e_k_1;
44 }
45 u_k = saturate(u_k, -u_max, u_max);
46 u_k_1 = u_k;
47 e_k_1 = e_k;
48 return u_k;
49}
50
51template <typename T>
53{
54 u_k_1 = 0.0;
55 e_k_1 = 0.0;
56 start = false;
57}
58
59template <typename T>
61{
62 u_k_1 = u_k_1_;
63}
64
65template <typename T>
67{
68 dt = dt_;
69}
70
71template <typename T>
73{
74 Kp = Kp_;
75}
76
77template <typename T>
79{
80 Ki = Ki_;
81}
82
83template <typename T>
85{
86 u_k_1 = u_k_1_;
87}
88
89template <typename T>
91{
92 u_max = u_max_;
93}
94
95template <typename T>
97{
98 return dt;
99}
100
101template <typename T>
103{
104 return Kp;
105}
106
107template <typename T>
109{
110 return Ki;
111}
112
113template <typename T>
115{
116 return u_k_1;
117}
118
119template <typename T>
121{
122 return u_max;
123}
T get_Ki()
Gets the integral gain.
Definition pi.h:109
void set_Kp(T Kp_)
Sets the proportional gain.
Definition pi.h:73
void reset()
Resets the PI controller state.
Definition pi.h:53
void set_dt(T dt_)
Sets the controller sampling time.
Definition pi.h:67
T update(T x_0, T x)
Computes the PI control output.
Definition pi.h:33
T get_u_k_1()
Gets the previous controller output.
Definition pi.h:115
void set_Ki(T Ki_)
Sets the integral gain.
Definition pi.h:79
void set_u_0(T u_k_1_)
Sets the previous controller output.
Definition pi.h:85
void init(T dt_, T Kp_, T Ki_, T u_k_1_, T u_max_)
Initializes the PI controller.
Definition pi.h:16
void merge(T u_k_1_)
Merges an external controller output into the PI state.
Definition pi.h:61
T get_u_max()
Gets the maximum controller output.
Definition pi.h:121
void set_param(T dt_, T Kp_, T Ki_, T u_k_1_, T u_max_)
Sets the PI controller parameters.
Definition pi.h:23
T get_Kp()
Gets the proportional gain.
Definition pi.h:103
PI()
Constructs a PI controller.
Definition pi.h:5
T get_dt()
Gets the controller sampling time.
Definition pi.h:97
void set_u_max(T u_max_)
Sets the maximum controller output.
Definition pi.h:91
Proportional-Integral (PI) controller.
constexpr T saturate(T x, T x_min, T x_max)
Saturates a value within a specified range.
Definition utility.h:51