Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

TCLab Mathematical Model

We will use the TCLab as a motivating example for this workshop.

The code below sets default font sizes.

import matplotlib.pyplot as plt

SMALL_SIZE = 14
MEDIUM_SIZE = 16
BIGGER_SIZE = 18

plt.rc("font", size=SMALL_SIZE)  # controls default text sizes
plt.rc("axes", titlesize=SMALL_SIZE)  # fontsize of the axes title
plt.rc("axes", labelsize=MEDIUM_SIZE)  # fontsize of the x and y labels
plt.rc("xtick", labelsize=SMALL_SIZE)  # fontsize of the tick labels
plt.rc("ytick", labelsize=SMALL_SIZE)  # fontsize of the tick labels
plt.rc("legend", fontsize=SMALL_SIZE)  # legend fontsize
plt.rc("figure", titlesize=BIGGER_SIZE)  # fontsize of the figure title
plt.rc("lines", linewidth=3)

Temperature Control Lab

The temperature control lab is an Arduino-based hands-on experiment for teaching dynamic modeling and process control developed by Prof. John Hedengren. At Notre Dame, we restructured our core undergraduate process control class around six hands-on laboratory assignments with the TCLab.

The TCLab board contains two heater plus temperature sensor assemblies. Using Python (or MATLAB), students can independently maninputate the electrical power to the heaters and measure the temperatures.

TC Lab hardware

System Identification Data

Using the TCLab, we performed two system identification tests: step test and sine wave test.

Step Test

We will start by loading the data using pandas.

import sys

on_colab = "google.colab" in sys.modules
if on_colab:
    file = "https://raw.githubusercontent.com/dowlinglab/pyomo-doe/main/data/tclab_step_test.csv"
else:
    file = "../data/tclab_step_test.csv"

import pandas as pd

df = pd.read_csv(file)
df.head()
Loading...

Let’s start by plotting the heater data.

ax = df.plot(x="Time", y=["Q1", "Q2"], xlabel="Time (s)", ylabel="Heater Power (%)")
<Figure size 640x480 with 1 Axes>

In this step test, heater 1 was set to 50% power and heater 2 was off. Let’s see the resulting temperature profiles.

import matplotlib.pyplot as plt

ax = df.plot(x="Time", y=["T1", "T2"], xlabel="Time (s)", ylabel="Temperature (°C)")
<Figure size 640x480 with 1 Axes>

As expected, temperature 1 rises as expected for a (near) linear system. The experimentation noise is noticeable once the device approaches steady-state after 600 seconds. As expected, temperature 2 gradually rises in response to heater assembly 1 heating up. On the device, the two heater assembles are separated by ~1 cm.

Sine Test

if on_colab:
    file = "https://raw.githubusercontent.com/dowlinglab/pyomo-doe/main/data/tclab_sine_test_5min_period.csv"
else:
    file = "../data/tclab_sine_test_5min_period.csv"

df2 = pd.read_csv(file)
df2.head()
Loading...
ax = df2.plot(x="Time", y=["T1", "T2"], xlabel="Time (s)", ylabel="Temperature (°C)")
<Figure size 640x480 with 1 Axes>

Two-State Mathematical Model

Using these data, we want to develop a science-based mathematical model for the TCLab. For simplicity, we will develop a mathemical single heater and temperature sensor assembly. However, this workshop example also supports modeling both assemblies.

TCLab schematic

We will define two states:

  • TH,1T_{H,1} is the temperature of the heater/fin assembly (°C)

  • TS,1T_{S,1} is the temperature of the sensor (°C)

Assumptions:

  • The two bodies are uniform temperature, i.e., we are neglecting any temperature gradients in the fin.

  • The sensor exchanges heat only with the heater, and heat transfer to the surroundings is dominated by the heat sink attached to the heater.]

  • Heat capacities CpC_p are constant.

  • Radiative heat transfer is negligible.

We define the manipulated variable:

  • u1u_1 is the power sent to the heater (% of max)

This motivates the following model:

CpHdTH,1dt=Ua(TambTH,1)+Ub(TS,1TH,1)+αP1u1CpSdTS,1dt=Ub(TH,1TS,1)\begin{align} C^H_p\frac{dT_{H,1}}{dt} & = U_a(T_{amb} - T_{H,1}) + U_b(T_{S,1} - T_{H,1}) + \alpha P_1u_1\\ C^S_p\frac{dT_{S,1}}{dt} & = U_b(T_{H,1} - T_{S,1}) \end{align}

The model has the following unknown parameters:

  • CpHC^H_p is the heat capacity of the heater/fin assembly (J / °C)

  • CpSC^S_p is the heat capacity of the sensor (J / °C)

  • UaU_a is the heat transfer coefficient from the heater/fin to ambient (W / °C)

  • UbU_b is the heat transfer coefficient from the heater/fin to the sensor (W / °C)

And the following known parameters:

  • αP1\alpha P_1 are constants for the TCLab (W / %)

  • TambT_{amb} is the ambient temperature (°C)

State Space Model

