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. | |
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.
| ValueType | The numeric type for gains, set point, and control output (default: double). |
| TimeType | The numeric type for time values (default: double). |
|
inline |
Constructs a PID controller with the given feedback callbacks.
| currentValueFunc | Callback returning the current process value. |
| currentTimeFunc | Callback returning the current time. |
Sets the derivative gain.
| val | The new derivative gain value. |
Sets the integral gain.
| val | The new integral gain value. |
Sets the proportional gain.
| val | The new proportional gain value. |
|
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.
Updates the set point (target value the PID should converge on).
| val | The desired target value. |