EPICS ePID controls for feedback

Purpose: use the EPICS epid record for generic software feedback

Author: Pete R. Jemian

subversion property $Id: index.html 9860 2009-12-09 22:40:21Z jemian $

Theory of operation

  1. A signal is available as an EPICS process variable (IN). The signal source can be in the same VME with the feedback software or in another VME (or other EPICS IOC) available on the network.
  2. An input calculation (swait record) is used to allow some flexibility for conditioning the input signal to the feedback.
  3. An epid record is used to provide real-time feedback and recalculate the output variable.
  4. The output from the epid record is buffered by the outbuf calculation which watches the Feedback ON (FBON) switch and retains the previous output value if the feedback software is switched off.
  5. An output calculation is used to allow some flexibility for conditioning the output signal to the positioner (OUT). The conditioned epid result is pushed to the positioner.
  6. A positioner responds to the result from the epid record and thus further modifies the input signal.
  7. The feedback can be switched on manually or automatically, subject to the logic of some other calculation (CALC). For example, a shutter closed signal could suspend feedback. In this case, the output is not driven.
  8. When the feedback is switched on, the positioner should not jerk to a different position. The feedback software must be prepared to start moving the positioner from its present location.

Related information

MEDM control screen

fb_epid database GUI

The MEDM screen provides access to all the controls of the epid record. To add some flexibility, an EPICS interface database has been created. The user can change the input variable(s) through a calculation (swait record).

Control of the output variable will be permitted between the software limits shown at the bottom of the control screen. From the output calc, it is possible to change the PV which will be directed by this database.

The enable calculation can be used to provide automated on/off.

MEDM controls

Information for the EPICS System Administrator

How to use the database

Use one instance of this database for each feedback channel. If two different methods for feedback are desired for a given axis, call two instances of this database. For example, on 33ID for feedback of the DCM crystal 2 PZT, one might choose either the XBPM position signal or the D3 graphite foil intensity to drive the PZT position.

Example XBPM position feedback
macro meaning
P iad:fbe:xbpm:y
IN iad:xbpm:pos:y
OUT iad:540:c0:out0
MODE PID
CALC A&&B&&C
PERMIT1 iad:beamAvailable.VAL
PERMIT2 iad:xbpm:current:ok.VAL
PERMIT3  
PERMIT4  
Example D3 foil feedback
macro meaning
P iad:fbe:D3:y
IN iad:540:c0:in10
OUT iad:540:c0:out0
MODE Max/Min
CALC A&&B
PERMIT1 iad:beamAvailable.VAL
PERMIT2  
PERMIT3  
PERMIT4  

Database flow chart

The present database was constructed after a brief period of development testing.

database flow chart

User Configuration

Once the software has been installed (IOC configured with database and autosave/restore configured to retain settings across restarts of the IOC), some careful setup needs to happen before the software is ready to be used.

First, it is necessary to identify the EPICS PVs for the control variable (such as a positioner or the power to a heating element) and the signal variable (the PV that is sampled for the PID loop). These may have been configured in the IOC but it is possible to change them while the IOC is running. They can be changed without need to recompile or restart the EPICS IOC.

To avoid any unexpected consequences, be sure the fb_epid software is switched off before changing any PVs or changing between modes of operation. In the MEDM screen, in the EPID output section, press the button marked off.

It is most important to make sure that the input signal is updated faster than the recalculation interval for the fb_epid software or instability will occur. A factor of 3 to 10 input updates per output update is reasonable. The output will be updated each time the epid is processed.

Setup of the calculations

The versatility of the fb_epid support lies in the various calculations that can be reconfigured by the user while the IOC is operating.

Setting the enable calculation

The operation of fb_epid is permitted when the result of the enable calculation is 1.0. The first, obvious, choice is that bo record is provided to the user to switch the fb_epid software on and off. But the software should also disable itself when the input signal goes out of range or also due to some other operating parameters.

Other factors can be built into the enable calculation. For example, on undulator beam lines, it is not useful to run the feedback if the undulator is not operating (gap is closed or magnets are energized). In such a case, monitor the PV for the undulator gap (APS undulator A) and enable only if the gap is below some reasonable number such as 50 mm.

One should also factor the fb_epid input signal into the enable calculation by checking that is within a valid operating range.

Setting the input calculation

It is possible to perform limited math on the input signal to be used. For example, when the goal is to maximize the conductance through a crystal pair, such as a monochromator, the best signal would be a ratio between detector immediately before and after the pair of crystals. The control variable would be the rotation angle of either of the two crystals (usually a fine rotation of the second crystal). The input calculation would then monitor the PVs for both detectors and calculate the ratio of the two: A/B. In this example, it would also be useful to include the PV of this calculation in the enable calculation and ensure that the ratio is acceptable.

Setting the limits on the output

To prevent the epid record from driving the control variable out of bounds, there are limits for low and high. The software will not allow the positioner to drive outside of these limits. Editor: Is this correct or is it a clamp on the output or a reset if the value is found to go outside the range?

Tuning of the epid record

For more information about the EPICS epid record, see http://cars9.uchicago.edu/software/epics/epidRecord.html. There is a special discussion on feedback tuning in PID mode.

The epid record can run in either Max/Min or PID mode. Max/Min is used to maximize a positive input signal or minimize a negative input signal such as from a beam line detector. PID mode is used to keep the input signal at constant value such as holding a sample's temperature constant.

Editor: What is the role of the Set Point in PID mode? Probably need to check the epid record source code for this information.

Max/Min mode

Max/Min mode is useful for monochromator feedback or other situations where a positive signal is to be maximized (or a negative signal is to be minimized). The online epid record documentation is lacking details about this mode so one is referred to inspecting the source code.

PID mode

PID mode is useful for holding the input signal to the Set Point by adjusting the control variable. The epid record documentation provides a good description of how to set the PID constants.

Macro substitutions in the support files

Macro substitutions in the fb_epid.adl file

Here is an example command line that calls the support.

need to supply example

There are several macro substitutions in the fb_epid.adl to simplify use of the MEDM screen.

macro description
$(P) Prefix for this instance of support.
$(E) description

Macro substitutions in the fb_epid.db file

There are several macro substitutions in the fb_epid.db to simplify installation of the EPICS database.

macro description
$(P) Prefix for this instance of this database. Note that $(P):in.INAN holds PV name of input PV (by default)
$(IN) PV name: input signal
$(OUT) PV name: output positioner
$(MODE) either PID or Max/Min
$(CALC) string: actual calculation to go in $(P):enable.CALC, 1=feedback on, 0=feedback off. A trivial value might be "A" which only watches the value of $(P):on.
$(PERMIT1) PV name: boolean value to permit operations; value becomes $(P):enable.B
$(PERMIT2) PV name: boolean value to permit operations; value becomes $(P):enable.C
$(PERMIT3) PV name: boolean value to permit operations; value becomes $(P):enable.D
$(PERMIT4) PV name: boolean value to permit operations; value becomes $(P):enable.E