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
pd.h
Go to the documentation of this file.
1
5 * @details
6 * This file defines the @ref control_system::pd::PD class, which
7 * implements a discrete-time proportional-derivative (PD) controller.
8 *
9 * The controller combines proportional and derivative actions to
10 * generate a control output based on the error between a reference
11 * value and the measured or current value.
12 *
13 * The controller maintains the previous control error as internal
14 * state 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_PD_PD_H
27#define CONTROL_SYSTEM_PD_PD_H
28
29#include "../utility/utility.h"
30
32{
37
38 namespace pd
39 {
44
50 * The PD class implements a discrete-time proportional-derivative
51 * controller using configurable proportional and derivative gains.
52 *
53 * The controller uses the sampling time for its discrete-time
54 * derivative action and maintains the previous control error as
55 * internal state.
56 *
57 * @tparam T Numeric data type used for the controller.
58 *
59 * @par Example
60 * @code{.cpp}
61 * control_system::pd::PD<double> controller;
62 *
63 * controller.init(
64 * 0.001,
65 * Kp,
66 * Kd,
67 * 100.0
68 * );
69 *
70 * double output = controller.update(reference, measurement);
71 * @endcode
72 */
73 template <typename T>
74 class PD
75 {
76 public:
78
80 * @details
81 * Constructs the controller with its parameters and internal
82 * state initialized to their default values.
83 */
84 PD();
85
86 /**
87 * @brief Initializes the PD controller.
88 *
89 * @param[in] dt_ Controller sampling time in seconds.
90 * @param[in] Kp_ Proportional gain.
91 * @param[in] Kd_ Derivative gain.
92 * @param[in] u_max_ Maximum allowed controller output.
93 *
94 * @details
95 * Initializes the controller sampling time, proportional and
96 * derivative gains, and output limit.
97 */
98 void init(T dt_, T Kp_, T Kd_, T u_max_);
99
102
104 * @param[in] Kp_ Proportional gain.
105 * @param[in] Kd_ Derivative gain.
106 * @param[in] u_max_ Maximum allowed controller output.
107 *
108 * @details
109 * Updates the controller sampling time, proportional and
110 * derivative gains, and maximum output limit.
111 */
112 void set_param(T dt_, T Kp_, T Kd_, T u_max_);
113
114
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_Kp(T Kp_);
163
169 void set_Kd(T Kd_);
170
176 void set_u_max(T u_max_);
177
183 T get_dt();
184
190 T get_Kp();
191
197 T get_Kd();
198
204 T get_e_k_1();
205
211 T get_u_max();
212
213 private:
221 T dt = 0.0;
222
229 T e_k_1 = 0.0;
230
234 T Kp = 0.0;
235
239 T Kd = 0.0;
240
247 bool start = true;
248
256 T u_max = 9999999999;
257 };
258
259#include "../../src/pd/pd.tpp"
260 }
261}
262
263#endif
T u_max
Maximum controller output.
Definition pd.h:256
void init(T dt_, T Kp_, T Kd_, T u_max_)
Initializes the PD controller.
Definition pd.h:15
PD()
Constructs a PD controller.
Definition pd.h:5
void set_u_max(T u_max_)
Sets the maximum controller output.
Definition pd.h:80
T get_u_max()
Gets the maximum controller output.
Definition pd.h:110
void set_dt(T dt_)
Sets the controller sampling time.
Definition pd.h:62
void set_Kd(T Kd_)
Sets the derivative gain.
Definition pd.h:74
T e_k_1
Previous control error.
Definition pd.h:229
void merge(T u_k_1_)
Merges an external controller output into the PD state.
Definition pd.h:57
T get_e_k_1()
Gets the previous control error.
Definition pd.h:104
void reset()
Resets the PD controller state.
Definition pd.h:50
void set_param(T dt_, T Kp_, T Kd_, T u_max_)
Sets the PD controller parameters.
Definition pd.h:22
T Kp
Proportional gain.
Definition pd.h:234
T dt
Controller sampling time.
Definition pd.h:221
bool start
Controller startup state.
Definition pd.h:247
T get_Kp()
Gets the proportional gain.
Definition pd.h:92
T get_dt()
Gets the controller sampling time.
Definition pd.h:86
T Kd
Derivative gain.
Definition pd.h:239
T get_Kd()
Gets the derivative gain.
Definition pd.h:98
T update(T x_0, T x)
Computes the PD control output.
Definition pd.h:31
void set_Kp(T Kp_)
Sets the proportional gain.
Definition pd.h:68
Contains control-system algorithms and controllers.
Definition d.h:32
Contains proportional-derivative controller implementations.
Utility functions for the Control System library.