TCLab Simulate Step Response

Objective: Simulate temperature response and compare to data from the TCLab.

A simplified dynamic model of the Temperature Control Lab (TCLab) is the following:

$$\tau_p \frac{dT}{dt} = \left(T_a-T\right) + K_p \, Q$$

With the temperature initially at ambient temperature (`T_a`), simulate the change in temperature over the 5 minutes when heater Q is adjusted to 50%. Use a values of `\tau`=120 sec, `K_p`=0.8oC/%, and `T_a`=23oC. Compare the simulated temperature response to data from the TCLab. Add a simulation prediction to the script below to compare with the TCLab data.

TCLab Step Response

Use the following code to generate a step response or use the TCLab Web Interface.

import numpy as np
import matplotlib.pyplot as plt
import tclab
import time

n = 300  # Number of second time points (5 min)
tm = np.linspace(0,n,n+1) # Time values

# data
lab = tclab.TCLab()
T1 = [lab.T1]
lab.Q1(50)
for i in range(n):
    time.sleep(1)
    print(lab.T1)
    T1.append(lab.T1)
lab.close()

# Plot results
plt.figure(1)
plt.plot(tm,T1,'r.',label='Measured')
plt.ylabel('Temperature (degC)')
plt.xlabel('Time (sec)')
plt.legend()
plt.show()

Solutions

import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
import tclab
import time

n = 300  # Number of second time points (5 min)
tm = np.linspace(0,n,n+1) # Time values

# data
lab = tclab.TCLab()
T1 = [lab.T1]
lab.Q1(50)
for i in range(n):
    time.sleep(1)
    print(lab.T1)
    T1.append(lab.T1)
lab.close()

# simulation
def labsim(TC,t):
    dTCdt = ((23-TC) + 0.8*50)/120.0
    return dTCdt
Tsim = odeint(labsim,23,tm)

# Plot results
plt.figure(1)
plt.plot(tm,Tsim,'b-',label='Simulated')
plt.plot(tm,T1,'r.',label='Measured')
plt.ylabel('Temperature (degC)')
plt.xlabel('Time (sec)')
plt.legend()
plt.show()

import numpy as np
import matplotlib.pyplot as plt
import tclab
import time
# pip install gekko
from gekko import GEKKO

n = 300  # Number of second time points (5 min)

# data
lab = tclab.TCLab()
T1 = [lab.T1]
lab.Q1(50)
for i in range(n):
    time.sleep(1)
    print(lab.T1)
    T1.append(lab.T1)
lab.close()

# simulation
m = GEKKO()
m.time = np.linspace(0,n,n+1)
TC = m.Var(23)
m.Equation(120*TC.dt()==(23-TC)+0.8*50)
m.options.IMODE = 4 # dynamic simulation
m.solve(disp=False)

# Plot results
plt.figure(1)
plt.plot(m.time,TC,'b-',label='Simulated')
plt.plot(m.time,T1,'r.',label='Measured')
plt.ylabel('Temperature (degC)')
plt.xlabel('Time (sec)')
plt.legend()
plt.show()

Generative AI Learning

Use these prompts to test your understanding after completing the exercise. Direct the AI - do not let it do the exercise for you.

"Quiz me with 4 questions, one at a time, about step testing a thermal system: why a step input reveals the process gain and time constant, what changes in the response if the heater step is doubled, why the measured temperature keeps rising after 5 minutes, and how a simulation differs from the physical device. Grade my answers and list my misconceptions."
"Here is my simulated vs measured TCLab step response: {describe or paste}. Critique it as a senior process engineer: is the mismatch from parameters, model structure, or the experiment? Suggest one specific next test and ask me to predict its outcome before revealing yours."

App: Run the step test in the browser with the TCLab Simulation Studio - record a run on the built-in simulator (or a connected device) and compare the model prediction to the measurement without writing code.

What to Turn In

Submit a short report (PDF, 1-2 pages) that curates your results into a demonstration of what you learned. You may use Generative AI to help write the report, but you must guide it to the correct visualizations, justifications, and assumptions. Answer these questions:

  1. Include your step-response plot (simulation vs TCLab data or app measurement). What are the starting temperature and the temperature after 5 minutes at 80% heater?
  2. Where do the simulation and measurement disagree most, and what physical effect does the model miss?
  3. From the quiz prompt: one question you missed and the corrected answer.
  4. One claim the AI made about your data that you verified or refuted, with evidence.

Course Information

Assignments

Projects

Exams

Dynamic Modeling

Equipment Design

Control Design

Optimal Control

Related Courses

Admin