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.tpp
Go to the documentation of this file.
1
#include "
../../include/derivative/d.h
"
2
3
template
<
typename
T>
4
control_system::derivative::D<T>::D
()
5
{
6
dt = 0.0;
7
e_k_1 = 0.0;
8
Kd = 0.0;
9
start =
true
;
10
}
11
12
template
<
typename
T>
13
void
control_system::derivative::D<T>::init
(T dt_, T Kd_, T u_max_)
14
{
15
set_param(dt_, Kd_, u_max_);
16
start =
true
;
17
}
18
19
template
<
typename
T>
20
void
control_system::derivative::D<T>::set_param
(T dt_, T Kd_, T u_max_)
21
{
22
dt = dt_;
23
Kd = Kd_;
24
u_max = u_max_;
25
}
26
27
template
<
typename
T>
28
T
control_system::derivative::D<T>::update
(T x_0, T x)
29
{
30
T e_k = x_0 - x;
31
T u_k = 0.0;
32
if
(start ==
true
)
33
{
34
start =
false
;
35
u_k = 0.0;
36
}
37
else
38
{
39
u_k = Kd * (e_k - e_k_1) / dt;
40
}
41
u_k =
saturate
(u_k, -u_max, u_max);
42
e_k_1 = e_k;
43
return
u_k;
44
}
45
46
template
<
typename
T>
47
void
control_system::derivative::D<T>::reset
()
48
{
49
e_k_1 = 0.0;
50
start =
true
;
51
}
52
53
template
<
typename
T>
54
void
control_system::derivative::D<T>::merge
(T u_k_1_)
55
{
56
}
57
58
template
<
typename
T>
59
void
control_system::derivative::D<T>::set_dt
(T dt_)
60
{
61
dt = dt_;
62
}
63
64
template
<
typename
T>
65
void
control_system::derivative::D<T>::set_Kd
(T Kd_)
66
{
67
Kd = Kd_;
68
}
69
70
template
<
typename
T>
71
void
control_system::derivative::D<T>::set_u_max
(T u_max_)
72
{
73
u_max = u_max_;
74
}
75
76
template
<
typename
T>
77
T
control_system::derivative::D<T>::get_dt
()
78
{
79
return
dt;
80
}
81
82
template
<
typename
T>
83
T
control_system::derivative::D<T>::get_Kd
()
84
{
85
return
Kd;
86
}
87
88
template
<
typename
T>
89
T
control_system::derivative::D<T>::get_e_k_1
()
90
{
91
return
e_k_1;
92
}
control_system::derivative::D::reset
void reset()
Resets the derivative controller state.
Definition
d.h:48
control_system::derivative::D::set_u_max
void set_u_max(T u_max_)
Sets the maximum controller output.
Definition
d.h:72
control_system::derivative::D::get_Kd
T get_Kd()
Gets the derivative gain.
Definition
d.h:84
control_system::derivative::D::init
void init(T dt_, T Kd_, T u_max_)
Initializes the derivative controller.
Definition
d.h:14
control_system::derivative::D::D
D()
Constructs a derivative controller.
Definition
d.h:5
control_system::derivative::D::get_dt
T get_dt()
Gets the controller sampling time.
Definition
d.h:78
control_system::derivative::D::set_dt
void set_dt(T dt_)
Sets the controller sampling time.
Definition
d.h:60
control_system::derivative::D::set_param
void set_param(T dt_, T Kd_, T u_max_)
Sets the derivative controller parameters.
Definition
d.h:21
control_system::derivative::D::set_Kd
void set_Kd(T Kd_)
Sets the derivative gain.
Definition
d.h:66
control_system::derivative::D::update
T update(T x_0, T x)
Computes the derivative control output.
Definition
d.h:29
control_system::derivative::D::merge
void merge(T u_k_1_)
Merges an external controller output into the derivative state.
Definition
d.h:55
control_system::derivative::D::get_e_k_1
T get_e_k_1()
Gets the previous control error.
Definition
d.h:90
d.h
Derivative (D) 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
derivative
d.tpp
Generated by
1.17.0