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
d_lpf_1.tpp
Go to the documentation of this file.
2
3template <typename T>
5{
6 dt = 0.0;
7 e_k_1 = 0.0;
8 Kd = 0.0;
9 start = true;
10
11 u_k_1 = 0.0;
12 tau = 0.0;
13}
14
15template <typename T>
16void control_system::derivative::D_LPF_1<T>::init(T dt_, T Kd_, T fc_, T u_max_)
17{
18 set_param(dt_, Kd_, fc_, u_max_);
19 start = true;
20}
21
22template <typename T>
23void control_system::derivative::D_LPF_1<T>::set_param(T dt_, T Kd_, T fc_, T u_max_)
24{
25 dt = dt_;
26 Kd = Kd_;
27 tau = 1.0 / (6.28318530717958647692528676655900576 * fc_);
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 = 0.0;
40 }
41 else
42 {
43 u_k = (tau * u_k_1 + Kd * (e_k - e_k_1)) / (tau + dt);
44 }
45 u_k = saturate(u_k, -u_max, u_max);
46 e_k_1 = e_k;
47 u_k_1 = u_k;
48 return u_k;
49}
50
51template <typename T>
53{
54 e_k_1 = 0.0;
55 start = true;
56 u_k_1 = 0.0;
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 Kd = Kd_;
75}
76
77template <typename T>
79{
80 tau = 1.0 / (6.28318530717958647692528676655900576 * fc_);
81}
82
83template <typename T>
85{
86 u_max = u_max_;
87}
88
89template <typename T>
91{
92 return dt;
93}
94
95template <typename T>
97{
98 return Kd;
99}
100
101template <typename T>
103{
104 return 1.0 / (6.28318530717958647692528676655900576 * tau);
105}
106
107template <typename T>
109{
110 return e_k_1;
111}
112
113template <typename T>
115{
116 return u_k_1;
117}
118
119template <typename T>
121{
122 return u_max;
123}
D_LPF_1()
Constructs a derivative controller with filtered output.
Definition d_lpf_1.h:5
void set_Kd(T Kd_)
Sets the derivative gain.
Definition d_lpf_1.h:73
T get_dt()
Gets the controller sampling time.
Definition d_lpf_1.h:91
void set_param(T dt_, T Kd_, T fc_, T u_max_)
Sets the derivative controller parameters.
Definition d_lpf_1.h:24
T get_Kd()
Gets the derivative gain.
Definition d_lpf_1.h:97
T update(T x_0, T x)
Computes the filtered derivative control output.
Definition d_lpf_1.h:33
void reset()
Resets the derivative controller state.
Definition d_lpf_1.h:53
void set_dt(T dt_)
Sets the controller sampling time.
Definition d_lpf_1.h:67
void init(T dt_, T Kd_, T fc_, T u_max_)
Initializes the derivative controller.
Definition d_lpf_1.h:17
T get_u_k_1()
Gets the previous controller output.
Definition d_lpf_1.h:115
void set_u_max(T u_max_)
Sets the maximum controller output.
Definition d_lpf_1.h:85
void merge(T u_k_1_)
Merges an external controller output into the derivative state.
Definition d_lpf_1.h:61
void set_fc(T fc_)
Sets the low-pass filter cutoff frequency.
Definition d_lpf_1.h:79
T get_fc()
Gets the low-pass filter cutoff frequency.
Definition d_lpf_1.h:103
T get_e_k_1()
Gets the previous control error.
Definition d_lpf_1.h:109
T get_u_max()
Gets the maximum controller output.
Definition d_lpf_1.h:121
Derivative controller with first-order low-pass filtering.
constexpr T saturate(T x, T x_min, T x_max)
Saturates a value within a specified range.
Definition utility.h:51