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
pi.h
Go to the documentation of this file.
1
5
* @details
6
* This file defines the @ref control_system::pi::PI class, which
7
* implements a discrete-time proportional-integral (PI) controller.
8
*
9
* The controller combines proportional and integral actions to generate
10
* a control output based on the error between a reference value and the
11
* measured or current value.
12
*
13
* The controller maintains the previous control error and previous
14
* controller output as internal state variables and applies a configurable
15
* maximum output 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_PI_PI_H
28
#define CONTROL_SYSTEM_PI_PI_H
29
30
#include "
../utility/utility.h
"
31
32
namespace
control_system
33
{
38
39
namespace
pi
40
{
45
53
*
54
* The controller uses the sampling time for its discrete-time
55
* integral action and maintains the previous control error and
56
* controller output as internal state.
57
*
58
* @tparam T Numeric data type used for the controller.
59
*
60
* @par Example
61
* @code{.cpp}
62
* control_system::pi::PI<double> controller;
63
*
64
* controller.init(
65
* 0.001,
66
* Kp,
67
* Ki,
68
* 0.0,
69
* 100.0
70
* );
71
*
72
* double output = controller.update(reference, measurement);
73
* @endcode
74
*/
75
template
<
typename
T>
76
class
PI
77
{
78
public
:
79
/**
80
* @brief Constructs a PI controller.
81
*
82
* @details
83
* Constructs the controller with its parameters and internal
84
* state initialized to their default values.
85
*/
86
PI
();
87
89
91
* @param[in] dt_ Controller sampling time in seconds.
92
* @param[in] Kp_ Proportional gain.
93
* @param[in] Ki_ Integral gain.
94
* @param[in] u_k_1_ Previous controller output.
95
* @param[in] u_max_ Maximum allowed controller output.
96
*
97
* @details
98
* Initializes the controller sampling time, proportional and
99
* integral gains, previous controller output, and output limit.
100
*/
101
void
init
(T dt_, T Kp_, T Ki_, T u_k_1_, T u_max_);
102
103
/**
104
* @brief Sets the PI controller parameters.
105
*
106
* @param[in] dt_ Controller sampling time in seconds.
107
* @param[in] Kp_ Proportional gain.
108
* @param[in] Ki_ Integral gain.
109
* @param[in] u_k_1_ Previous controller output.
110
* @param[in] u_max_ Maximum allowed controller output.
111
*
112
* @details
113
* Updates the controller sampling time, gains, previous
114
* controller output, and maximum output limit.
115
*/
116
void
set_param
(T dt_, T Kp_, T Ki_, T u_k_1_, T u_max_);
117
119
121
* @param[in] x_0 Reference or desired value.
122
* @param[in] x Current or measured value.
123
*
124
* @return PI controller output limited by the configured
125
* maximum output.
126
*
127
* @details
128
* Calculates the proportional and integral contributions
129
* using the current control error and the stored controller
130
* state.
131
*/
132
T
update
(T x_0, T x);
133
141
void
reset
();
142
153
void
merge
(T u_k_1_);
154
160
void
set_dt
(T dt_);
161
167
void
set_Kp
(T Kp_);
168
174
void
set_Ki
(T Ki_);
175
181
void
set_u_0
(T u_k_1_);
182
188
void
set_u_max
(T u_max_);
189
195
T
get_dt
();
196
202
T
get_Kp
();
203
209
T
get_Ki
();
210
216
T
get_u_k_1
();
217
223
T
get_u_max
();
224
225
private
:
233
T
dt
= 0.0;
234
241
T
u_k_1
= 0.0;
242
249
T
e_k_1
= 0.0;
250
254
T
Kp
= 0.0;
255
259
T
Ki
= 0.0;
260
268
T
u_max
= 9999999999;
269
276
bool
start
=
true
;
277
};
278
279
#include "
../../src/pi/pi.tpp
"
280
}
281
}
282
283
#endif
control_system::pi::PI::get_Ki
T get_Ki()
Gets the integral gain.
Definition
pi.h:109
control_system::pi::PI::set_Kp
void set_Kp(T Kp_)
Sets the proportional gain.
Definition
pi.h:73
control_system::pi::PI::u_max
T u_max
Maximum controller output.
Definition
pi.h:268
control_system::pi::PI::e_k_1
T e_k_1
Previous control error.
Definition
pi.h:249
control_system::pi::PI::start
bool start
Controller startup state.
Definition
pi.h:276
control_system::pi::PI::reset
void reset()
Resets the PI controller state.
Definition
pi.h:53
control_system::pi::PI::set_dt
void set_dt(T dt_)
Sets the controller sampling time.
Definition
pi.h:67
control_system::pi::PI::update
T update(T x_0, T x)
Computes the PI control output.
Definition
pi.h:33
control_system::pi::PI::get_u_k_1
T get_u_k_1()
Gets the previous controller output.
Definition
pi.h:115
control_system::pi::PI::u_k_1
T u_k_1
Previous controller output.
Definition
pi.h:241
control_system::pi::PI::set_Ki
void set_Ki(T Ki_)
Sets the integral gain.
Definition
pi.h:79
control_system::pi::PI::Ki
T Ki
Integral gain.
Definition
pi.h:259
control_system::pi::PI::set_u_0
void set_u_0(T u_k_1_)
Sets the previous controller output.
Definition
pi.h:85
control_system::pi::PI::dt
T dt
Controller sampling time.
Definition
pi.h:233
control_system::pi::PI::init
void init(T dt_, T Kp_, T Ki_, T u_k_1_, T u_max_)
Initializes the PI controller.
Definition
pi.h:16
control_system::pi::PI::merge
void merge(T u_k_1_)
Merges an external controller output into the PI state.
Definition
pi.h:61
control_system::pi::PI::get_u_max
T get_u_max()
Gets the maximum controller output.
Definition
pi.h:121
control_system::pi::PI::set_param
void set_param(T dt_, T Kp_, T Ki_, T u_k_1_, T u_max_)
Sets the PI controller parameters.
Definition
pi.h:23
control_system::pi::PI::get_Kp
T get_Kp()
Gets the proportional gain.
Definition
pi.h:103
control_system::pi::PI::Kp
T Kp
Proportional gain.
Definition
pi.h:254
control_system::pi::PI::PI
PI()
Constructs a PI controller.
Definition
pi.h:5
control_system::pi::PI::get_dt
T get_dt()
Gets the controller sampling time.
Definition
pi.h:97
control_system::pi::PI::set_u_max
void set_u_max(T u_max_)
Sets the maximum controller output.
Definition
pi.h:91
control_system
Contains control-system algorithms and controllers.
Definition
d.h:32
pi
Contains proportional-integral controller implementations.
pi.tpp
utility.h
Utility functions for the Control System library.
include
pi
pi.h
Generated by
1.17.0