motor_controller
Public Member Functions | List of all members
motor_controller::PID Class Reference

PID Implementation in C++. More...

#include <PID.hpp>

Public Member Functions

 PID ()
 Constructor. More...
 
void setParallelCoefficients (double _Ts, double _Kp=0, double _Ki=0, double _Kd=0, double _N=0, double _B=1, double _Tt=-1, double _YMin=0, double _YMax=0)
 Sets the coefficients for a 'PARALLEL' type PID. More...
 
void setIdealCoefficients (double _Ts, double _K=0, double _Ti=0, double _Td=0, double _N=0, double _B=1, double _Tt=-1, double _YMin=0, double _YMax=0)
 Sets the coefficients for a 'PARALLEL' type PID. More...
 
void setParallelPIDSettings (const ParallelPIDSettings &_settings)
 Sets the coefficients for a 'PARALLEL' type PID using the struct ParallelPIDSettings. More...
 
void setPIDSettings (const PIDSettings &_settings)
 Sets the coefficients for a 'IDEAL' type PID using the struct PIDSettings. More...
 
double saturate (double _val)
 Sets the saturation limit to +/- _val, disables if _val = 0.0. More...
 
double update (double _measuredValue, double _referenceValue, double time=0.0)
 Returns the Controller command at each sampling time. More...
 
void reset ()
 Resets the controller. More...
 
void printCoefficients ()
 Prints the controller coefficients. More...
 
void disableIntegral ()
 Diables the integral part of the controller. More...
 
void enableIntegral ()
 Enables the integral part of the controller. More...
 
void enableIntegral (double _Ti)
 Enables the integral part of the controller with time constant _Ti. More...
 
bool isIntegralEnabled () const
 Returns whether integral part is enabled. More...
 
void disableDerivative ()
 Diables the derivative part of the controller. More...
 
void enableDerivative ()
 Enables the derivative part of the controller. More...
 
void enableDerivative (double _Td)
 Enables the derivative part of the controller with time constant _Td. More...
 
bool isDerivativeEnabled () const
 Returns whether derivative part is enabled. More...
 
void disableDerivativeFiltering ()
 Diables the derivative filtering. More...
 
void enableDerivativeFiltering ()
 Enables the derivative filtering. More...
 
void enableDerivativeFiltering (double _N)
 Enables the derivative filtering with time constant _N. More...
 
bool isDerivativeFilteringEnabled () const
 Returns whether derivative filtering part is enabled. More...
 
void setDerivativeMode (DerivativeMode mode)
 Sets the derivative mode. More...
 
DerivativeMode getDerivativeMode () const
 Returns the current derivative mode. More...
 
bool isSaturated ()
 Returns true if the controller got saturated in the last run. More...
 
PIDState getState () const
 Returns the internal state of the controller. More...
 

Detailed Description

PID Implementation in C++.

Implementation based on "Control System Design" by Karl Johan Åström. implements 'IDEAL TYPE' PID with

Ideal design: $u(t) = K_p \left\{ e(t) + \frac{1}{T_i}\int e(t) + T_d \dot{y}(t)) \right\} $ where $u(t)$ is the controller output, $e(t)$ is the error and $y(t)$ is measured control variable.

USAGE:

GUIDELINES :

Author
Ajish Babu (ajish.nosp@m..bab.nosp@m.u@dfk.nosp@m.i.de)

Constructor & Destructor Documentation

PID::PID ( )

Constructor.

Member Function Documentation

void PID::disableDerivative ( )

Diables the derivative part of the controller.

void PID::disableDerivativeFiltering ( )

Diables the derivative filtering.

void PID::disableIntegral ( )

Diables the integral part of the controller.

void PID::enableDerivative ( )

Enables the derivative part of the controller.

void PID::enableDerivative ( double  _Td)

Enables the derivative part of the controller with time constant _Td.

void PID::enableDerivativeFiltering ( )

Enables the derivative filtering.

void PID::enableDerivativeFiltering ( double  _N)

Enables the derivative filtering with time constant _N.

void PID::enableIntegral ( )

Enables the integral part of the controller.

void PID::enableIntegral ( double  _Ti)

Enables the integral part of the controller with time constant _Ti.

DerivativeMode PID::getDerivativeMode ( ) const

Returns the current derivative mode.

PIDState PID::getState ( ) const

Returns the internal state of the controller.

bool motor_controller::PID::isDerivativeEnabled ( ) const
inline

Returns whether derivative part is enabled.

bool motor_controller::PID::isDerivativeFilteringEnabled ( ) const
inline

Returns whether derivative filtering part is enabled.

bool motor_controller::PID::isIntegralEnabled ( ) const
inline

Returns whether integral part is enabled.

bool PID::isSaturated ( )

Returns true if the controller got saturated in the last run.

void PID::printCoefficients ( )

Prints the controller coefficients.

void PID::reset ( )

Resets the controller.

double PID::saturate ( double  _val)

Sets the saturation limit to +/- _val, disables if _val = 0.0.

void PID::setDerivativeMode ( DerivativeMode  mode)

Sets the derivative mode.

Parameters
mode- Defines if the derivative will be applied to the error or only to the output
void PID::setIdealCoefficients ( double  _Ts,
double  _K = 0,
double  _Ti = 0,
double  _Td = 0,
double  _N = 0,
double  _B = 1,
double  _Tt = -1,
double  _YMin = 0,
double  _YMax = 0 
)

Sets the coefficients for a 'PARALLEL' type PID.

Ideal design: $u(t) = K_p \left\{ e(t) + \frac{1}{T_i}\int e(t) + T_d \dot{y}(t)) \right\} $ where $u(t)$ is the controller output, $e(t)$ is the error and $y(t)$ is measured control variable.

Parameters
_Kpgain for proportional error, integral error and derivative output
_Tiintegral time constant
_Tdderivative time constant

see PIDSettings for details of the rest of the parameters

void PID::setParallelCoefficients ( double  _Ts,
double  _Kp = 0,
double  _Ki = 0,
double  _Kd = 0,
double  _N = 0,
double  _B = 1,
double  _Tt = -1,
double  _YMin = 0,
double  _YMax = 0 
)

Sets the coefficients for a 'PARALLEL' type PID.

Parallel design: $u(t) = K_p e(t) + K_i\int e(t) + K_d \dot{y}(t))$ where $u(t)$ is the controller output, $e(t)$ is the error and $y(t)$ is measured control variable.

Parameters
_Kpproportional gain
_Kiintegral gain
_Kdderivative gain

see PIDSettings for details of the rest of the parameters

void PID::setParallelPIDSettings ( const ParallelPIDSettings _settings)

Sets the coefficients for a 'PARALLEL' type PID using the struct ParallelPIDSettings.

void PID::setPIDSettings ( const PIDSettings _settings)

Sets the coefficients for a 'IDEAL' type PID using the struct PIDSettings.

double PID::update ( double  _measuredValue,
double  _referenceValue,
double  time = 0.0 
)

Returns the Controller command at each sampling time.

Parameters
_measuredValueis the measured system output
_referenceValueis the reference input for the controller
timeis the optional current time

Applies the derivative action either to the error or only to the output


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