This lab assignment introduces the use of PID control for the temperature control laboratory. In this assignment you will be
The first step is attempt completely manual control of the dual heaters. Using the GUI interface below, connect to the temperature control lab, and adjust heaters Q1 and Q2 to acheive steady state temperatures of 50°C for T1 and 40°C for T2.
Hint: The there is interaction between the heaters, i.e, an adjustment in either Q1 or Q2 will affect both T1 and T2. So this is exercise in satisfying two constraints by manipulating two variables.
from tclab.gui import NotebookUI
%matplotlib notebook
interface = NotebookUI()
interface.gui
Given a process variable $PV$ and setpoint $SP$, proportional-integral-derivative control determines the value of a manipulated variable MV by the rule
\begin{align} MV & = \bar{MV} + K_p\left(SP - PV\right) + K_i \int_0^t \left(SP-PV)\right)dt + K_d \frac{d\left(SP-PV\right)}{dt} \end{align}where $K_p$, $K_i$, and $K_d$ are the proportional, integral, and derivative coefficients, respectively.
The following code defines a Python object that implements this algorithm.
class PID:
def __init__(self):
self.Kp = 1
self.Ki = 100
self.Kd = 0
self.e = 0
self.dedt = 0
self.eint = 0
self.mv = 0
def update(self, setpoint, pv):
e = setpoint - pv
self.dedt = self.e - e
self.eint += e
self.e = e
self.mv = self.Kp * self.e + self.Ki * self.eint + self.Kd * self.dedt
return self.mv
The following cell provides an initial implementation of PID control for heater T1. Modify this code to add a second controller, pid2
, for heater T2. Test using the off-line simulator. When happy with the results, apply the control to the actual heater.
from tclab import setup, clock, Historian, Plotter
TCLab = setup(connected=False, speedup = 20)
pid1 = PID()
pid1.Kp = 2
pid1.Ki = .1
pid1.Kd = 2
with TCLab() as lab:
h = Historian(lab.sources)
p = Plotter(h, 800)
for t in clock(800):
lab.U1 = pid1.update(50, lab.T1)
p.update(t)
Using the code you developed above, create a new cell below and test the following issues:
Describe the benefits of integral and derivative action.