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.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
12template <typename T>
13void 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
19template <typename T>
20void 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
27template <typename T>
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
46template <typename T>
48{
49 e_k_1 = 0.0;
50 start = true;
51}
52
53template <typename T>
55{
56}
57
58template <typename T>
60{
61 dt = dt_;
62}
63
64template <typename T>
66{
67 Kd = Kd_;
68}
69
70template <typename T>
72{
73 u_max = u_max_;
74}
75
76template <typename T>
78{
79 return dt;
80}
81
82template <typename T>
84{
85 return Kd;
86}
87
88template <typename T>
90{
91 return e_k_1;
92}
void reset()
Resets the derivative controller state.
Definition d.h:48
void set_u_max(T u_max_)
Sets the maximum controller output.
Definition d.h:72
T get_Kd()
Gets the derivative gain.
Definition d.h:84
void init(T dt_, T Kd_, T u_max_)
Initializes the derivative controller.
Definition d.h:14
D()
Constructs a derivative controller.
Definition d.h:5
T get_dt()
Gets the controller sampling time.
Definition d.h:78
void set_dt(T dt_)
Sets the controller sampling time.
Definition d.h:60
void set_param(T dt_, T Kd_, T u_max_)
Sets the derivative controller parameters.
Definition d.h:21
void set_Kd(T Kd_)
Sets the derivative gain.
Definition d.h:66
T update(T x_0, T x)
Computes the derivative control output.
Definition d.h:29
void merge(T u_k_1_)
Merges an external controller output into the derivative state.
Definition d.h:55
T get_e_k_1()
Gets the previous control error.
Definition d.h:90
Derivative (D) controller.
constexpr T saturate(T x, T x_min, T x_max)
Saturates a value within a specified range.
Definition utility.h:51