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
control_system::pi::PI< T > Class Template Reference

Discrete-time proportional-integral controller. More...

#include <pi.h>

Public Member Functions

 PI ()
 Constructs a PI controller.
get_dt ()
 Gets the controller sampling time.
get_Ki ()
 Gets the integral gain.
get_Kp ()
 Gets the proportional gain.
get_u_k_1 ()
 Gets the previous controller output.
get_u_max ()
 Gets the maximum controller output.
void init (T dt_, T Kp_, T Ki_, T u_k_1_, T u_max_)
 Initializes the PI controller.
void merge (T u_k_1_)
 Merges an external controller output into the PI state.
void reset ()
 Resets the PI controller state.
void set_dt (T dt_)
 Sets the controller sampling time.
void set_Ki (T Ki_)
 Sets the integral gain.
void set_Kp (T Kp_)
 Sets the proportional gain.
void set_param (T dt_, T Kp_, T Ki_, T u_k_1_, T u_max_)
 Sets the PI controller parameters.
void set_u_0 (T u_k_1_)
 Sets the previous controller output.
void set_u_max (T u_max_)
 Sets the maximum controller output.
update (T x_0, T x)
 Computes the PI control output.

Private Attributes

dt = 0.0
 Controller sampling time.
e_k_1 = 0.0
 Previous control error.
Ki = 0.0
 Integral gain.
Kp = 0.0
 Proportional gain.
bool start = true
 Controller startup state.
u_k_1 = 0.0
 Previous controller output.
u_max = 9999999999
 Maximum controller output.

Detailed Description

template<typename T>
class control_system::pi::PI< T >

Discrete-time proportional-integral controller.

The PI class implements a discrete-time proportional-integral controller using configurable proportional and integral gains.

The controller uses the sampling time for its discrete-time integral action and maintains the previous control error and controller output as internal state.

Template Parameters
TNumeric data type used for the controller.
Example
controller.init(
0.001,
Kp,
Ki,
0.0,
100.0
);
double output = controller.update(reference, measurement);
Discrete-time proportional-integral controller.
Definition pi.h:77
T update(T x_0, T x)
Computes the PI control output.
Definition pi.h:33
T Ki
Integral gain.
Definition pi.h:259
void init(T dt_, T Kp_, T Ki_, T u_k_1_, T u_max_)
Initializes the PI controller.
Definition pi.h:16
T Kp
Proportional gain.
Definition pi.h:254

Definition at line 76 of file pi.h.

Constructor & Destructor Documentation

◆ PI()

template<typename T>
control_system::pi::PI< T >::PI ( )

Constructs a PI controller.

Constructs the controller with its parameters and internal state initialized to their default values.

Definition at line 5 of file pi.h.

Member Function Documentation

◆ get_dt()

template<typename T>
T control_system::pi::PI< T >::get_dt ( )

Gets the controller sampling time.

Returns
Sampling time in seconds.

Definition at line 97 of file pi.h.

◆ get_Ki()

template<typename T>
T control_system::pi::PI< T >::get_Ki ( )

Gets the integral gain.

Returns
Integral gain.

Definition at line 109 of file pi.h.

◆ get_Kp()

template<typename T>
T control_system::pi::PI< T >::get_Kp ( )

Gets the proportional gain.

Returns
Proportional gain.

Definition at line 103 of file pi.h.

◆ get_u_k_1()

template<typename T>
T control_system::pi::PI< T >::get_u_k_1 ( )

Gets the previous controller output.

Returns
Previous controller output.

Definition at line 115 of file pi.h.

◆ get_u_max()

template<typename T>
T control_system::pi::PI< T >::get_u_max ( )

Gets the maximum controller output.

Returns
Maximum allowed controller output.

Definition at line 121 of file pi.h.

◆ init()

template<typename T>
void control_system::pi::PI< T >::init ( T dt_,
T Kp_,
T Ki_,
T u_k_1_,
T u_max_ )

Initializes the PI controller.

Parameters
[in]dt_Controller sampling time in seconds.
[in]Kp_Proportional gain.
[in]Ki_Integral gain.
[in]u_k_1_Previous controller output.
[in]u_max_Maximum allowed controller output.

