|
motor_controller
|
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... | |
PID Implementation in C++.
Implementation based on "Control System Design" by Karl Johan Åström. implements 'IDEAL TYPE' PID with
Ideal design:
where
is the controller output,
is the error and
is measured control variable.
USAGE:
setParallelCoefficients(Ts, Kp, Ki, Kd) which uses the parallel form of PID(as seen in most textbooks). In this case almost all the other features of the controller are disabled.GUIDELINES :
( Rule of thumb,
)| PID::PID | ( | ) |
Constructor.
| 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.
|
inline |
Returns whether derivative part is enabled.
|
inline |
Returns whether derivative filtering part is enabled.
|
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.
| 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:
where
is the controller output,
is the error and
is measured control variable.
| _Kp | gain for proportional error, integral error and derivative output |
| _Ti | integral time constant |
| _Td | derivative 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:
where
is the controller output,
is the error and
is measured control variable.
| _Kp | proportional gain |
| _Ki | integral gain |
| _Kd | derivative 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.
| _measuredValue | is the measured system output |
| _referenceValue | is the reference input for the controller |
| time | is the optional current time |
Applies the derivative action either to the error or only to the output
1.8.11