Example: Feedback using the epid record

This example builds on the previous example where a sensor creating a signal was connected to the Arduino and monitored from EPICS. An LED was connected to the Arduino to control (or modify) the first signal.

This example will control the output of the LED based on the signal from the sensor. We’ll test our controls by changing the background lighting levels and the desired signal level from the sensor. In effect, we are building constant lighting (maintaining a constant level of illumination).

Requirements:

  • Arduino system with specified electronics circuit (Electronic Circuit: photocell and LED)
  • Linux computer with Arduino interface
  • EPICS IOC configured to communicate with Arduino
  • CSS BOY client for EPICS [1]

The EPICS epid record [2] is used to continuously update the control based on updates to the signal with the goal of driving the signal to a desired set point. The epid record provides an extended Proportional-Integral-Derivative controller (for more information about PID control, see, for example, these documents from the University of Michigan: [3], [4], [5]) to a process configured by EPICS PVs. Additional equations are sketched out [6] that convert the terms of the UMich documentation into terms of the epid record.

Basic PID Theory

At its heart, PID control is implemented to maintain a time-dependent, measured signal, \(M(t)\), at a desired value, \(D(t)\) by adjusting a control, \(Y(t)\). The general PID equation is based on the concept of a process error, \(\epsilon(t)\), that is the difference between the actual and desired values of the signal:

\[\epsilon(t) = M(t) - D(t)\]

general PID equation ([5]):

\[Y(t) = K_c \left[ { \epsilon(t) + {1 \over T_i}\int_0^t \epsilon(t_i)d{t_i} + T_d {d\epsilon(t) \over dt} } \right] + Y(t_0)\]

epid record PID equation ([2]):

\[Y_n = K_P \epsilon(t) + K_P K_I \sum_i {\epsilon_i \delta t_i} + K_P K_D {\epsilon_n - \epsilon_{n-1} \over \delta t_n}\]

Note

The process error, \(\epsilon(t)\), is also known as various other names, such as following error.

Outline

Definition of Terms

term description
\(t\) time
\(M(t)\) measured input signal as a function of time
\(D(t)\) set point (desired value of signal) as a function of time
\(Y(t)\) chosen control output as a function of time
\(\epsilon(t)\) process error: \(\epsilon(t) = M(t) - D(t)\)
\(K\) generalized process gain: \(K = {\hbox{change in output} \over \hbox{change in input}}\)
\(K_c\) process gain constant (from theory, to be determined empirically)
\(T_i\) process integral coefficient (from theory, to be determined empirically)
\(T_d\) process derivative coefficient (from theory, to be determined empirically)
\(K_P\) proportional gain coefficient (EPICS user input): \(K_P = K_C\)
\(K_I\) integral gain coefficient (EPICS user input): \(K_I = {K_C / T_i}\)
\(K_D\) derivative gain coefficient (EPICS user input): \(K_D = K_C T_d\)
\(\tau\) time for response to complete
\(\tau_d\) dead time before system starts to respond
\(\delta t\) time between samples

Configuration of epid

-tba-

Adjusting \(K_p\), \(K_i\), and \(K_d\)

-tba-

Measure the System Response

Once the PID parameters are adjusted for the local particulars, the performance can be demonstrated by charting \(D(t)\), \(M(t)\), and \(Y(t)\). The next figure shows such a chart for a few days in January, Chicago area.

fig.CSSBOY_epid_chart

Example operation of epid feedback for several days (CSSBOY_epid_chart.png). Colors: \(D(t)\) (set point, blue), \(M(t)\) (photocell, red), \(Y(t)\) (LED, green)

The chart, at first, shows steady-state operations of a tuned PID loop. With \(M(t)=\mbox{1.3}\), the loop varies the LED brightness (\(Y(t)\)) to hold \(M(t)\) steady. At night, the LED is brightest. During the day, the LED brightness is reduced to maintain the chosen set point.

Some time on 01-28, the epid feedback was turned off (manually) and \(Y(t)\) was set to zero. In this case, the ambient light level is recorded by \(M(t)\). On 01-29, \(D(t)\) was also set to zero. Since the epid loop was off, this change had not effect. Note that in the overnight period, the sensor was not able to detect variations in the ambient darkness. Selection of different resistors would improve the nighttime sensitivity but that is for a different project. With the feedback on, the signal is within range of both the photocell and the LED such that \(Y(t)\) can be used to correlate lighting conditions at any time of day or night.

Later on 01-29, the epid feedback was resumed and the loop locked in within the charted sampling period. Actual time for lockin with the terms shown was within 10 seconds.

Spikes in the photocell signal, \(M(t)\), appear on 01-30 and are likely due to USB communications errors between EPICS and the Arduino. The short-lived spikes have no obvious effect on the epid operations.

The variations of \(Y(t)\) on 01-30 correlate with ambient conditions on that day (reflections from passing traffic, lighting, weather) and indicate the response of the epid controls to changing conditions as it maintains the chosen set point.

When epid feedback is turned on, the lighting level is held constant. At this point, we declare success and finish this document.