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
pi.tpp
Go to the documentation of this file.
1
#include "
../../include/pi/pi.h
"
2
3
template
<
typename
T>
4
control_system::pi::PI<T>::PI
()
5
{
6
dt = 0.0;
7
Kp = 0.0;
8
Ki = 0.0;
9
u_k_1 = 0.0;
10
e_k_1 = 0.0;
11
start =
true
;
12
}
13
14
template
<
typename
T>
15
void
control_system::pi::PI<T>::init
(T dt_, T Kp_, T Ki_, T u_k_1_, T u_max_)
16
{
17
set_param(dt_, Kp_, Ki_, u_k_1_, u_max_);
18
start =
true
;
19
}
20
21
template
<
typename
T>
22
void
control_system::pi::PI<T>::set_param
(T dt_, T Kp_, T Ki_, T u_k_1_, T u_max_)
23
{
24
dt = dt_;
25
Kp = Kp_;
26
Ki = Ki_;
27
u_k_1 = u_k_1_;
28
u_max = u_max_;
29
}
30
31
template
<
typename
T>
32
T
control_system::pi::PI<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 = u_k_1 + Kp * e_k;
40
}
41
else
42
{
43
u_k = u_k_1 + (Kp + Ki * dt) * e_k - Kp * e_k_1;
44
}
45
u_k =
saturate
(u_k, -u_max, u_max);
46
u_k_1 = u_k;
47
e_k_1 = e_k;
48
return
u_k;
49
}
50
51
template
<
typename
T>
52
void
control_system::pi::PI<T>::reset
()
53
{
54
u_k_1 = 0.0;
55
e_k_1 = 0.0;
56
start =
false
;
57
}
58
59
template
<
typename
T>
60
void
control_system::pi::PI<T>::merge
(T u_k_1_)
61
{
62
u_k_1 = u_k_1_;
63
}
64
65
template
<
typename
T>
66
void
control_system::pi::PI<T>::set_dt
(T dt_)
67
{
68
dt = dt_;
69
}
70
71
template
<
typename
T>
72
void
control_system::pi::PI<T>::set_Kp
(T Kp_)
73
{
74
Kp = Kp_;
75
}
76
77
template
<
typename
T>
78
void
control_system::pi::PI<T>::set_Ki
(T Ki_)
79
{
80
Ki = Ki_;
81
}
82
83
template
<
typename
T>
84
void
control_system::pi::PI<T>::set_u_0
(T u_k_1_)
85
{
86
u_k_1 = u_k_1_;
87
}
88
89
template
<
typename
T>
90
void
control_system::pi::PI<T>::set_u_max
(T u_max_)
91
{
92
u_max = u_max_;
93
}
94
95
template
<
typename
T>
96
T
control_system::pi::PI<T>::get_dt
()
97
{
98
return
dt;
99
}
100
101
template
<
typename
T>
102
T
control_system::pi::PI<T>::get_Kp
()
103
{
104
return
Kp;
105
}
106
107
template
<
typename
T>
108
T
control_system::pi::PI<T>::get_Ki
()
109
{
110
return
Ki;
111
}
112
113
template
<
typename
T>
114
T
control_system::pi::PI<T>::get_u_k_1
()
115
{
116
return
u_k_1;
117
}
118
119
template
<
typename
T>
120
T
control_system::pi::PI<T>::get_u_max
()
121
{
122
return
u_max;
123
}
control_system::pi::PI::get_Ki
T get_Ki()
Gets the integral gain.
Definition
pi.h:109
control_system::pi::PI::set_Kp
void set_Kp(T Kp_)
Sets the proportional gain.
Definition
pi.h:73
control_system::pi::PI::reset
void reset()
Resets the PI controller state.
Definition
pi.h:53
control_system::pi::PI::set_dt
void set_dt(T dt_)
Sets the controller sampling time.
Definition
pi.h:67
control_system::pi::PI::update
T update(T x_0, T x)
Computes the PI control output.
Definition
pi.h:33
control_system::pi::PI::get_u_k_1
T get_u_k_1()
Gets the previous controller output.
Definition
pi.h:115
control_system::pi::PI::set_Ki
void set_Ki(T Ki_)
Sets the integral gain.
Definition
pi.h:79
control_system::pi::PI::set_u_0
void set_u_0(T u_k_1_)
Sets the previous controller output.
Definition
pi.h:85
control_system::pi::PI::init
void init(T dt_, T Kp_, T Ki_, T u_k_1_, T u_max_)
Initializes the PI controller.
Definition
pi.h:16
control_system::pi::PI::merge
void merge(T u_k_1_)
Merges an external controller output into the PI state.
Definition
pi.h:61
control_system::pi::PI::get_u_max
T get_u_max()
Gets the maximum controller output.
Definition
pi.h:121
control_system::pi::PI::set_param
void set_param(T dt_, T Kp_, T Ki_, T u_k_1_, T u_max_)
Sets the PI controller parameters.
Definition
pi.h:23
control_system::pi::PI::get_Kp
T get_Kp()
Gets the proportional gain.
Definition
pi.h:103
control_system::pi::PI::PI
PI()
Constructs a PI controller.
Definition
pi.h:5
control_system::pi::PI::get_dt
T get_dt()
Gets the controller sampling time.
Definition
pi.h:97
control_system::pi::PI::set_u_max
void set_u_max(T u_max_)
Sets the maximum controller output.
Definition
pi.h:91
pi.h
Proportional-Integral (PI) 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
pi
pi.tpp
Generated by
1.17.0