Initializes the controller sampling time, proportional and integral gains, previous controller output, and output limit.

Definition at line 16 of file pi.h.

◆ merge()

template<typename T>
void control_system::pi::PI< T >::merge ( T u_k_1_)

Merges an external controller output into the PI state.

Parameters
[in]u_k_1_Previous or externally provided controller output.

Updates the internal previous-output state using the specified controller output.

Definition at line 61 of file pi.h.

◆ reset()

template<typename T>
void control_system::pi::PI< T >::reset ( )

Resets the PI controller state.

Resets the stored previous control error, previous controller output, and startup state.

Definition at line 53 of file pi.h.

◆ set_dt()

template<typename T>
void control_system::pi::PI< T >::set_dt ( T dt_)

Sets the controller sampling time.

Parameters
[in]dt_Sampling time in seconds.

Definition at line 67 of file pi.h.

◆ set_Ki()

template<typename T>
void control_system::pi::PI< T >::set_Ki ( T Ki_)

Sets the integral gain.

Parameters
[in]Ki_Integral gain.

Definition at line 79 of file pi.h.

◆ set_Kp()

template<typename T>
void control_system::pi::PI< T >::set_Kp ( T Kp_)

Sets the proportional gain.

Parameters
[in]Kp_Proportional gain.

Definition at line 73 of file pi.h.

◆ set_param()

template<typename T>
void control_system::pi::PI< T >::set_param ( T dt_,
T Kp_,
T Ki_,
T u_k_1_,
T u_max_ )

Sets the PI controller parameters.

Parameters
[in]dt_Controller sampling time in seconds.
[in]Kp_Proportional gain.
[in]Ki_Integral gain.
[in]u_k_1_Previous controller output.
[in]u_max_Maximum allowed controller output.

Updates the controller sampling time, gains, previous controller output, and maximum output limit.

Definition at line 23 of file pi.h.

◆ set_u_0()

template<typename T>
void control_system::pi::PI< T >::set_u_0 ( T u_k_1_)

Sets the previous controller output.

Parameters
[in]u_k_1_Previous controller output.

Definition at line 85 of file pi.h.

◆ set_u_max()

template<typename T>
void control_system::pi::PI< T >::set_u_max ( T u_max_)

Sets the maximum controller output.

Parameters
[in]u_max_Maximum allowed controller output.

Definition at line 91 of file pi.h.

◆ update()

template<typename T>
T control_system::pi::PI< T >::update ( T x_0,
T x )

Computes the PI control output.

Parameters
[in]x_0Reference or desired value.
[in]xCurrent or measured value.
Returns
PI controller output limited by the configured maximum output.

Calculates the proportional and integral contributions using the current control error and the stored controller state.

Definition at line 33 of file pi.h.

Member Data Documentation

◆ dt

template<typename T>
T control_system::pi::PI< T >::dt = 0.0
private

Controller sampling time.

Sampling period of the discrete-time PI controller in seconds.

Definition at line 233 of file pi.h.

◆ e_k_1

template<typename T>
T control_system::pi::PI< T >::e_k_1 = 0.0
private

Previous control error.

Stores the control error from the previous iteration.

Definition at line 249 of file pi.h.

◆ Ki

template<typename T>
T control_system::pi::PI< T >::Ki = 0.0
private

Integral gain.

Definition at line 259 of file pi.h.

◆ Kp

template<typename T>
T control_system::pi::PI< T >::Kp = 0.0
private

Proportional gain.

Definition at line 254 of file pi.h.

◆ start

template<typename T>
bool control_system::pi::PI< T >::start = true
private

Controller startup state.

Indicates whether the controller is in its startup state.

Definition at line 276 of file pi.h.

◆ u_k_1

template<typename T>
T control_system::pi::PI< T >::u_k_1 = 0.0
private

Previous controller output.

Stores the controller output from the previous iteration.

Definition at line 241 of file pi.h.

◆ u_max

template<typename T>
T control_system::pi::PI< T >::u_max = 9999999999
private

Maximum controller output.

Defines the maximum allowed magnitude of the controller output.

Definition at line 268 of file pi.h.


The documentation for this class was generated from the following files: