5.1. Relay Control#
5.1.1. Simple Relay Control#
The following code implements relay control for temperature T1 on the Temperature Control Lab.
This is simple to implement, in fact it is just one line of code in the following cell. Adjust Tsetpoint
to a desired setpoint value, then run the cell.
%matplotlib inline
from tclab import TCLab, clock, Historian
# control parameters
Qmax = 100
Tsetpoint = 40
# time horizon and time step
tfinal = 300
tstep = 1
# perform experiment
with TCLab() as a:
h = Historian(a)
h.initplot(tfinal)
for t in clock(tfinal, tstep):
T1 = a.T1 # measure temperature
Q1 = Qmax if a.T1 < Tsetpoint else 0 # compute manipulated variable
a.Q1(Q1) # adjust power
h.update(t) # log results
TCLab disconnected successfully.
5.1.2. Relay Control with Hysteresis#
One of the issues with simple relay control is the potential for ‘chattering’, which are situations where the manipulated variable (in this case heater power) rapid on-and-off switching. This can be caused by systems that are highly response to control inputs or where the sensor measurements carry significant noise.
The typical home thermostat used for furnace control incorporates a simple but highly effective solution to the chattering period. The idea is to intentially overshoot the setpoint. Then, after the control switches state, there will be at least a short period of time where no further control action should be necessary. The control algorithm can be written
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
# control parameters
Qmax = 100
Tsetpoint = 50
d = 0.5
# time horizon and time step
tfinal = 300
tstep = 1
# perform experiment
with TCLab() as a:
h = Historian(a)
h.initplot(tfinal)
Q1 = a.Q1()
for t in clock(tfinal, tstep):
T1 = a.T1
if T1 <= Tsetpoint - d/2:
Q1 = Qmax
if T1 >= Tsetpoint + d/2:
Q1 = 0
a.Q1(Q1)
h.update()
TCLab disconnected successfully.
5.1.3. Multivariable On-Off Control#
%matplotlib inline
from tclab import TCLab, clock, Historian
Tsetpoint1 = 45
Tsetpoint2 = 35
Qmax = 100
tfinal = 480
d = 0.5
with TCLab() as a:
h = Historian(a)
h.initplot(tfinal)
Q1 = a.Q1()
Q2 = a.Q2()
for t in clock(tfinal):
T1 = a.T1
if T1 <= Tsetpoint1 - d/2:
Q1 = Qmax
if T1 >= Tsetpoint1 + d/2:
Q1 = 0
a.Q1(Q1)
T2 = a.T2
if T2 <= Tsetpoint2 - d/2:
Q2 = Qmax
if T2 >= Tsetpoint2 + d/2:
Q2 = 0
a.Q2(Q2)
h.update()
TCLab disconnected successfully.
5.1.4. Exercises#
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.
What is the effect of sample time on control performance? What happens if you make the controller sample time longer?
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.
For a relay control with hystersis, try to sketch a graph of \(Q\) as a function of \(T\) assuming \(T_{Setpoint} = 50\) and \(h = 3\). Can you draw a unique function? Why not?