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::pd::PD< T > Class Template Reference

Discrete-time proportional-derivative controller. More...

#include <pd.h>

Public Member Functions

 PD ()
 Constructs a PD controller.
get_dt ()
 Gets the controller sampling time.
get_e_k_1 ()
 Gets the previous control error.
get_Kd ()
 Gets the derivative gain.
get_Kp ()
 Gets the proportional gain.
get_u_max ()
 Gets the maximum controller output.
void init (T dt_, T Kp_, T Kd_, T u_max_)
 Initializes the PD controller.
void merge (T u_k_1_)
 Merges an external controller output into the PD state.
void reset ()
 Resets the PD controller state.
void set_dt (T dt_)
 Sets the controller sampling time.
void set_Kd (T Kd_)
 Sets the derivative gain.
void set_Kp (T Kp_)
 Sets the proportional gain.
void set_param (T dt_, T Kp_, T Kd_, T u_max_)
 Sets the PD controller parameters.
void set_u_max (T u_max_)
 Sets the maximum controller output.
update (T x_0, T x)
 Computes the PD control output.

Private Attributes

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

Detailed Description

template<typename T>
class control_system::pd::PD< T >

Discrete-time proportional-derivative controller.

The PD class implements a discrete-time proportional-derivative controller using configurable proportional and derivative gains.

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

Template Parameters
TNumeric data type used for the controller.
Example
controller.init(
0.001,
Kp,
Kd,
100.0
);
double output = controller.update(reference, measurement);
Discrete-time proportional-derivative controller.
Definition pd.h:75
void init(T dt_, T Kp_, T Kd_, T u_max_)
Initializes the PD controller.
Definition pd.h:15
T Kp
Proportional gain.
Definition pd.h:234
T Kd
Derivative gain.
Definition pd.h:239
T update(T x_0, T x)
Computes the PD control output.
Definition pd.h:31

Definition at line 74 of file pd.h.

Constructor & Destructor Documentation

◆ PD()

template<typename T>
control_system::pd::PD< T >::PD ( )

Constructs a PD controller.

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

Definition at line 5 of file pd.h.

Here is the caller graph for this function:

Member Function Documentation

◆ get_dt()

template<typename T>
T control_system::pd::PD< T >::get_dt ( )

Gets the controller sampling time.

Returns
Sampling time in seconds.

Definition at line 86 of file pd.h.

◆ get_e_k_1()

template<typename T>
T control_system::pd::PD< T >::get_e_k_1 ( )

Gets the previous control error.

Returns
Control error from the previous controller iteration.

Definition at line 104 of file pd.h.

◆ get_Kd()

template<typename T>
T control_system::pd::PD< T >::get_Kd ( )

Gets the derivative gain.

Returns
Derivative gain.

Definition at line 98 of file pd.h.

◆ get_Kp()

template<typename T>
T control_system::pd::PD< T >::get_Kp ( )

Gets the proportional gain.

Returns
Proportional gain.

Definition at line 92 of file pd.h.

◆ get_u_max()

template<typename T>
T control_system::pd::PD< T >::get_u_max ( )

Gets the maximum controller output.

Returns
Maximum allowed controller output.

Definition at line 110 of file pd.h.

◆ init()

template<typename T>
void control_system::pd::PD< T >::init ( T dt_,
T Kp_,
T Kd_,
T u_max_ )

Initializes the PD controller.

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

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

Definition at line 15 of file pd.h.

◆ merge()

template<typename T>
void control_system::pd::PD< T >::merge ( T u_k_1_)

Merges an external controller output into the PD state.

Parameters
[in]u_k_1_Previous or externally provided controller output.

Updates the controller state using the specified previous controller output.

Definition at line 57 of file pd.h.

◆ reset()

template<typename T>
void control_system::pd::PD< T >::reset ( )

Resets the PD controller state.

Resets the stored previous control error and startup state.

Definition at line 50 of file pd.h.

◆ set_dt()

template<typename T>
void control_system::pd::PD< T >::set_dt ( T dt_)

Sets the controller sampling time.

Parameters
[in]dt_Sampling time in seconds.

Definition at line 62 of file pd.h.

◆ set_Kd()

template<typename T>
void control_system::pd::PD< T >::set_Kd ( T Kd_)

Sets the derivative gain.

Parameters
[in]Kd_Derivative gain.

Definition at line 74 of file pd.h.

Here is the call graph for this function:

◆ set_Kp()

template<typename T>
void control_system::pd::PD< T >::set_Kp ( T Kp_)

Sets the proportional gain.

Parameters
[in]Kp_Proportional gain.

Definition at line 68 of file pd.h.

◆ set_param()

template<typename T>
void control_system::pd::PD< T >::set_param ( T dt_,
T Kp_,
T Kd_,
T u_max_ )

Sets the PD controller parameters.

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

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

Definition at line 22 of file pd.h.

◆ set_u_max()

template<typename T>
void control_system::pd::PD< T >::set_u_max ( T u_max_)

Sets the maximum controller output.

Parameters
[in]u_max_Maximum allowed controller output.

Definition at line 80 of file pd.h.

◆ update()

template<typename T>
T control_system::pd::PD< T >::update ( T x_0,
T x )

Computes the PD control output.

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

Calculates the proportional and derivative contributions using the current control error and the stored previous control error.

Definition at line 31 of file pd.h.

Member Data Documentation

◆ dt

template<typename T>
T control_system::pd::PD< T >::dt = 0.0
private

Controller sampling time.

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

Definition at line 221 of file pd.h.

◆ e_k_1

template<typename T>
T control_system::pd::PD< T >::e_k_1 = 0.0
private

Previous control error.

Stores the control error from the previous iteration.

Definition at line 229 of file pd.h.

◆ Kd

template<typename T>
T control_system::pd::PD< T >::Kd = 0.0
private

Derivative gain.

Definition at line 239 of file pd.h.

◆ Kp

template<typename T>
T control_system::pd::PD< T >::Kp = 0.0
private

Proportional gain.

Definition at line 234 of file pd.h.

◆ start

template<typename T>
bool control_system::pd::PD< T >::start = true
private

Controller startup state.

Indicates whether the controller is in its startup state.

Definition at line 247 of file pd.h.

◆ u_max

template<typename T>
T control_system::pd::PD< T >::u_max = 9999999999
private

Maximum controller output.

Defines the maximum allowed magnitude of the controller output.

Definition at line 256 of file pd.h.


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