libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
PIDController< ValueType, TimeType > Class Template Reference

Discrete Proportional-Integral-Derivative (PID) controller. More...

#include <pidcontroller.h>

Public Types

using CurrentTimeFunc = std::function< TimeType()>
 Callback type that returns the current time.
 
using CurrentValueFunc = std::function< ValueType()>
 Callback type that returns the current measured process value.
 

Public Member Functions

 PIDController (CurrentValueFunc currentValueFunc, CurrentTimeFunc currentTimeFunc)
 Constructs a PID controller with the given feedback callbacks.
 
ValueType getGainP () const
 Returns the proportional gain.
 
void setGainP (const ValueType &val)
 Sets the proportional gain.
 
ValueType getGainI () const
 Returns the integral gain.
 
void setGainI (const ValueType &val)
 Sets the integral gain.
 
ValueType getGainD () const
 Returns the derivative gain.
 
void setGainD (const ValueType &val)
 Sets the derivative gain.
 
void updateSetPoint (const ValueType &val)
 Updates the set point (target value the PID should converge on).
 
ValueType step ()
 Advances the PID by one time step and returns the control output.
 
void reset ()
 Resets the integral accumulator, previous error, and update timestamp.
 

Detailed Description

template<typename ValueType = double, typename TimeType = double>
class PIDController< ValueType, TimeType >

Discrete Proportional-Integral-Derivative (PID) controller.

Implements a standard PID control loop parameterized on value and time types. The controller requires two callbacks: one that returns the current measured value of the process variable (for closed-loop control) or the last requested output (for open-loop control), and one that returns the current time as a monotonically increasing value.

Template Parameters
ValueTypeThe numeric type for gains, set point, and control output (default: double).
TimeTypeThe numeric type for time values (default: double).

Constructor & Destructor Documentation

◆ PIDController()

template<typename ValueType = double, typename TimeType = double>
PIDController< ValueType, TimeType >::PIDController ( CurrentValueFunc  currentValueFunc,
CurrentTimeFunc  currentTimeFunc 
)
inline

Constructs a PID controller with the given feedback callbacks.

Parameters
currentValueFuncCallback returning the current process value.
currentTimeFuncCallback returning the current time.

Member Function Documentation

◆ setGainD()

template<typename ValueType = double, typename TimeType = double>
void PIDController< ValueType, TimeType >::setGainD ( const ValueType val)
inline

Sets the derivative gain.

Parameters
valThe new derivative gain value.

◆ setGainI()

template<typename ValueType = double, typename TimeType = double>
void PIDController< ValueType, TimeType >::setGainI ( const ValueType val)
inline

Sets the integral gain.

Parameters
valThe new integral gain value.

◆ setGainP()

template<typename ValueType = double, typename TimeType = double>
void PIDController< ValueType, TimeType >::setGainP ( const ValueType val)
inline

Sets the proportional gain.

Parameters
valThe new proportional gain value.

◆ step()

template<typename ValueType = double, typename TimeType = double>
ValueType PIDController< ValueType, TimeType >::step ( )
inline

Advances the PID by one time step and returns the control output.

Should be called at regular intervals as frequently as possible. If called too infrequently, the controller may not respond to changes effectively.

Returns
The computed control value to apply to the controlled device.

◆ updateSetPoint()

template<typename ValueType = double, typename TimeType = double>
void PIDController< ValueType, TimeType >::updateSetPoint ( const ValueType val)
inline

Updates the set point (target value the PID should converge on).

Parameters
valThe desired target value.

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