Although not essential for this tutorial, we can write this model a a state space linear system.

The initial steady state is TambT_{amb}. So let’s write the dependent variables as excursions from the ambient temperature.

CpHd(TH,1Tamb)dt=Ua(TambTH,1)+Ub((TS,1Tamb)(TH,1Tamb))+αP1u1CpSd(TS,1Tamb)dt=Ub((TH,1Tamb)(TS,1Tamb))\begin{align} C^H_p\frac{d(T_{H,1} - T_{amb})}{dt} & = U_a(T_{amb} - T_{H,1}) + U_b((T_{S,1} - T_{amb}) - (T_{H,1} - T_{amb})) + \alpha P_1u_1\\ C^S_p\frac{d(T_{S,1} - T_{amb})}{dt} & = U_b((T_{H,1} - T_{amb}) - (T_{S,1} - T_{amb})) \end{align}

Then divide by the heat capacities.

d(TH,1Tamb)dt=Ua+UbCpH(TH,1Tamb)+UbCpH(TS,1Tamb)+αP1CpHu1d(TS,1Tamb)dt=UbCpS((TH,1Tamb)(TS,1Tamb))\begin{align} \frac{d(T_{H,1} - T_{amb})}{dt} & = -\frac{U_a+U_b}{C^H_p}(T_{H,1} - T_{amb}) + \frac{U_b}{C^H_p}(T_{S,1} - T_{amb}) + \frac{\alpha P_1}{C^H_p}u_1 \\ \frac{d(T_{S,1} - T_{amb})}{dt} & = \frac{U_b}{C^S_p}((T_{H,1} - T_{amb}) - (T_{S,1} - T_{amb})) \end{align}

The two-state model can be rewritten using vectors to collect the states, inputs, measurable outputs, and arrays to collect the coefficients of the differential equations.

ddt[TH,1TambTS,1Tamb]x=[Ua+UbCpHUbCpHUbCpSUbCpS]A[TH,1TambTS,1Tamb]x+[αP1CpH0]B[u1]u[TS,1Tamb]y=[01]C[TH,1TambTS,1Tamb]x\begin{align} \frac{d}{dt}\underbrace{\begin{bmatrix} T_{H,1} - T_{amb} \\ T_{S,1} - T_{amb} \end{bmatrix}}_\mathbf{x} & = \underbrace{\begin{bmatrix} -\frac{U_a+U_b}{C^H_p} & \frac{U_b}{C^H_p} \\ \frac{U_b}{C^S_p} & - \frac{U_b}{C^S_p}\end{bmatrix}}_\mathbf{A} \underbrace{\begin{bmatrix} T_{H,1} - T_{amb} \\ T_{S,1} - T_{amb} \end{bmatrix}}_\mathbf{x} + \underbrace{\begin{bmatrix} \frac{\alpha P_1}{C^H_p} \\ 0 \end{bmatrix}}_\mathbf{B} \underbrace{\begin{bmatrix} u_1 \end{bmatrix}}_\mathbf{u} \\ \\ \underbrace{\begin{bmatrix} T_{S,1} - T_{amb} \end{bmatrix}}_\mathbf{y} & = \underbrace{\begin{bmatrix}0 & 1 \end{bmatrix}}_\mathbf{C} \underbrace{\begin{bmatrix} T_{H,1} - T_{amb} \\ T_{S,1} - T_{amb} \end{bmatrix}}_\mathbf{x} \end{align}

In other words, we can write the temperature control lab model as a state-space model

dxdt=Ax+Buy=Cx\begin{align} \frac{d\mathbf{x}}{dt} & = \mathbf{A} \mathbf{x} + \mathbf{B} \mathbf{u} \\ \mathbf{y} & = \mathbf{C} \mathbf{x} \end{align}

where the state space variables are the deviations of temperature from the ambient TambT_{amb}:

u=[u1]inputsx=[TH,1TambTS,1Tamb]statesy=[TS,1Tamb]measurements\begin{align} \mathbf{u} & = \begin{bmatrix} u_1 \end{bmatrix} && \text{inputs} \\ \\ \mathbf{x} & = \begin{bmatrix} T_{H,1} - T_{amb} \\ T_{S,1} - T_{amb} \end{bmatrix} && \text{states} \\ \\ \mathbf{y} & = \begin{bmatrix} T_{S,1} - T_{amb} \end{bmatrix} && \text{measurements} \\ \end{align}

and the parameters are embedded in the matrices:

A=[Ua+UbCpHUbCpHUbCpSUbCpS]B=[αP1CpH0]C=[01]\begin{align} \mathbf{A} = \begin{bmatrix} -\frac{U_a+U_b}{C^H_p} & \frac{U_b}{C^H_p} \\ \frac{U_b}{C^S_p} & - \frac{U_b}{C^S_p}\end{bmatrix} \quad \mathbf{B} = \begin{bmatrix} \frac{\alpha P_1}{C^H_p} \\ 0 \end{bmatrix} \quad \mathbf{C} = \begin{bmatrix}0 & 1 \end{bmatrix} \\ \end{align}