RRM 3-14 CPID Control

From EPICSWIKI
Revision as of 19:12, 18 April 2008 by KazimierzGofron (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

EPICS Record Reference Manual


CPID Control

The CPID record, like the PID record, is used for making error corrections on output values in order to maintain a specified setpoint. In the CPID record, the setpoint must be retrieved from another database record. When the record is processed, it reads the controlled value and the setpoint, and then computes the error correction. Unlike the PID record, the CPID record can write this value because it has its own output link.

Another important difference is that unlike the PID record, the CPID record has four different modes: normal mode, sequencer mode, local mode, and manual mode. The normal mode causes the CPID record to function in the same way as the PID record does. The other modes significantly change how the CPID record functions. All these modes are explained in this chapter.

When in normal mode, the CPID record performs the same equation as the PID record. This equation consists of three parts: 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 response of the process being controlled.

Parameter Fields

The fields in this record fall into several categories:

  • scan parameters
  • controlled variable and setpoint parameters
  • output, readback, and mode parameters
  • expression parameters
  • operator display parameters
  • alarm parameters
  • monitor parameters
  • run-time parameters


Scan Parameters

The CPID record has the standard fields for specifying under what circumstances the record will be processed. These fields are listed in Scan Fields. In addition, Scanning Specification explains how these fields are used. Since the CPID record supports no direct interfaces to hardware, it cannot be scanned on I/O interrupt, i.e., its SCAN field cannot specify I/O Intr.

However, the CPID record contains an additional field that affects its processing while in normal mode. The minimum delta time field (MDT) is a scanning field particular to the CPID record and PID records. 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 so that if the amount of time between the last time the record was processed and the current time is less than MDT, then DM and the output value (OVAL) are set to 0. If MDT is left at its default value (0), the minimum delta will be equal to one clock tick.


FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
MDTMinimum Delta TimeFLOATYes0YesYesNoNo


Controlled Variable and Setpoint Parameters

The control variable location field (CVL) is used to obtain the value of the controlled process variable, the value read into the CVAL field. The link must be a database link. If it is not a database link an INVALID alarm is triggered when the record is processed. See Address Specification for information on specifying links.

The setpoint value is set in the VAL field. Unlike the PID record, the setpoint value cannot be read from other records, but must be set via dbPuts. It is set equal to CVAL, the value retrieved from the CVL link, when the record is initialized.


FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
CVLControlled value location (an input link)INLINKYes0NoNoN/ANo
VALSetpoint valueFLOATNo0YesYesYesYes


Expression Parameters

The PID expression calculated by the CPID record in Normal mode is the same as the PID record's expression. The discrete from 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.

When in Normal Mode, the DM field contains the change in manipulated value, i.e., the result of the PID expression delM(n). For other modes, the value is different, but is always an increment which can 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. Note that the final result to be written may not be the same as the final result of the equation; that is, DM, the result of the equation, may not equal OVAL, the output value, depending on the mode.

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))


FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
KPProportional GainFLOATYes0YesYesNoNo
KIIntegral Gain, in repeats per minute.FLOATYes0YesYesNoNo
KDDerivative Gain, in repeats per minuteFLOATYes0YesYesNoNo
DMChange in Manipulated ValueFLOATNo0YesNoYesNo
PProportional contribution to DM.FLOATNo0YesNoYesNo
IIntegral contribution to DM.FLOATNo0YesNoYesNo
DDerivative contribution to DM.FLOATNo0YesNoYesNo
CTClock ticks when previous process occurred.ULONGNo0YesNoYesNo
DTTime difference in seconds between processing steps.FLOATNo0YesNoYesNo
ERRCurrent error (VAL - CVAL).FLOATNo0YesNoYesNo
DERRDelta ErrorFLOATNo0YesNoYesNo


Output, Readback, and Mode Parameters

Unlike the PID record, the CPID record has an output link so that it can write its output. The value written is the value of the OVAL field. How record processing determines this value depends on, among other things, the current mode and the limits.

Firstly, the record has two output modes, CHANGE and POSITION, set by the OMOD field. If OMOD is (0,1), then the output mode will be (CHANGE, POSITION). The OMOD field cannot be modified at run-time, so it must be configured to be either CHANGE or POSITION. It is initialized to CHANGE by default.

When CHANGE, the record sets OVAL equal to DM, the result of the PID expression. DM being itself an increment, OVAL is an incremental value in the CHANGE mode. If the record is in POSITION mode, OVAL is an absolute value obtained by adding OVAL to DM. In this case, OVAL will be the last value of OVAL when it was written unless it was changed by database access.

if CHANGE
    OVAL = DM
if POSITION
    OVAL = OVAL + DM

After OVAL is adjusted in case it violates the value limits explained below, DM is set equal to OVAL when in CHANGE mode. When in position mode, after any adjustments, DM is set equal to OVAL - MLST, MLST being the value of OVAL the last time the record was processed. This way, DM is always an increment, adjusted to be within the value limits.

