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 and last error.
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.
dtfloatSeconds since the previous step.
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.
maxfloatThe highest output the controller may command.
Returns
- Pid
The clamped controller.