Class Pid
Holds a value at a setpoint by trading off present, past, and predicted error.
public sealed class Pid : IDisposable
- Inheritance
-
Pid
- Implements
- Inherited Members
Remarks
This is the controller behind holding a temperature, a pressure, or a speed steady against a load that keeps changing.
Constructors
Pid(float, float, float)
Creates a controller with the given gains and no output limits.
public Pid(float kp, float ki, float kd)
Parameters
kpfloatThe proportional gain, reacting to present error.
kifloatThe integral gain, correcting accumulated error.
kdfloatThe derivative gain, damping predicted error.
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Reset()
Clears the accumulated integral, the last error, and the last output.
public void Reset()
Update(float, float, float)
Advances the controller by one step.
public float Update(float setpoint, float measurement, float dt)
Parameters
setpointfloatThe value being held.
measurementfloatThe latest measured value. A setpoint or measurement that is not a finite number is ignored, and the previous output returned.
dtfloatThe time since the previous step, in the unit the integral and derivative gains assume. One at or below zero skips the integral and derivative.
Returns
- float
The control output.
WithLimits(float, float, float, float, float)
Creates a controller whose output is clamped to a range.
public static Pid WithLimits(float kp, float ki, float kd, float min, float max)
Parameters
kpfloatThe proportional gain, reacting to present error.
kifloatThe integral gain, correcting accumulated error.
kdfloatThe derivative gain, damping predicted error.
minfloatThe lowest output the controller may command; NegativeInfinity leaves the low side open.
maxfloatThe highest output the controller may command; PositiveInfinity leaves the high side open.
Returns
- Pid
The clamped controller.