3.4. Relay Control#
3.4.1. Relay Control for the Temperature Control Lab#
Relay control is perhaps the simplest form of feedback control that comes to mind for controlling common heaters. This is the on/off control familiar from home thermostats, air conditioners, and other devices where the manipulated variable is in either an “on” state or an “off” state.
The following code implements relay control for temperature T1 on the Temperature Control Lab. At each time step \(t_k\), the value of
where \( 0\% \leq U_{k} \leq 100\%\) refers to percentage of the maximum heater power, \(T_k\) is the measured temperature at time \(t_k\), and \(T^{SP}_k\) is the temperature setpoint at time \(t_k\). Typically \(U^{min}\) and \(U^{max}\) will be set to 0% and 100%, respectively, but other choices are possible.
Relay control can be implemented as a single line of code in the standard clock-driven loop of the Temperature Control Lab.
from tclab import TCLab, clock, Historian, Plotter, setup
TCLab = setup(connected=False, speedup=20)
# control parameters
U_min = 0
U_max = 100
T_SP = 40
# time horizon and time step
t_final = 250
t_step = 1
# perform experiment
with TCLab() as lab:
lab.P1 = 200
h = Historian(lab.sources)
p = Plotter(h, t_final)
for t in clock(t_final, t_step):
T1 = lab.T1 # measure temperature
U1 = U_max if lab.T1 < T_SP else U_min # compute manipulated variable
lab.Q1(U1) # adjust power
p.update(t) # log results
![../_images/0f6f3f113cd14e33bb3a7a504a3961823b1960d2539e50a8401b18ccb5d2d9b4.png](../_images/0f6f3f113cd14e33bb3a7a504a3961823b1960d2539e50a8401b18ccb5d2d9b4.png)
TCLab Model disconnected successfully.
![../_images/0f6f3f113cd14e33bb3a7a504a3961823b1960d2539e50a8401b18ccb5d2d9b4.png](../_images/0f6f3f113cd14e33bb3a7a504a3961823b1960d2539e50a8401b18ccb5d2d9b4.png)
3.4.2. Relay Control with Deadzone (Hysteresis) or Deadtime#
One of the issues with simple relay control is the potential for ‘chattering’ where the manipulated variable (in this case heater power) exhibits periods of rapid on-and-off switching. This can be caused by systems that are highly response to control inputs, or where sensor measurements carry significant noise.
There are several simple and highly effective solutions to the problem of chattering.
Deadzone (also called hysteresis). The manipulated variable is switched on or off only after the process variable has moved past the setpoint by a specified amount \(d\).
Deadtime Following an on-or-off transition in the manipulated variable, no further transition is allowed for a specified period of time called the deadtime.
The control algorithm for relay control with a deadzone extending \(d\) above and below the setpoint, a closed form is given by
where \(d\) is the tolerance or hysteresis.
For home heating systems a typical value is in the range of 0.5 to 1 degree F. This image shows how hystersis was adjusted on a typical home thermostat in common usage in the late 20th century.
The furnance is turned on for temperatures below the range
and is turned for temperatures above the range. Within the range, however, the furnance may be on or off depending on what happened at the last decision point.
The following code implements relay control with hystersis.
%matplotlib inline
from tclab import TCLab, clock, Historian, Plotter, setup
TCLab = setup(connected=False, speedup=20)
# control parameters
U_min = 0
U_max = 100
T_SP = 40
d = 0.5
# time horizon and time step
t_final = 250
t_step = 1
# perform experiment
with TCLab() as lab:
lab.P1 = 200
h = Historian(lab.sources)
p = Plotter(h, t_final)
U1 = U_min
for t in clock(t_final, t_step):
T1 = lab.T1
if T1 <= T_SP - d:
U1 = U_max
elif T1 >= T_SP + d:
U1 = U_min
lab.Q1(U1)
p.update(t)
![../_images/57c799f73794550789f290429da68470d5effcb93874bda96c594b75b9645bc7.png](../_images/57c799f73794550789f290429da68470d5effcb93874bda96c594b75b9645bc7.png)
TCLab Model disconnected successfully.
![../_images/57c799f73794550789f290429da68470d5effcb93874bda96c594b75b9645bc7.png](../_images/57c799f73794550789f290429da68470d5effcb93874bda96c594b75b9645bc7.png)
Study Question: Examining the closed-loop responses, it’s obvious that the heater is oversized for the purpose of control at 40 deg C. Try other values for \(Q^{\max}\) to see if you can improve closed-loop performance.
Study Question: What is the effect of sample time on control performance? What happens if you make the controller sample time longer?
Study Question: In a new cell, create a modification of the script to include a change in setpoint from 40 deg C to 50 deg C at the 300 second mark. Run the experiment for at least 10 minutes to see the full effect.
Study Question: For a relay control with deadzone (also called hysteresis), try to sketch a graph of the manipulated variable \(Q\) as a function of the process variable \(T\). Assume the setpoint is 50 and \(d = 3\). Can you draw a unique function? Why not?