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
pd.tpp
Go to the documentation of this file.
2
3template <typename T>
5{
6 dt = 0.0;
7 e_k_1 = 0.0;
8 Kp = 0.0;
9 Kd = 0.0;
10 start = true;
11}
12
13template <typename T>
14void control_system::pd::PD<T>::init(T dt_, T Kp_, T Kd_, T u_max_)
15{
16 set_param(dt_, Kp_, Kd_, u_max_);
17 start = true;
18}
19
20template <typename T>
21void control_system::pd::PD<T>::set_param(T dt_, T Kp_, T Kd_, T u_max_)
22{
23 dt = dt_;
24 Kp = Kp_;
25 Kd = Kd_;
26 u_max = u_max_;
27}
28
29template <typename T>
31{
32 T e_k = x_0 - x;
33 T u_k = 0.0;
34 if (start == true)
35 {
36 start = false;
37 u_k = Kp * e_k;
38 }
39 else
40 {
41 u_k = (Kp + Kd / dt) * e_k - (Kd / dt) * e_k_1;
42 }
43 u_k = saturate(u_k, -u_max, u_max);
44 e_k_1 = e_k;
45 return u_k;
46}
47
48template <typename T>
50{
51 e_k_1 = 0.0;
52 start = true;
53}
54
55template <typename T>
57{
58}
59
60template <typename T>
62{
63 dt = dt_;
64}
65
66template <typename T>
68{
69 Kp = Kp_;
70}
71
72template <typename T>
74{
75 Kd = Kd_;
76}
77
78template <typename T>
80{
81 u_max = u_max_;
82}
83
84template <typename T>
86{
87 return dt;
88}
89
90template <typename T>
92{
93 return Kp;
94}
95
96template <typename T>
98{
99 return Kd;
100}
101
102template <typename T>
104{
105 return e_k_1;
106}
107
108template <typename T>
110{
111 return u_max;
112}
void init(T dt_, T Kp_, T Kd_, T u_max_)
Initializes the PD controller.
Definition pd.h:15
PD()
Constructs a PD controller.
Definition pd.h:5
void set_u_max(T u_max_)
Sets the maximum controller output.
Definition pd.h:80
T get_u_max()
Gets the maximum controller output.
Definition pd.h:110
void set_dt(T dt_)
Sets the controller sampling time.
Definition pd.h:62
void set_Kd(T Kd_)
Sets the derivative gain.
Definition pd.h:74
void merge(T u_k_1_)
Merges an external controller output into the PD state.
Definition pd.h:57
T get_e_k_1()
Gets the previous control error.
Definition pd.h:104
void reset()
Resets the PD controller state.
Definition pd.h:50
void set_param(T dt_, T Kp_, T Kd_, T u_max_)
Sets the PD controller parameters.
Definition pd.h:22
T get_Kp()
Gets the proportional gain.
Definition pd.h:92
T get_dt()
Gets the controller sampling time.
Definition pd.h:86
T get_Kd()
Gets the derivative gain.
Definition pd.h:98
T update(T x_0, T x)
Computes the PD control output.
Definition pd.h:31
void set_Kp(T Kp_)
Sets the proportional gain.
Definition pd.h:68
Proportional-Derivative (PD) controller.
constexpr T saturate(T x, T x_min, T x_max)
Saturates a value within a specified range.
Definition utility.h:51