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_lpf_1.h
Go to the documentation of this file.
1
5 * @details
6 * This file defines the @ref control_system::derivative::D_LPF_1 class,
7 * which implements a discrete-time derivative controller with a
8 * first-order low-pass filter.
9 *
10 * The controller uses a configurable derivative gain, sampling time,
11 * and filter cutoff frequency. The previous control error and controller
12 * output are maintained as internal state variables.
13 *
14 * The controller output is constrained by a configurable maximum output
15 * limit.
16 *
17 * @tparam T Numeric data type used for the controller calculations.
18 *
19 * @author Abhinay Kumar
20 * @version 1.0.0
21 * @date 2026-08-11
22 *
23 * @copyright
24 * Copyright (c) 2026 Abhinay Kumar
25 */
26
27#ifndef CONTROL_SYSTEM_DERIVATIVE_D_LPF_1_H
28#define CONTROL_SYSTEM_DERIVATIVE_D_LPF_1_H
29
30#include "../utility/utility.h"
31
32namespace control_system
38
39 namespace derivative
40 {
45
51
53 * derivative action.
54 *
55 * The controller uses the sampling time, derivative gain, and
56 * filter cutoff frequency to calculate the derivative contribution.
57 *
58 * The previous control error and controller output are maintained
59 * as internal state, and the controller output is limited by the
60 * configured maximum output.
61 *
62 * @tparam T Numeric data type used for the controller.
63 *
64 * @par Example
65 * @code{.cpp}
66 * control_system::derivative::D_LPF_1<double> controller;
67 *
68 * controller.init(
69 * 0.001,
70 * Kd,
71 * 10.0,
72 * 100.0
73 * );
74 *
75 * double output = controller.update(reference, measurement);
76 * @endcode
77 */
78 template <typename T>
79 class D_LPF_1
80 {
81 public:
83
85 * @details
86 * Constructs the controller with its parameters and internal
87 * state initialized to their default values.
88 */
89 D_LPF_1();
90
91 /**
92 * @brief Initializes the derivative controller.
93 *
94 * @param[in] dt_ Controller sampling time in seconds.
95 * @param[in] Kd_ Derivative gain.
96 * @param[in] fc_ Low-pass filter cutoff frequency in Hz.
97 * @param[in] u_max_ Maximum allowed controller output.
98 *
99 * @details
100 * Initializes the controller sampling time, derivative gain,
101 * filter cutoff frequency, and output limit.
102 */
103 void init(T dt_, T Kd_, T fc_, T u_max_);
104
107
109 * @param[in] Kd_ Derivative gain.
110 * @param[in] fc_ Low-pass filter cutoff frequency in Hz.
111 * @param[in] u_max_ Maximum allowed controller output.
112 *
113 * @details
114 * Updates the controller sampling time, derivative gain,
115 * filter cutoff frequency, and maximum output limit.
116 */
117 void set_param(T dt_, T Kd_, T fc_, T u_max_);
118
119
122 * @param[in] x_0 Reference or desired value.
123 * @param[in] x Current or measured value.
124 *
125 * @return Filtered derivative controller output limited by
126 * the configured maximum output.
127 *
128 * @details
129 * Calculates the derivative contribution from the change in
130 * control error and applies the configured first-order
131 * low-pass filtering.
132 */
133 T update(T x_0, T x);
134
142 void reset();
143
154 void merge(T u_k_1_);
155
161 void set_dt(T dt_);
162
168 void set_Kd(T Kd_);
169
175 void set_fc(T fc_);
176
182 void set_u_max(T u_max_);
183
189 T get_dt();
190
196 T get_Kd();
197
203 T get_fc();
204
210 T get_e_k_1();
211
217 T get_u_k_1();
218
224 T get_u_max();
225
226 private:
234 T dt = 0.0;
235
242 T e_k_1 = 0.0;
243
247 T Kd = 0.0;
248
255 bool start = true;
256
263 T u_k_1 = 0.0;
264
268 T tau = 0.0;
269
277 T u_max = 9999999999;
278 };
279
281 }
282}
283
284#endif
D_LPF_1()
Constructs a derivative controller with filtered output.
Definition d_lpf_1.h:5
T e_k_1
Previous control error.
Definition d_lpf_1.h:242
void set_Kd(T Kd_)
Sets the derivative gain.
Definition d_lpf_1.h:73
T get_dt()
Gets the controller sampling time.
Definition d_lpf_1.h:91
void set_param(T dt_, T Kd_, T fc_, T u_max_)
Sets the derivative controller parameters.
Definition d_lpf_1.h:24
T get_Kd()
Gets the derivative gain.
Definition d_lpf_1.h:97
T dt
Controller sampling time.
Definition d_lpf_1.h:234
T update(T x_0, T x)
Computes the filtered derivative control output.
Definition d_lpf_1.h:33
void reset()
Resets the derivative controller state.
Definition d_lpf_1.h:53
T u_k_1
Previous controller output.
Definition d_lpf_1.h:263
void set_dt(T dt_)
Sets the controller sampling time.
Definition d_lpf_1.h:67
void init(T dt_, T Kd_, T fc_, T u_max_)
Initializes the derivative controller.
Definition d_lpf_1.h:17
T get_u_k_1()
Gets the previous controller output.
Definition d_lpf_1.h:115
void set_u_max(T u_max_)
Sets the maximum controller output.
Definition d_lpf_1.h:85
T u_max
Maximum controller output.
Definition d_lpf_1.h:277
void merge(T u_k_1_)
Merges an external controller output into the derivative state.
Definition d_lpf_1.h:61
bool start
Controller startup state.
Definition d_lpf_1.h:255
void set_fc(T fc_)
Sets the low-pass filter cutoff frequency.
Definition d_lpf_1.h:79
T tau
Time constant of the first-order low-pass filter.
Definition d_lpf_1.h:268
T get_fc()
Gets the low-pass filter cutoff frequency.
Definition d_lpf_1.h:103
T get_e_k_1()
Gets the previous control error.
Definition d_lpf_1.h:109
T get_u_max()
Gets the maximum controller output.
Definition d_lpf_1.h:121
Contains control-system algorithms and controllers.
Definition d.h:32
Contains derivative controller implementations.
Utility functions for the Control System library.