Secondly, there are four different modes on top of the output mode: Normal, Sequencer, Manual, and Local.

  1. In Normal mode, OVAL is computed as explained above. DM is also computed as usual.
  2. In Sequencer mode, the CPID record computes OVAL as SVAL - ORBV when in CHANGE mode, and sets OVAL equal to SVAL in the POSITION mode. DM is computed as SVAL - ORBV in CHANGE mode and OVAL - SVAL in POSITION mode. The sequencer program should determine the value of SVAL while in Sequencer mode.
  3. In Manual mode, the CPID record computes OVAL as MVAL - ORBV when in CHANGE mode, and sets OVAL equal to MVAL when in POSITION mode. DM is set equal to MVAL - ORBV in CHANGE mode and OVAL - MVAL in POSITION mode. MVAL is determined by the operator at run-time, via dbPuts.
  4. In Local mode, the CPID record sets OVAL equal to 0 when the output mode is CHANGE and ORBV when the output mode is POSITION. The Local mode was implemented to support the setting of the output by a local hardware control.

The MMOD, SMOD, and LOC field determine which of these four modes the CPID record is in. The MMOD and SMOD fields are set via database access (by the operator or the sequencer). The LOC field must specify a database link if the record is to be placed into Local mode. If the MMOD field is true (has a value other than 0), then the mode is Manual. If the SMOD field is true, then the mode is Sequencer. If the LOC field is a database link and the value retrieved from it is 0, then the mode is Local. The default mode is the normal mode so that if none of the above conditions exist, the mode is normal. An order of precedence exists so that the mode can be determined when more than one of the above conditions is true. The order of precedence is Local mode, Manual mode, Sequencer, then Normal mode, so that if the MMOD and SMOD fields are true and the value retrieved from the LOC field is not 0 (i.e., local mode is not requested), then the mode is Sequencer.

Note: DM is calculated even for modes other than Normal. This prevents the DT change in time contribution from "winding up" when the mode is other than Normal.

Finally, MAX, MIN, DMAX, and DMIN fields are used to specify limits for the output value. The MAX and MIN fields limit the value of OVAL, whereas the DMAX and DMIN fields limit the value of DM. How these fields do this for the different modes is somewhat complex. See Record Processing in this chapter for a further explanation of how these fields work.


FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
OUTOutput LinkOUTLINKYes0NoNoN/ANo
ORBLOutput Readback LocationINLINKYes NoNoNoNo
OMODOutput ModeRECCHOICEYes0YesNoNoNo
ORBVOutput Readback ValueFLOATNo0YesYesNoNo
MAXMaximum LimitFLOATYes0YesYesNoNo
MINMinimum LimitFLOATYes0YesYesNoNo
DMAXMaximum ChangeFLOATYes0YesYesNoNo
DMINMinimum ChangeFLOATYes0YesYesNoNo
LOCLocal Mode SwitchINLINKYes  NoNoNo
MMODManual Mode RequestGBLCHOICEYes0YesYesNoNo
SMODSequencer Mode RequestGBLCHOICEYes0YesYesNoNo
MVALManual ValueFLOATYes0YesYesNoNo
SVALSequencer ValueFLOATYes0YesYesNoNo


Operator Display Parameters

These parameters are used to present meaningful data to the operator. These fields are used to 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, P, I, D, 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.


FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
EGUEngineering UnitsSTRINGYesnullYesYesNoNo
HOPRHigh Operating RangeFLOATYes0YesYesNoNo
LOPRLow Operating RangeFLOATYes0YesYesNoNo
PRECDisplay PrecisionSHORTYes0YesYesNoNo
NAMERecord NameSTRINGYes0YesNoNo 
DESCDescriptionSTRINGYesNullYesYesNoNo


Alarm Parameters

The possible alarm conditions for PID are the SCAN alarm, limit alarms, and an INVALID alarm that is triggered when CVL is not a database link. The SCAN and INVALID 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. Alarm Fields lists other fields related to a alarms that are common to all record types.


FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
HIHIHihi Alarm LimitFLOATYes0YesYesNoYes
HIGHHigh Alarm LimitFLOATYes0YesYesNoYes
LOWLow Alarm LimitFLOATYes0YesYesNoYes
LOLOLolo Alarm LimitFLOATYes0YesYesNoYes
HHSVHihi Alarm SeverityGBLCHOICEYes0YesYesNoYes
HSVHigh Alarm SeverityGBLCHOICEYes0YesYesNoYes
LSVLow Alarm SeverityGBLCHOICEYes0YesYesNoYes
LLSVLolo Alarm SeverityGBLCHOICEYes0YesYesNoYes
HYSTAlarm DeadbandDOUBLEYes0YesYesNoNo


Monitor Parameters

These parameters are deadbands configured by the user which determine when to send monitors on the DM field. If the value of DM is greater than ADEL, archive monitors for the OVAL, CT, and DM fields are sent. Additionally, if the record is in Normal mode, monitors for P, I, D, ERR, DERR, and DT are sent. MDEL is used the same way as ADEL for all other types of monitors.

