5.1. Relay Control#

5.1.1. Simple Relay Control#

The following code implements relay control for temperature T1 on the Temperature Control Lab.

(5.10)#\[\begin{align} Q(t) & = \begin{cases} Q^{max} &\text{if $T \leq T_{setpoint}$}\\ 0 & \text{if $T \geq T_{setpoint}$} \end{cases} \end{align}\]

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
../_images/8b8e8305aa74898e4579f72042fca9c6e975afe06202780b5c37d4a9ad1629a3.png
TCLab disconnected successfully.
../_images/8b8e8305aa74898e4579f72042fca9c6e975afe06202780b5c37d4a9ad1629a3.png

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

(5.11)#\[\begin{align} Q(t) & = \begin{cases} 0 & \text{if $T \geq T_{Setpoint} - \frac{d}{2}$}\\ Q^{max} &\text{if $T \leq T_{Setpoint} + \frac{d}{2}$}\\ Q(t-\delta t) & \mbox{otherwise} \end{cases} \end{align}\]

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.

Honeywell thermostat open

The furnance is turned on for temperatures below the range

(5.12)#\[\begin{align} T_{Setpoint} - \frac{d}{2} \leq T \leq T_{Setpoint} + \frac{d}{2} \end{align}\]

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()
../_images/425ea50e2e892e6f5cd5a14c425abd6890bd5d74302df3d29324b7e1d97235af.png
TCLab disconnected successfully.
../_images/425ea50e2e892e6f5cd5a14c425abd6890bd5d74302df3d29324b7e1d97235af.png

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()
../_images/4588b28c40558fa82c68834d8e630cffc1043ecc66cbb25b9f8c9cc87f4a2b84.png
TCLab disconnected successfully.
../_images/4588b28c40558fa82c68834d8e630cffc1043ecc66cbb25b9f8c9cc87f4a2b84.png

5.1.4. Exercises#

  1. 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.

  2. What is the effect of sample time on control performance? What happens if you make the controller sample time longer?

  3. 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.

  4. 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?