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.h
Go to the documentation of this file.
1
5 * @details
6 * This file defines the @ref control_system::derivative::D class, which
7 * implements a discrete-time derivative controller.
8 *
9 * The controller generates a control output based on the rate of change
10 * of the control error between a reference value and the measured or
11 * current value.
12 *
13 * The controller maintains the previous control error as internal state
14 * and applies a configurable maximum output limit.
15 *
16 * @tparam T Numeric data type used for the controller calculations.
17 *
18 * @author Abhinay Kumar
19 * @version 1.0.0
20 * @date 2026-08-11
21 *
22 * @copyright
23 * Copyright (c) 2026 Abhinay Kumar
24 */
25
26#ifndef CONTROL_SYSTEM_DERIVATIVE_D_H
27#define CONTROL_SYSTEM_DERIVATIVE_D_H
28
30
32{
37
38 namespace derivative
39 {
44
48 *
49 * @details
50 * The D class implements a discrete-time derivative controller
51 * using a configurable derivative gain and sampling time.
52 *
53 * The derivative contribution is calculated from the change in
54 * control error between successive controller iterations.
55 *
56 * The previous control error is maintained as internal state and
57 * the controller output is limited by the configured maximum
58 * output value.
59 *
60 * @tparam T Numeric data type used for the controller.
61 *
62 * @par Example
63 * @code{.cpp}
64 * control_system::derivative::D<double> controller;
65 *
66 * controller.init(
67 * 0.001,
68 * Kd,
69 * 100.0
70 * );
71 *
72 * double output = controller.update(reference, measurement);
73 * @endcode
74 */
75 template <typename T>
76 class D
77 {
78 public:
82
84 * state initialized to their default values.
85 */
86 D();
87
88
90 *
91 * @param[in] dt_ Controller sampling time in seconds.
92 * @param[in] Kd_ Derivative gain.
93 * @param[in] u_max_ Maximum allowed controller output.
94 *
95 * @details
96 * Initializes the controller sampling time, derivative gain,
97 * and output limit.
98 */
99 void init(T dt_, T Kd_, T u_max_);
100
112 void set_param(T dt_, T Kd_, T u_max_);
113
128 T update(T x_0, T x);
129
136 void reset();
137
148 void merge(T u_k_1_);
149
155 void set_dt(T dt_);
156
162 void set_Kd(T Kd_);
163
169 void set_u_max(T u_max_);
170
176 T get_dt();
177
183 T get_Kd();
184
190 T get_e_k_1();
191
198
199 private:
207 T dt = 0.0;
208
215 T e_k_1 = 0.0;
216
220 T Kd = 0.0;
221
228 bool start = true;
229
237 T u_max = 9999999999;
238 };
239
241 }
242}
243
244#endif
void reset()
Resets the derivative controller state.
Definition d.h:48
bool start
Controller startup state.
Definition d.h:228
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
T e_k_1
Previous control error.
Definition d.h:215
D()
Constructs a derivative controller.
Definition d.h:5
T get_dt()
Gets the controller sampling time.
Definition d.h:78
T u_max
Maximum controller output.
Definition d.h:237
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 Kd
Derivative gain.
Definition d.h:220
T dt
Controller sampling time.
Definition d.h:207
T get_u_max()
Gets the maximum controller output.
T get_e_k_1()
Gets the previous control error.
Definition d.h:90
Contains control-system algorithms and controllers.
Definition d.h:32
Contains derivative controller implementations.
Utility functions for the Control System library.