RRM 3-13 PID Control
PID Control
The PID record is used to maintain a setpoint that affects the output according to the difference between a controlled value and the setpoint. The record reads the controlled value and the setpoint when the record is processed, and then the PID expression computes the result, which is stored in a field (DM) that can be accessed via another record, usually an analog output record.
There are three terms of the PID expression: the proportional, the integral, and the derivative. Using the gain that exists for each of these terms, the user can weight each contribution according to the characteristics of the controlled variable.
Parameter Fields
The fields in this record fall into several categories:
- scan parameters
- controlled variable
- setpoint parameters
- expression parameters
- operator display parameters
- alarm parameters
- monitor parameters
- run-time parameters
Scan Parameters
The PID record has the standard fields for specifying under what circumstances it will be processed. Note, however, that the integral and derivative parts of the algorithm are affected by the SCAN field, i.e., the scanning algorithm. For Passive, I/O Interrupt, and Event, or a period of 0.1 seconds, the interval is set to 1. For periods of 0.2, 0.5, 1, and 2 seconds, the interval is set to 2, 3, 4, and 5.
These fields are listed in Scan Fields. In addition, Scanning Specification explains how these fields are used.
The minimum delta time field (MDT) is a processing field particular to the PID record. It can be configured by the user or modified at run-time. It contains a floating point value which represents the minimum amount of time between record processing. If the amount of time between the last time the record was processed an the current time is less than MDT, than the record is not processed. If MDT is left at its default value (0), the minimum delta will be equal to one clock tick.
Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor | PP |
---|---|---|---|---|---|---|---|---|
MDT | Minimum Delta Time | FLOAT | Yes | 0 | Yes | Yes | No | No |
Controlled Variable Parameters
The control variable link field (CVL) is used to obtain the value of the controlled process variable, i.e., the value read into the CVAL field. The link must be a database link. If it is not a database link a MAJOR alarm is triggered when the record is processed. See Address Specification for information on how to specify database links.
Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor | PP |
---|---|---|---|---|---|---|---|---|
CVL | Controlled Value Location (an input link) | INLINK | Yes | 0 | No | No | N/A | No |
CVAL | Value of controlled variable | FLOAT | No | 0 | Yes | YesNo | No | No |
Setpoint Parameters
The setpoint mode select (SMSL) and the setpoint location (STPL) fields determine where the setpoint value is obtained, which is held in the VAL field. The SMSL and STPL fields work just like the OMSL and DOL fields found in many output records (analog output, binary output, etc.).
The SMSL field has two choices: supervisory
and closed_loop
. When supervisory
, the setpoint, i.e., VAL, can be set via database access. When closed_loop
, the setpoint value is retrieved from the link specified in STPL, which must be a database link. See Address Specification for information on how to specify database links. STML can also be a constant in which case VAL is set equal to the constant value when the record is initialized.
Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor | PP |
---|---|---|---|---|---|---|---|---|
STPL | Setpoint Location (an input link) | INLINK | Yes | 0 | No | No | N/A | No |
SMSL | Setpoint Mode select. | GBLCHOICE | Yes | 0 | Yes | Yes | No | No |
VAL | Setpoint value | FLOAT | No | 0 | Yes | Yes | Yes | Yes |
Expression Parameters
The discrete form of the PID expression is as follows:
M(n) = KP × E(n) + KI × SUMi ( E(i) × dT(n) ) + KD × ( | E(n) - E(n-1) | ) + Mr |
----------------- | ||
dT(n) |
where
- M(n) = value of manipulated variable at nth instant.
- KP, KI, and KD = Proportional, Integral, Derivative gains set by the user
- E(n) = Error at nth sampling instant
- SUMi = Sum from i=0 to i=n
- dT(n) = Time difference between n-1th instance and nth instance
- Mr = Midrange adjustment
Taking the first difference between instances yields the following equation:
delM(n) = KP × (E(n) - E(n-1)) + KI × E(i) × dT(n) + KD × ( | E(n) - E(n-1) | ) - ( | E(n) - E(n-1) | ) |
----------------- | ----------------- | |||
dT(n) | dT(n-1) |
The terms KP, KI, and KD are the only terms configured by the user. These terms represent the gain for the proportional (KP), integral (KI) and the derivative (KD). A field exists for each of these terms (the KP, KI, and KD fields). KP should be configured according to the characteristics of the controlled variable; KI should be set equal to the number of times that the integral contribution repeats the proportional contribution; and KD should equal the number of minutes until the derivative contribution repeats the proportional contribution.
The PID record calculates the other terms of the expression:
- E(n)
- Error at nth sampling instant, where the Error equals the setpoint minus the value of the controlled variable (VAL - CVAL).
- delM(n)
- This is the end result of the PID expression -- the change in the manipulated value. The DM field holds this value.
- dT(n)
- This is the time difference between n and n-1, between current and last samplings.
The final result of the expression delM(n)
and the other parts of the expression are held in several different run-time fields, which are not configurable prior to run-time, nor modifiable at run-time, but can be accessed so that their values can be used. See Run-time Parameters in this chapter for more information on those fields.
Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor | PP |
---|---|---|---|---|---|---|---|---|
KP | Proportional Gain | FLOAT | Yes | 0 | Yes | Yes | No | No |
KI | Integral Gain, in repeats per minute. | FLOAT | Yes | 0 | Yes | Yes | No | No |
KD | Derivative Gain, in repeats per minute | FLOAT | Yes | 0 | Yes | Yes | No | No |
Operator Display Parameters
These parameters are used to present meaningful data to the operator. They display the setpoint (VAL), the controlled variable (CVAL), the change in manipulated value (DM), and other fields of the PID, either textually or graphically.
EGU is a string of up to 16 characters describing the units of PID's manipulated values measures. It is retrieved by the get_units
record support routine. It must be configured by the user if at all.
The HOPR and LOPR fields set the upper and lower display limits for the VAL, HIHI, HIGH, LOW, LOLO, VAL, and CVAL fields.
The PREC field determines the floating point precision with which to display VAL and CVAL. It is used whenever the get_precision
record support routine is called.
See Fields Common to All Record Types for more on the record name (NAME) and description (DESC) fields.
Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor | PP |
---|---|---|---|---|---|---|---|---|
EGU | Engineering Units | STRING [16] | Yes | null | Yes | Yes | No | No |
HOPR | High Operating Range | FLOAT | Yes | 0 | Yes | Yes | No | No |
LOPR | Low Operating Range | FLOAT | Yes | 0 | Yes | Yes | No | No |
PREC | Display Precision | SHORT | Yes | 0 | Yes | Yes | No | No |
NAME | Record Name | STRING [29] | Yes | 0 | Yes | No | No | No |
DESC | Description | STRING [29] | Yes | Null | Yes | Yes | No | No |
Alarm Parameters
The possible alarm conditions for PID are the SCAN alarm, limit alarms, and an alarm that is triggered when CVL is not a database link. The SCAN and "CVL" alarms are called by the record routines and are always of MAJOR severity.
The limit alarms trigger alarms on the VAL field. They are configured by the user in the HIHI, LOLO, HIGH, and LOW fields using floating point values. For each of these fields, there is a corresponding severity field which can be either NO ALARM, MINOR, or MAJOR. See Alarm Specification for a complete explanation of alarms and these fields.
Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor | PP |
---|---|---|---|---|---|---|---|---|
HIHI | Hihi Alarm Limit | FLOAT | Yes | 0 | Yes | Yes | No | Yes |
LOLO | High Alarm Limit | FLOAT | Yes | 0 | Yes | Yes | No | Yes |
HIGH | Low Alarm Limit | FLOAT | Yes | 0 | Yes | Yes | No | Yes |
LOW | Lolo Alarm Limit | FLOAT | Yes | 0 | Yes | Yes | No | Yes |
HHSV | Hihi Alarm Severity | GBLCHOICE | Yes | 0 | Yes | Yes | No | Yes |
LLSV | High Alarm Severity | GBLCHOICE | Yes | 0 | Yes | Yes | No | Yes |
HSV | Low Alarm Severity | GBLCHOICE | Yes | 0 | Yes | Yes | No | Yes |
LSV | Lolo Alarm Severity | GBLCHOICE | Yes | 0 | Yes | Yes | No | Yes |
HYST | Alarm Deadband | DOUBLE | Yes | 0 | Yes | Yes | No | No |
Alarm Fields lists other fields related to a alarms that are common to all record types.
Monitor Parameters
These parameters are used to determine when to send monitors placed on the VAL field. These fields contain values configured by the user. The monitors are sent when the VAL field exceeds the last monitored field (MLST, ALST, and LALM) by the appropriate delta. Otherwise, value change monitors are not called. If these fields have a value of zero, everytime the value changes, a monitor will be triggered; if they have a value of -1, everytime the record is processed, monitors are triggered. The ADEL field is the delta used for archive monitors, and the MDEL field is the delta for all other types of monitors.
The ODEL field specifies the hysteresis factor for the DM field, the field which holds the manipulated value. Unless the current value of DM is greater than the amount which the user specifies in this field, no monitors will be invoked. If zero, anytime DM is greater than zero, a monitor is triggered. If -1, each time the record is processed, a monitor is triggered. Note that when monitors are called for DM, they are also called for the following fields which comprise the PID expression: P, I, D, CT, DT, ERR, and DERR.
See Monitor Specification for a complete explanation of monitors.
Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor | PP |
---|---|---|---|---|---|---|---|---|
ADEL | Archive Deadband | DOUBLE | Yes | 0 | Yes | Yes | No | No |
MDEL | Monitor, i.e. value change, Deadband | DOUBLE | Yes | 0 | Yes | Yes | No | No |
ODEL | Output deadband | FLOAT | Yes | 0 | Yes | Yes | No | No |
Run-time Parameters
These parameters are used by the run-time code for processing the PID. They are not configurable prior to run-time. They represent the current state of the PID and/or the terms of the PID expression. Many of them are used to process the PID record more efficiently.
The DM field contains the change in manipulated value, the result of the PID expression (delM(n)). It is an increment which will usually be accessed by the desired output link (DOL) of an analog output record. Since its value represents an increment, the OIF field of the analog output record should be set to Incremental
. There is no output field with which the PID record can itself send output.
The P, I, D, CT, DT, ERR, and DERR fields are used to calculate the PID expression. They are not configurable prior to, nor modifiable during, run-time, but may be of interest when fine tuning the gains of each contribution (KP, KI, KD). The following lists the fields as they relate to the expression:
- ERR
- E(n). Error at current sampling (VAL-CVAL).
- DERR
- E(n) - E(n-1). Difference between current error and error at last sampling.
- P
- This field corresponds to
KP * DERR
- I
- This field corresponds to
E(n) * dTn * KI
- D
- This field corresponds to
Kp * Kd * (err/dt(n) - derr/dt(n-1))
The LALM, ALST, and MLST fields are used by record processing to implement the monitors for this record. These fields hold the values for the VAL field from the last time the record was processed. When the record is processed again the difference between these fields and current value of VAL exceeds the appropriate delta (MDEL for instance), then the appropriate monitors are triggered.
Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor | PP |
---|---|---|---|---|---|---|---|---|
DM | Change in Manipulated Value | FLOAT | No | 0 | Yes | No | Yes | No |
ODM | Old DM. | FLOAT | No | 0 | Yes | No | Yes | No |
P | Proportional contribution to DM. | FLOAT | No | 0 | Yes | No | Yes | No |
I | Integral contribution to DM. | FLOAT | No | 0 | Yes | No | Yes | No |
D | Derivative contribution to DM. | FLOAT | No | 0 | Yes | No | Yes | No |
CT | Clock ticks when previous process occurred. | ULONG | No | 0 | Yes | No | Yes | No |
DT | Time difference in seconds between processing steps. | FLOAT | No | 0 | Yes | No | Yes | No |
ERR | Current error (VAL - CVAL). | FLOAT | No | 0 | Yes | No | Yes | No |
DERR | Delta Error | FLOAT | No | 0 | Yes | No | Yes | No |
LALM | Value when last monitors for alarm were triggered | FLOAT | No | 0 | Yes | No | No | No |
ALST | Value when last monitors for archiver were triggered | FLOAT | No | 0 | Yes | No | No | No |
MLST | Value when last monitors for value changes were triggered | FLOAT | No | 0 | Yes | No | No | No |
Record Support
Record Support Routines
init_record
If STPL is a constant link, initialize VAL with it's value and set UDF to false.
process
See next section.
get_value
Fills in the values of struct valueDes so that they refer to VAL.
get_units
Retrieves EGU.
get_precision
Retrieves PREC.
get_graphic_double
Sets the following values:
upper_disp_limit = hopr lower_disp_limit = lopr
get_control_double
Sets the following values
upper_ctrl_limit = hopr lower_ctrl_limit = lopr
get_alarm_double
Sets the following values:
upper_alarm_limit = hihi upper_warning_limit = high lower_warning_limit = low lower_alarm_limit = lolo
Record Processing
Routine process implements the following algorithm:
- If CVL is not a database link a major alarm is declared and the algorithm completes.
- The current value of CVAL is obtained from CVL.
- If STPL is a database link and SMSL is CLOSED_LOOP then VAL is obtained from STPL and UDF is set to false.
- The time difference since the last time step is calculated. If it is less than MDT or if no ticks have occurred since the last time the algorithm was executed, process just completes without raising any alarms, checking monitors, or scanning the forward link.
- The new values of P, I, D, OUT, CT, DT, ERR, and DERR are computed.
- Check alarms. This routine checks to see if the new VAL causes the alarm status and severity to change. If so NSEV and NSTA and LALM are set. It also honors the alarm hysteresis factor (HYST). Thus the value must change by at least HYST before the alarm status and severity changes.
- Checks to see if monitors should be invoked:
- Alarm Monitors are invoked if ADEL and MDEL conditions are met.
- Archive and value change monitors are invoked if ODEL conditions are met. If monitors are triggered from DM, they are also triggered for P, I, D, CT, DT, E
EPICS Record Reference Manual - 19 MAY 1998