EPID Record

Author: Mark Rivers

Contents

 

Introduction


The EPID record is used to maintain a setpoint that affects the output according to the difference between a controlled value and the setpoint. It provides EPICS with a very flexible and powerful tool for peforming feedback. The EPID record is an Enhanced version of the EPICS PID record. The major improvements in the EPID record compared to the PID record include:

Each time the record is processed the setpoint is read and then the do_pid() function in device support is called. The Soft Record device support reads the controlled value, computes the PID expression and, if feedback is enabled, writes its output to the output link.

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.

 

Scan Parameters


The PID record has the standard fields (SCAN, etc.) for specifying under what circumstances it will be processed. 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. The actual meaning of the SCAN and MDT fields depends upon which device support is used:

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 meaning of the INP field depends upon what device support is used:

  • Soft Record device support. The input link field (INP) 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. The INP field can be modified at run-time.
  • MPF Ip330PID device support. The input link field (INP) is used to specify the location of the MPF Ip330PID server which actually performs the feedback. The Ip330PID server is configured in the vxWorks MPF server startup file to specify which Ip330 ADC channel is used as the input from which the value is read into the CVAL field. The link must be a VME link, and cannot be modified at run-time.
  • Field Summary Type DCT Initial Access Modify Rec Proc Monitor PP
    INP Controlled Value Location (an input link) INLINK Yes 0 Yes Yes N/A No
    CVAL Value of controlled variable FLOAT No 0 Yes No Yes 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. STML can also be a constant in which case VAL is set equal to the constant value when the record is initialized, and the value can be modified at run-time via database access or channel access.

    Field Summary Type DCT Initial Access Modify Rec Proc Monitor PP
    STPL Setpoint Location (an input link) INLINK Yes 0 Yes Yes N/A No
    SMSL Setpoint Mode select. GBLCHOICE Yes 0 Yes Yes No No
    VAL Setpoint value FLOAT No 0 Yes Yes Yes Yes

     

    Output parameters


    There are two fields which control the output of the EPID record, FBON (Feedback On) and OUTL (Output Link). The meanings of the these fields depends upon what device support is used:

  • Soft Record device support. The output link field (OUTL) is used to control where the computed output (OVAL) is sent. If OUTL is a database link and if FBON=1 then the output value (OVAL) is written to this link each time the record processes. If FBON=0, or if OUTL is not a database link then the device support still computes the OVAL but does not write OVAL to the output link.
  • MPF Ip330PID device support. The output link field (OUTL) is not used. Rather, the Ip330PID server is configured in the vxWorks MPF server startup file to specify which DAC128V DAC channel is used as the output. If FBON=1 then the computed output will be written to the DAC channel each time the feedback loop executes. The execution of the feedback loop is independent of, and typically much faster than the rate at which the EPID record processes. If FBON=0 then the feedback loop still executes, but it does not write the output to the DAC channel.
  • Field Summary Type DCT Initial Access Modify Rec Proc Monitor PP
    OUTL Output Location (an outlink) OUTLINK Yes 0 Yes Yes N/A No
    FBON Feedback On or Off MENU Yes Off Yes Yes No No

     

    Feedback Parameters


    The discrete from of the PID expression is as follows:

    M(n) = P + I + D

    P = KP * E(n)

    I = KP * KI * SUMi ( E(i) * dT(n) )

    D = KP * KD * ( (E(n) - (E(n-1) ) / dT(n) )

    where

    M(n) = value of manipulated variable at nth instant.
    P = Proportional term
    I = Integral term
    D = Derivative term
    KP = Proportional gain
    KI = Integral gain
    KD = Derivative gain
    E(n) = Error at nth sampling instant
    SUMi = Sum from i=0 to i=n
    dT(n) = Time difference between n-1 instance and nth instance

    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) terms. 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 per second that the integral contribution repeats the proportional contribution; and KD should equal the number of seconds until the derivative contribution repeats the proportional contribution. See the guide to feedback tuning below for more information on setting KP, KI and KD.

    The PID device support calculates the other terms of the expression. The Soft Record and MPF Ip330PID device support both calculate these as follows:

    E(n)
    Error at nth sampling instant, where the Error equals the setpoint minus the value of the controlled variable (VAL - CVAL). The ERR field in the record holds this value.
    P
    Proportional term, calculated from the above equation. The P field in the record holds this value.
    I
    Integral term, calculated from the above equation. The I field in the record holds this value. Note that the integral term is a sum from time=0 to the present time, and hence can grow extremely large if not subject to some "sanity checks". The EPICS PID record does not perform any such checks, which is a serious limitation. The EPID record device support performs the following checks to prevent the integral term from growing too large when feedback is not working correctly:
    D
    Derivative term. The D field in the record holds this value.
    M(n)
    This is the end result of the PID expression--the change in the manipulated value, which is the desired output. The OVAL field holds this value. However, OVAL is first limited to be no smaller than DRVL and no larger than DRVH.
    dT(n)
    This is the time difference between n and n-1, between current and last samplings. It is stored in the DT field. For the Soft Record device support this field is Read-Only. For the MPF Ip330PID device support this field can be modified to control the time per feedback loop.
    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
    ERR Current error (VAL - CVAL) FLOAT No 0 Yes No Yes No
    P Proportional contribution to OVAL FLOAT No 0 Yes No Yes No
    I Integral contribution to OVAL FLOAT No 0 Yes Yes Yes No
    D Derivative contribution to OVAL 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 Yes Yes No
    OVAL Output value FLOAT No 0 Yes No Yes No
    DRVL Low limit on OVAL FLOAT Yes 0 Yes Yes No No
    DRVH High limit on OVAL FLOAT Yes 0 Yes Yes No No

     

    Feedback Tuning


    The following is intended to provide some guidance on selecting the optimal values for KP, KI and KD.

    1. Turn off feedback (FBON=0).

    2. Set KI and KD to zero initially in order to first determine the optimum value for KP.

    3. If possible calculate theoretically or empirically the "correct" value of KP, e.g. the required change in OVAL to produce a unit change in CVAL. For example if controlling a heater power supply with a DAC which has 10 Watt/volt response, and the heater response is 10 degrees/Watt, then KP=.01 volts/degree.

    4. Set KP to about 10%-25% of the "correct" value computed above.

    5. Turn on feedback (FBON=1) and make changes in the setpoint (VAL) and observe the system response. Don't worry about system droop (CVAL != VAL), since this is unavoidable when KI=0. Rather look for oscillations and instability. Gradually increase KP while making changes in the setpoint. When KP is too large the system will begin to oscillate. Decrease KP until the oscillations just disappear.

    6. Increase KI (units of Hz) to eliminate the system droop. The optimum value of KI depends upon the time constant of the system and the update rate of the feedback loop. Increase KI until the system responds as rapidly as possible to changes in the setpoint without overshoot or oscillation.

    7. For systems with no significant inertia KD should be left at zero. For systems with large inertia increase KD (units of seconds) to minimize overshoot.

     

    Operator Display Parameters


    These parameters are used to present meaningful data to the operator. They display the setpoint (VAL), the controlled variable (CVAL), the output value (OVAL), and other fields of the EPID, 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, CVAL, HIHI, HIGH, LOW, and LOLO fields.

    The DRVH and DRVL fields set the upper and lower display limits for the OVAL, P, I, and D 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.

    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 Yes 0 Yes No No No
    DESC Description STRING Yes Null Yes Yes No No

     

    Alarm Parameters


    The possible alarm conditions for EPID 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.

    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

     

    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 OVAL field, the field which holds the manipulated value. Unless the current value of OVAL is greater than the amount which the user specifies in this field, no monitors will be invoked. If zero, anytime OVAL 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 OVAL, they are also called for the following fields which comprise the PID expression: P, I, D, CT, DT, ERR, and DERR.

    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


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


    init_record

    If STPL is a constant link, initialize VAL with it's value and set UDF to false.

    Call init_record routine in device support. For Soft Record device support this does nothing. For MPF Ip330PID device support this establishes the connection to the MPF server.

    process

    See next section.

    get_value

    Null.

    get_units

    Retrieves EGU.

    get_precision

    Retrieves PREC.

    get_graphic_double

    Sets the following values:

    For the VAL, CVAL, HIHI, HIGH, LOW, and LOLO fields sets:

  • upper_disp_limit = HOPR
  • lower_disp_limit = LOPR
  • For the OVAL, P, I, and D fields sets:

  • upper_disp_limit = DRVH
  • lower_disp_limit = DRVL
  • get_control_double

    Sets the following values

    For the VAL, CVAL, HIHI, HIGH, LOW, and LOLO fields sets:

  • upper_ctrl_limit = HOPR
  • lower_ctrl_limit = LOPR
  • For the OVAL, P, I, and D fields sets:

  • upper_ctrl_limit = DRVH
  • lower_ctrl_limit = DRVL
  • get_alarm_double

    Sets the following values if the field is VAL:

    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. If STPL is a database link and SMSL is CLOSED_LOOP then VAL is obtained from STPL and UDF is set to false.
    2. The device support do_pid routine is called. If device supports sets PACT=true (which the MPF Ip330PID device support does when it needs to communicate with the MPF server) then return immediately.
    3. 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.
    4. Checks to see if monitors should be invoked:

     

    Device Support


    Device support for the EPID record should implement at least the init_record and do_pid functions. New device support for the EPID record could be written, for example, to communicate with hardware PID controllers.

    There is presently device support for Soft Record (which is very similar to the record support in the EPICS PID record) and for the MPF Ip330PID server.

    Soft Record

    init_record()
    This does nothing in the current implementation.

    do_pid()

    1. If CVL is not a database link a major alarm is declared and the algorithm completes.
    2. The current value of CVAL is obtained from CVL.
    3. 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.
    4. The new values of P, I, D, OVAL, CT, DT, and ERR are computed.
    5. If feedback is On (FBON=1) and OUTL is a valid output link then OVAL is written to the output link.

    MPF Ip330PID

    init_record()
    This calls the dev_init routine, which creates the DevMpf object and establishes communication with the MPF Ip330PID server.

    do_pid()

    1. Checks to see if any of the parameters KP, KI, KD, DT, DRVH, DRVL, VAL, or FBON have changed and if so sends the new values to the MPF server.
    2. Reads the current values of CVAL, ERR, OVAL, P, I, D, and DT from the MPF server.

    Suggestions and Comments to:
    Mark Rivers : (rivers@cars.uchicago.edu)
    Last modified: November 25, 1999