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
pd.tpp
Go to the documentation of this file.
1
#include "
../../include/pd/pd.h
"
2
3
template
<
typename
T>
4
control_system::pd::PD<T>::PD
()
5
{
6
dt = 0.0;
7
e_k_1 = 0.0;
8
Kp = 0.0;
9
Kd = 0.0;
10
start =
true
;
11
}
12
13
template
<
typename
T>
14
void
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
20
template
<
typename
T>
21
void
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
29
template
<
typename
T>
30
T
control_system::pd::PD<T>::update
(T x_0, T x)
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
48
template
<
typename
T>
49
void
control_system::pd::PD<T>::reset
()
50
{
51
e_k_1 = 0.0;
52
start =
true
;
53
}
54
55
template
<
typename
T>
56
void
control_system::pd::PD<T>::merge
(T u_k_1_)
57
{
58
}
59
60
template
<
typename
T>
61
void
control_system::pd::PD<T>::set_dt
(T dt_)
62
{
63
dt = dt_;
64
}
65
66
template
<
typename
T>
67
void
control_system::pd::PD<T>::set_Kp
(T Kp_)
68
{
69
Kp = Kp_;
70
}
71
72
template
<
typename
T>
73
void
control_system::pd::PD<T>::set_Kd
(T Kd_)
74
{
75
Kd = Kd_;
76
}
77
78
template
<
typename
T>
79
void
control_system::pd::PD<T>::set_u_max
(T u_max_)
80
{
81
u_max = u_max_;
82
}
83
84
template
<
typename
T>
85
T
control_system::pd::PD<T>::get_dt
()
86
{
87
return
dt;
88
}
89
90
template
<
typename
T>
91
T
control_system::pd::PD<T>::get_Kp
()
92
{
93
return
Kp;
94
}
95
96
template
<
typename
T>
97
T
control_system::pd::PD<T>::get_Kd
()
98
{
99
return
Kd;
100
}
101
102
template
<
typename
T>
103
T
control_system::pd::PD<T>::get_e_k_1
()
104
{
105
return
e_k_1;
106
}
107
108
template
<
typename
T>
109
T
control_system::pd::PD<T>::get_u_max
()
110
{
111
return
u_max;
112
}
control_system::pd::PD::init
void init(T dt_, T Kp_, T Kd_, T u_max_)
Initializes the PD controller.
Definition
pd.h:15
control_system::pd::PD::PD
PD()
Constructs a PD controller.
Definition
pd.h:5
control_system::pd::PD::set_u_max
void set_u_max(T u_max_)
Sets the maximum controller output.
Definition
pd.h:80
control_system::pd::PD::get_u_max
T get_u_max()
Gets the maximum controller output.
Definition
pd.h:110
control_system::pd::PD::set_dt
void set_dt(T dt_)
Sets the controller sampling time.
Definition
pd.h:62
control_system::pd::PD::set_Kd
void set_Kd(T Kd_)
Sets the derivative gain.
Definition
pd.h:74
control_system::pd::PD::merge
void merge(T u_k_1_)
Merges an external controller output into the PD state.
Definition
pd.h:57
control_system::pd::PD::get_e_k_1
T get_e_k_1()
Gets the previous control error.
Definition
pd.h:104
control_system::pd::PD::reset
void reset()
Resets the PD controller state.
Definition
pd.h:50
control_system::pd::PD::set_param
void set_param(T dt_, T Kp_, T Kd_, T u_max_)
Sets the PD controller parameters.
Definition
pd.h:22
control_system::pd::PD::get_Kp
T get_Kp()
Gets the proportional gain.
Definition
pd.h:92
control_system::pd::PD::get_dt
T get_dt()
Gets the controller sampling time.
Definition
pd.h:86
control_system::pd::PD::get_Kd
T get_Kd()
Gets the derivative gain.
Definition
pd.h:98
control_system::pd::PD::update
T update(T x_0, T x)
Computes the PD control output.
Definition
pd.h:31
control_system::pd::PD::set_Kp
void set_Kp(T Kp_)
Sets the proportional gain.
Definition
pd.h:68
pd.h
Proportional-Derivative (PD) controller.
saturate
constexpr T saturate(T x, T x_min, T x_max)
Saturates a value within a specified range.
Definition
utility.h:51
src
pd
pd.tpp
Generated by
1.17.0