Class PidController
Proporitional-Integral-Derivative(PID) controller
that supports
- first and second order low pass filtering of process variable
- anti-windup
- bumpless transfer between auto and manual mode
- "warmstarting" -bumpless startup
- feedforward
- scaling of input and output values
- gain scheduling of Kp
- gain scheduling of Ti
- "kicking" as is usually applied to compressor recycling controllers/anti-surge
- min select/max select (also referred to as high select or low select: (multiple pid-controllers controlling the same output switch between auto and tracking mode)
By design decision, this class should be kept relativly simple in terms of coding patterns, so that it is possible to
hand-port this class to other languages (c++/c/Structured Text/Labview/Matlab etc).
To simulate PID-control, use the wrapper class PIDModel, as it wraps this class and impelments the
ISimulatableModel
interface needed to simulate with ProcessSimulator
Inherited Members
Namespace: TimeSeriesAnalysis.Dynamic
Assembly: TimeSeriesAnalysis.dll
Syntax
public class PidController
Constructors
| Edit this page View SourcePidController(double, double, double, double, double)
Constructor
Declaration
public PidController(double TimeBase_s, double Kp = 1, double Ti = 50, double Td = 0, double nanValue = -9999)
Parameters
Type | Name | Description |
---|---|---|
double | TimeBase_s | |
double | Kp | |
double | Ti | |
double | Td | |
double | nanValue |
Methods
| Edit this page View SourceGetControllerStatus()
Returns a status code, to determine if controller is in manual, auto or in tracking(relevant for split range controllers.)
Declaration
public PidStatus GetControllerStatus()
Returns
Type | Description |
---|---|
PidStatus |
GetFeedForward()
Get the feedforward parameters of the controller
Declaration
public PidFeedForward GetFeedForward()
Returns
Type | Description |
---|---|
PidFeedForward |
GetGainScehduling(PidGainScheduling)
Get the gain scheduling settings of the controller
Declaration
public PidGainScheduling GetGainScehduling(PidGainScheduling gainSchedulingObj)
Parameters
Type | Name | Description |
---|---|---|
PidGainScheduling | gainSchedulingObj |
Returns
Type | Description |
---|---|
PidGainScheduling |
GetScaling()
Get the object that contains scaling information
Declaration
public PidScaling GetScaling()
Returns
Type | Description |
---|---|
PidScaling |
GetTimeBase()
Sets the length of time in seconds between each iteration of the controller, i.e. the "clock time" or "time base". This is very important to set correctly for the controller to function properly. Normally the clock time is set only once during intalization.
Declaration
public double GetTimeBase()
Returns
Type | Description |
---|---|
double |
GetTrackingCutoff()
Get the tracking cutoff parameter
Declaration
public double GetTrackingCutoff()
Returns
Type | Description |
---|---|
double |
GetTrackingOffset()
Returns the tracking offset of the controller, the offset that a non-active controller will add or subtract from its output when inactive in a split range control scheme
Declaration
public double GetTrackingOffset()
Returns
Type | Description |
---|---|
double |
GetUIfInAuto()
Returns the value of the output u that the controller would give if it was in auto. This is useful when considering turning on a controller that is in manual to see that the controller gives a sensible output. Call "iterate" first to update the internals of the controller.
Declaration
public double GetUIfInAuto()
Returns
Type | Description |
---|---|
double |
GetUWithoutTracking()
Split range controllers add an offset to the output u for inactive or "tracking" controllers. This function returns the "raw" u without tracking, which can be useful for initalizing simulations with split range control.
Declaration
public double GetUWithoutTracking()
Returns
Type | Description |
---|---|
double |
Iterate(double, double, double?, double?, double?)
Calculates the next u[k] output of the controller given the most recent process value and setpoint value, and optionally also including the tracking signal (only applicable if this is a split range controller) and optionally the gainScehduling variable if controller is to gain-schedule
Declaration
public double Iterate(double y_process_abs, double y_set_abs, double? uTrackSignal = null, double? gainSchedulingVariable = null, double? feedForwardVariable = null)
Parameters
Type | Name | Description |
---|---|---|
double | y_process_abs | |
double | y_set_abs | |
double? | uTrackSignal | |
double? | gainSchedulingVariable | |
double? | feedForwardVariable |
Returns
Type | Description |
---|---|
double |
Iterate(double[], double[], double[])
Calculates an entire output vector u given vector of processes and setpoints (and optionally a tracking signal for split range) This method is useful for back-testing against historic data.
Declaration
public double[] Iterate(double[] y_process_abs, double[] y_set_abs, double[] uTrackSignal = null)
Parameters
Type | Name | Description |
---|---|---|
double[] | y_process_abs | |
double[] | y_set_abs | |
double[] | uTrackSignal |
Returns
Type | Description |
---|---|
double[] |
SetAntiSurgeParams(PidAntiSurgeParams)
Sets the anti-surge "kick" paramters of the controller
Declaration
public void SetAntiSurgeParams(PidAntiSurgeParams antiSurgeParams)
Parameters
Type | Name | Description |
---|---|---|
PidAntiSurgeParams | antiSurgeParams |
SetAutoMode()
Set the control to autoamtic mode (i.e. u varies based on inputs and settings) (use SetManualMode to switch back)
Declaration
public void SetAutoMode()
SetFeedForward(PidFeedForward)
Set the feedforward of the controller Re-calling this setter to update
Declaration
public void SetFeedForward(PidFeedForward feedForwardObj)
Parameters
Type | Name | Description |
---|---|---|
PidFeedForward | feedForwardObj |
SetGainScehduling(PidGainScheduling)
Set the gain scheduling of the controller (by default controller has no gain-scheduling) Re-calling this setter to update gain-scheduling
Declaration
public void SetGainScehduling(PidGainScheduling gainSchedulingObj)
Parameters
Type | Name | Description |
---|---|---|
PidGainScheduling | gainSchedulingObj |
SetKp(double)
Sets the Proportional gain(P) of the controller
Declaration
public void SetKp(double Kp)
Parameters
Type | Name | Description |
---|---|---|
double | Kp |
SetManualMode()
Set the control to manual mode (i.e. constant u). Will cause a bumpless transfer.(use SetAutoMode to switch back)
Declaration
public void SetManualMode()
SetManualOutput(double)
Set the manual output of the model (will only be used if set)
Declaration
public void SetManualOutput(double uManual)
Parameters
Type | Name | Description |
---|---|---|
double | uManual |
SetPidFiltering(PidFilterParams)
Set the object that defines input filtering for the pid-controller
Declaration
public void SetPidFiltering(PidFilterParams pidFiltering)
Parameters
Type | Name | Description |
---|---|---|
PidFilterParams | pidFiltering |
SetScaling(PidScaling)
Gives a PIDscaling object that specifies how input and output is to be scaled.
Declaration
public void SetScaling(PidScaling pidScaling)
Parameters
Type | Name | Description |
---|---|---|
PidScaling | pidScaling |
SetTd(double)
Sets the differential(D) time contant of the controller in seconds
Declaration
public void SetTd(double Td_seconds)
Parameters
Type | Name | Description |
---|---|---|
double | Td_seconds |
SetTi(double)
Sets the Integral(I) time contant of the controller in seconds
Declaration
public void SetTi(double Ti_seconds)
Parameters
Type | Name | Description |
---|---|---|
double | Ti_seconds |
SetTrackingOffset(double, double)
Set the offset that is to be added or subtracte to a split range controller that is inactive or tracking. If this value is above zero, then the controller is MIN SELECT, if this value is negative then the controller is assumed MAX SELECT if this vlaue is zero, then trakcking will not work properly as controller will be unable to determine if its output was selected by looking at the tracking signal.
Declaration
public void SetTrackingOffset(double uTrackingOffset, double uTrackingCutoff = 0.5)
Parameters
Type | Name | Description |
---|---|---|
double | uTrackingOffset | |
double | uTrackingCutoff |
SetU0ForPcontrol(double)
For proportional-only controllers (P-controllers), a u0 offset to be added to u is specified by this method.
Declaration
public void SetU0ForPcontrol(double u0)
Parameters
Type | Name | Description |
---|---|---|
double | u0 |
WarmStart(double, double, double)
Initalizes the controller internal state(integral term) to be steady at the given process value and output value, useful to avoid bumps when staring controller
Declaration
public void WarmStart(double y_process_abs, double y_set_abs, double u_abs)
Parameters
Type | Name | Description |
---|---|---|
double | y_process_abs | |
double | y_set_abs | |
double | u_abs |