The ODEL field is not implemented in the PID record.

See Monitor Specification for a complete explanation of monitors.


FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
ADELArchive DeadbandDOUBLEYes0YesYesNoNo
MDELMonitor, i.e. value change, DeadbandDOUBLEYes0YesYesNoNo
ODELOutput deadband for DMFLOATYes0YesYesNoNo


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 CVAL field is the controlled variable value retrieved from the CVL link.

The LALM field is used to implement the hysteresis factor for the alarms.

The ALST field holds the last value for OVAL, but has no other function for the record.

The MLST field holds the last value for the OVAL field. It is used to calculate a value for DM when the record is in the POSITION mode. After any other calculations, DM is set equal to OVAL - MLST. Thus, even in POSTION mode, DM always holds a relative value, the difference between DM and the value of OVAL from the last time the record was processed.

The PMOD field indicates the current mode of the record:

  • 0 Normal Mode
  • 1 Manual Mode
  • 2 Sequencer Mode
  • 3 Local Control Mode

The last mode field (LMOD) implements monitors for PMOD. If PMOD is not equal to LMOD, monitors are posted for the PMOD field.


FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
CVALValue of controlled variableFLOATNo0YesYes/NoNoNo
OVALOutput ValueFLOATNo0YesYesYesNo
ODMOld DM. FLOATNo0YesNoYesNo
LALMValue from when last monitors for alarm were triggeredFLOATNo0YesNoNoNo
ALSTValue when last monitors for archiver were triggeredFLOATNo0YesNoNoNo
MLSTValue when last monitors for value changes were triggeredFLOATNo0YesNoNoNo
LOVLLast Readback ValueFLOATNo0YesNoNoNo
PMODCurrent ModeRECCHOICEYes0 NoYesNo
LMODLast ModeRECCHOICEYes0yesNoNoNo
ODMOld DM ValueFLOATNo0YesNoNoNo


Record Support

Record Support Routines

init_record

Set UDF to false. Return 0.

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 if field is CVAL or VAL. Otherwise, calls recGblGetPrec().

get_graphic_double

Sets the following values if field is VAL, HIHI, HIGH, LOW, LOLO, P, I, D, or CVAL:

upper_disp_limit = hopr
lower_disp_limit = lopr

get_control_double

Sets the following values if field is VAL, HIHI, HIGH, LOW, LOLO, P, I, D, or CVAL:

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:

  1. Set PACT to TRUE.
  2. If CVL is not a database link an INVALID alarm is declared, PACT is set to FALSE, and the routine returns (0).
  3. The current value of CVAL is obtained from CVL.
  4. If ORBL is a database link, the current value of ORBV is obtained.
  5. Determine the mode:
    • mode = normal
    • if SMOD true
      • mode = Sequencer mode
    • if MMOD true
      • mode = Manual mode
    • if value retrieved from LOC is 0
      • mode = Local Mode
  6. Compute time difference between current and last processing; that is , compute DT.
  7. Set DM = 0.
  8. If Mode is Normal and DT < MDT, calculate DM using PID expression.
  9. If Mode is Normal and OMOD is CHANGE:
    • if (ORBV + DM) is less than MAX
      • set OVAL = MAX - ORBV
    • else if (ORBV + DM) < MIN
      • set OVAL = MIN - ORBV
    • else set OVAL = DM
  10. If Mode is Normal and OMOD is POSITION and OVAL > MAX:
    • if (OVAL - MAX) > DMAX
      • set OVAL = OVAL - DMAX
    • if (OVAL - MAX) >= DMIN
      • set OVAL = MAX
  11. If Mode is Normal and OMOD is POSITION and OVAL < MIN.
    • if (MIN - OVAL) > DMAX
      • Set OVAL = OVAL + DMAX
    • if ( MIN - OVAL) >= DMIN
      • set OVAL = MIN
  12. If Mode is Manual and OMOD is CHANGE
    • set DM and OVAL to MVAL - ORBV.
  13. If Mode is Manual and OMOD is POSITION
    • set DM and OVAL to MVAL - ORBV.
  14. if Mode is Local Control and OMOD is CHANGE
    • set OVAL equal to 0.
  15. If Mode is Local Control and OMOD is POSITION
    • set OVAL equal to ORBV.
  16. If Mode is Sequencer and OMOD is CHANGE
    • set DM and OVAL to SVAL - ORBV
  17. If Mode is Sequencer and OMOD is POSITION
    • set DM and OVAL to SVAL.
  18. If OMOD is CHANGE
    • set DM equal to OVAL.
  19. If OMOD is POSITION
    • set DM equal to OVAL - MLST.
  20. Write OVAL to output location.
  21. Check alarms and post if any.
  22. Check monitors and post if any.
  23. Process FLNK.
  24. Set PACT equal to FALSE and return 0.


Device Support

The CPID record has no associated device support.




EPICS Record Reference Manual - 19 MAY 1998