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
pd_lpf_1.h
Go to the documentation of this file.
1
5
* @details
6
* This file defines the @ref control_system::pd::PD_LPF_1 class, which
7
* implements a discrete-time proportional-derivative (PD) controller
8
* with a first-order low-pass filter associated with the derivative
9
* action.
10
*
11
* The controller uses configurable proportional and derivative gains,
12
* sampling time, derivative filter cutoff frequency, and maximum output
13
* limit.
14
*
15
* The previous control error and controller output are maintained as
16
* internal state variables.
17
*
18
* @tparam T Numeric data type used for the controller calculations.
19
*
20
* @author Abhinay Kumar
21
* @version 1.0.0
22
* @date 2026-08-11
23
*
24
* @copyright
25
* Copyright (c) 2026 Abhinay Kumar
26
*/
27
28
#ifndef CONTROL_SYSTEM_PD_PD_LPF_1_H
29
#define CONTROL_SYSTEM_PD_PD_LPF_1_H
30
31
#include "
../utility/utility.h
"
32
33
namespace
control_system
34
{
39
40
namespace
pd
41
{
46
52
54
* associated with the derivative action.
55
*
56
* The controller uses the sampling time, proportional gain,
57
* derivative gain, and derivative filter cutoff frequency to
58
* calculate the control output.
59
*
60
* The controller maintains the previous control error and
61
* controller output as internal state and applies a configurable
62
* maximum output limit.
63
*
64
* @tparam T Numeric data type used for the controller.
65
*
66
* @par Example
67
* @code{.cpp}
68
* control_system::pd::PD_LPF_1<double> controller;
69
*
70
* controller.init(
71
* 0.001,
72
* Kp,
73
* Kd,
74
* 10.0,
75
* 100.0
76
* );
77
*
78
* double output = controller.update(reference, measurement);
79
* @endcode
80
*/
81
template
<
typename
T>
82
class
PD_LPF_1
83
{
84
public
:
85
/**
86
* @brief Constructs a PD controller with filtered derivative.
87
*
88
* @details
89
* Constructs the controller with its parameters and internal
90
* state initialized to their default values.
91
*/
92
PD_LPF_1
();
93
95
97
* @param[in] dt_ Controller sampling time in seconds.
98
* @param[in] Kp_ Proportional gain.
99
* @param[in] Kd_ Derivative gain.
100
* @param[in] fc_ Derivative filter cutoff frequency in Hz.
101
* @param[in] u_max_ Maximum allowed controller output.
102
*
103
* @details
104
* Initializes the controller sampling time, proportional and
105
* derivative gains, derivative filter cutoff frequency, and
106
* output limit.
107
*/
108
void
init
(T dt_, T Kp_, T Kd_, T fc_, T u_max_);
109
113
115
* @param[in] Kd_ Derivative gain.
116
* @param[in] fc_ Derivative filter cutoff frequency in Hz.
117
* @param[in] u_max_ Maximum allowed controller output.
118
*
119
* @details
120
* Updates the controller sampling time, proportional and
121
* derivative gains, derivative filter cutoff frequency, and
122
* output limit.
123
*/
124
void
set_param
(T dt_, T Kp_, T Kd_, T fc_, T u_max_);
125
127
* @brief Computes the PD control output.
128
*
129
* @param[in] x_0 Reference or desired value.
130
* @param[in] x Current or measured value.
131
*
132
* @return PD controller output limited by the configured
133
* maximum output.
134
*
135
* @details
136
* Calculates the proportional and derivative contributions
137
* using the current and previous control errors. The
138
* derivative action is associated with a first-order
139
* low-pass filter.
140
*/
141
T
update
(T x_0, T x);
142
150
void
reset
();
151
162
void
merge
(T u_k_1_);
163
169
void
set_dt
(T dt_);
170
176
void
set_Kp
(T Kp_);
177
183
void
set_Kd
(T Kd_);
184
190
void
set_fc
(T fc_);
191
197
void
set_u_max
(T u_max_);
198
204
T
get_dt
();
205
211
T
get_Kp
();
212
218
T
get_Kd
();
219
225
T
get_fc
();
226
232
T
get_e_k_1
();
233
239
T
get_u_k_1
();
240
246
T
get_u_max
();
247
248
private
:
256
T
dt
= 0.0;
257
264
T
e_k_1
= 0.0;
265
269
T
Kp
= 0.0;
270
274
T
Kd
= 0.0;
275
282
bool
start
=
true
;
283
290
T
u_k_1
= 0.0;
291
299
T
tau
= 0.0;
300
308
T
u_max
= 9999999999;
309
};
310
311
#include "
../../src/pd/pd_lpf_1.tpp
"
312
}
313
}
314
315
#endif
control_system::pd::PD_LPF_1::u_k_1
T u_k_1
Previous controller output.
Definition
pd_lpf_1.h:290
control_system::pd::PD_LPF_1::get_fc
T get_fc()
Gets the derivative filter cutoff frequency.
Definition
pd_lpf_1.h:115
control_system::pd::PD_LPF_1::PD_LPF_1
PD_LPF_1()
Constructs a PD controller with filtered derivative.
Definition
pd_lpf_1.h:5
control_system::pd::PD_LPF_1::set_fc
void set_fc(T fc_)
Sets the derivative filter cutoff frequency.
Definition
pd_lpf_1.h:85
control_system::pd::PD_LPF_1::Kd
T Kd
Derivative gain.
Definition
pd_lpf_1.h:274
control_system::pd::PD_LPF_1::merge
void merge(T u_k_1_)
Merges an external controller output into the PD state.
Definition
pd_lpf_1.h:62
control_system::pd::PD_LPF_1::set_param
void set_param(T dt_, T Kp_, T Kd_, T fc_, T u_max_)
Sets the PD controller parameters.
Definition
pd_lpf_1.h:24
control_system::pd::PD_LPF_1::get_Kp
T get_Kp()
Gets the proportional gain.
Definition
pd_lpf_1.h:103
control_system::pd::PD_LPF_1::u_max
T u_max
Maximum controller output.
Definition
pd_lpf_1.h:308
control_system::pd::PD_LPF_1::e_k_1
T e_k_1
Previous control error.
Definition
pd_lpf_1.h:264
control_system::pd::PD_LPF_1::get_u_k_1
T get_u_k_1()
Gets the previous controller output.
Definition
pd_lpf_1.h:127
control_system::pd::PD_LPF_1::tau
T tau
Time constant of the derivative low-pass filter.
Definition
pd_lpf_1.h:299
control_system::pd::PD_LPF_1::start
bool start
Controller startup state.
Definition
pd_lpf_1.h:282
control_system::pd::PD_LPF_1::get_e_k_1
T get_e_k_1()
Gets the previous control error.
Definition
pd_lpf_1.h:121
control_system::pd::PD_LPF_1::set_u_max
void set_u_max(T u_max_)
Sets the maximum controller output.
Definition
pd_lpf_1.h:91
control_system::pd::PD_LPF_1::get_u_max
T get_u_max()
Gets the maximum controller output.
Definition
pd_lpf_1.h:133
control_system::pd::PD_LPF_1::set_Kd
void set_Kd(T Kd_)
Sets the derivative gain.
Definition
pd_lpf_1.h:79
control_system::pd::PD_LPF_1::get_Kd
T get_Kd()
Gets the derivative gain.
Definition
pd_lpf_1.h:109
control_system::pd::PD_LPF_1::set_dt
void set_dt(T dt_)
Sets the controller sampling time.
Definition
pd_lpf_1.h:67
control_system::pd::PD_LPF_1::init
void init(T dt_, T Kp_, T Kd_, T fc_, T u_max_)
Initializes the PD controller.
Definition
pd_lpf_1.h:17
control_system::pd::PD_LPF_1::update
T update(T x_0, T x)
Computes the PD control output.
Definition
pd_lpf_1.h:34
control_system::pd::PD_LPF_1::Kp
T Kp
Proportional gain.
Definition
pd_lpf_1.h:269
control_system::pd::PD_LPF_1::dt
T dt
Controller sampling time.
Definition
pd_lpf_1.h:256
control_system::pd::PD_LPF_1::reset
void reset()
Resets the PD controller state.
Definition
pd_lpf_1.h:54
control_system::pd::PD_LPF_1::set_Kp
void set_Kp(T Kp_)
Sets the proportional gain.
Definition
pd_lpf_1.h:73
control_system::pd::PD_LPF_1::get_dt
T get_dt()
Gets the controller sampling time.
Definition
pd_lpf_1.h:97
control_system
Contains control-system algorithms and controllers.
Definition
d.h:32
pd
Contains proportional-derivative controller implementations.
pd_lpf_1.tpp
utility.h
Utility functions for the Control System library.
include
pd
pd_lpf_1.h
Generated by
1.17.0