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.
Toggle main menu visibility
Loading...
Searching...
No Matches
d_lpf_1.tpp
Go to the documentation of this file.
1
#include "
../../include/derivative/d_lpf_1.h
"
2
3
template
<
typename
T>
4
control_system::derivative::D_LPF_1<T>::D_LPF_1
()
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
15
template
<
typename
T>
16
void
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
22
template
<
typename
T>
23
void
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
31
template
<
typename
T>
32
T
control_system::derivative::D_LPF_1<T>::update
(T x_0, T x)
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
51
template
<
typename
T>
52
void
control_system::derivative::D_LPF_1<T>::reset
()
53
{
54
e_k_1 = 0.0;
55
start =
true
;
56
u_k_1 = 0.0;
57
}
58
59
template
<
typename
T>
60
void
control_system::derivative::D_LPF_1<T>::merge
(T u_k_1_)
61
{
62
u_k_1 = u_k_1_;
63
}
64
65
template
<
typename
T>
66
void
control_system::derivative::D_LPF_1<T>::set_dt
(T dt_)
67
{
68
dt = dt_;
69
}
70
71
template
<
typename
T>
72
void
control_system::derivative::D_LPF_1<T>::set_Kd
(T Kd_)
73
{
74
Kd = Kd_;
75
}
76
77
template
<
typename
T>
78
void
control_system::derivative::D_LPF_1<T>::set_fc
(T fc_)
79
{
80
tau = 1.0 / (6.28318530717958647692528676655900576 * fc_);
81
}
82
83
template
<
typename
T>
84
void
control_system::derivative::D_LPF_1<T>::set_u_max
(T u_max_)
85
{
86
u_max = u_max_;
87
}
88
89
template
<
typename
T>
90
T
control_system::derivative::D_LPF_1<T>::get_dt
()
91
{
92
return
dt;
93
}
94
95
template
<
typename
T>
96
T
control_system::derivative::D_LPF_1<T>::get_Kd
()
97
{
98
return
Kd;
99
}
100
101
template
<
typename
T>
102
T
control_system::derivative::D_LPF_1<T>::get_fc
()
103
{
104
return
1.0 / (6.28318530717958647692528676655900576 * tau);
105
}
106
107
template
<
typename
T>
108
T
control_system::derivative::D_LPF_1<T>::get_e_k_1
()
109
{
110
return
e_k_1;
111
}
112
113
template
<
typename
T>
114
T
control_system::derivative::D_LPF_1<T>::get_u_k_1
()
115
{
116
return
u_k_1;
117
}
118
119
template
<
typename
T>
120
T
control_system::derivative::D_LPF_1<T>::get_u_max
()
121
{
122
return
u_max;
123
}
control_system::derivative::D_LPF_1::D_LPF_1
D_LPF_1()
Constructs a derivative controller with filtered output.
Definition
d_lpf_1.h:5
control_system::derivative::D_LPF_1::set_Kd
void set_Kd(T Kd_)
Sets the derivative gain.
Definition
d_lpf_1.h:73
control_system::derivative::D_LPF_1::get_dt
T get_dt()
Gets the controller sampling time.
Definition
d_lpf_1.h:91
control_system::derivative::D_LPF_1::set_param
void set_param(T dt_, T Kd_, T fc_, T u_max_)
Sets the derivative controller parameters.
Definition
d_lpf_1.h:24
control_system::derivative::D_LPF_1::get_Kd
T get_Kd()
Gets the derivative gain.
Definition
d_lpf_1.h:97
control_system::derivative::D_LPF_1::update
T update(T x_0, T x)
Computes the filtered derivative control output.
Definition
d_lpf_1.h:33
control_system::derivative::D_LPF_1::reset
void reset()
Resets the derivative controller state.
Definition
d_lpf_1.h:53
control_system::derivative::D_LPF_1::set_dt
void set_dt(T dt_)
Sets the controller sampling time.
Definition
d_lpf_1.h:67
control_system::derivative::D_LPF_1::init
void init(T dt_, T Kd_, T fc_, T u_max_)
Initializes the derivative controller.
Definition
d_lpf_1.h:17
control_system::derivative::D_LPF_1::get_u_k_1
T get_u_k_1()
Gets the previous controller output.
Definition
d_lpf_1.h:115
control_system::derivative::D_LPF_1::set_u_max
void set_u_max(T u_max_)
Sets the maximum controller output.
Definition
d_lpf_1.h:85
control_system::derivative::D_LPF_1::merge
void merge(T u_k_1_)
Merges an external controller output into the derivative state.
Definition
d_lpf_1.h:61
control_system::derivative::D_LPF_1::set_fc
void set_fc(T fc_)
Sets the low-pass filter cutoff frequency.
Definition
d_lpf_1.h:79
control_system::derivative::D_LPF_1::get_fc
T get_fc()
Gets the low-pass filter cutoff frequency.
Definition
d_lpf_1.h:103
control_system::derivative::D_LPF_1::get_e_k_1
T get_e_k_1()
Gets the previous control error.
Definition
d_lpf_1.h:109
control_system::derivative::D_LPF_1::get_u_max
T get_u_max()
Gets the maximum controller output.
Definition
d_lpf_1.h:121
d_lpf_1.h
Derivative controller with first-order low-pass filtering.
saturate
constexpr T saturate(T x, T x_min, T x_max)
Saturates a value within a specified range.
Definition
utility.h:51
src
derivative
d_lpf_1.tpp
Generated by
1.17.0