# IMPORT DATA FILES USED BY THIS NOTEBOOK
import os, requests
file_links = [("data/tclab-data.csv", "https://jckantor.github.io/CBE32338/data/tclab-data.csv")]
# This cell has been added by nbpages. Run this cell to download data files required for this notebook.
for filepath, fileurl in file_links:
stem, filename = os.path.split(filepath)
if stem:
if not os.path.exists(stem):
os.mkdir(stem)
if not os.path.isfile(filepath):
with open(filepath, 'wb') as f:
response = requests.get(fileurl)
f.write(response.content)
For this laboratory session you will collect data from a step test experiment, then fit the data to models derived from first-principles energy balances. Fitting models to data is an engineering skill that links between the real world of engineering systems to the theory you've been learning in the classroom.
Please work in groups of two.
Check out a TCLab kit. The kit consists of
Before going further, sign and date the equipment log sheet.
Download a copy of this notebook to your laptop, and complete the exercises shown below. Under each exercise heading, add as many text and code cells as needed to complete the exercise. The results should be embedded in the notebook. Be sure to 'save-as-you-go' to avoid losing your work.
Add any relevant notes to the equipment log and return the kit to equipment at the front of the lab. Return any malfunctioning kit to the instructor for repair.
Submit your completed lab notebook via Sakai. The notebook should contain the name of both lab partners. Both partners should submit a copy of the notebook.
Execute the following cell to verify that you have a working connection to the temperature control lab hardware. This will test for installation of TCLab.py, connection to the Arduino device, and working firmware within the Arduino.
from tclab import TCLab, clock, Historian, Plotter
lab = TCLab()
print("TCLab Temperatures:", lab.T1, lab.T2)
lab.close()
As discussed in class, for good model fitting it is essential for the TCLab hardware to be at steady state before proceeding with the step test. Run the following code to verify that the heaters are off and that the temperatures are at a steady ambient temperature.
# experimental parameters
tfinal = 30
# perform experiment
with TCLab() as lab:
h = Historian(lab.sources)
p = Plotter(h, tfinal)
for t in clock(tfinal):
p.update(t)
The step test consists of turning on one heater at 50% power and recording temperature data for at least 800 seconds. Copy and paste the code from Exercise 2 into the following cell, then modify as needed to accomplish the step test.
# experimental parameters
tfinal = 800
Q1 = 50
# perform experiment
with TCLab() as lab:
h = Historian(lab.sources)
p = Plotter(h, tfinal)
lab.Q1(Q1)
for t in clock(tfinal):
p.update(t)
Run the following cell to verify and save your data to a '.csv' file. Be sure you can find and locate the data on your laptop before leaving the lab. You will need access to this data for subsequent exercises.
%matplotlib inline
import matplotlib.pyplot as plt
t, T1, T2, Q1, Q2 = h.fields
plt.plot(t, T1, t, T2, t, Q1, t, Q2)
plt.legend(['T1','T2','Q1','Q2'])
plt.xlabel('Time / seconds')
plt.grid()
h.to_csv('tclab-data.csv')
1.) Approximating the the step test results for T1 as a first order transfer function, estimate the time constant and gain. Write your answer in the following cell.
A first order system transfer function is described by the differential equation
$$ \tau \frac{dy}{dt} + y = K u $$where $y$ is the deviation in process output and $u$ is the deviation in process input relative to a nominal condition. In this instance, the deviation variables are $u = Q_1$ and $y = T_1 - T_{amb}$. The process gain $K$ can be estimated from the steady state condition at the end of the step test.
$$K = \frac{y_{ss}}{u_{ss}} = \frac{54.75 - 23.81}{50} = 0.62$$The time constant $\tau$ can be estimated as the time required to achieve 63.2% of the final response. That value of $T_1$ can be computed as
$$23.81 + 0.632*(54.75-23.81) = 43.4$$This is about $\tau = 186$ seconds from the inspection of the data. These calculations are verified in the following code cell.
K = (T1[-1] - T1[0])/Q1[0]
print("Gain K = ", K, "degrees C per percent increase in Q1")
T = T1[0] + 0.632*(T1[-1] - T1[0])
print("63.2% of the final temperature rise corresponds to", T, "degrees C")
tau = t[min([k for k in range(0, len(T1)) if T < T1[k] ])]
print("tau =", tau, "seconds")
2.) As we discussed in class, a simple energy balance model for T1 is given by
$$C_p \frac{dT_1}{dt} = U_a(T_{amb} - T_1) + P Q_1$$where the parameter $P$ has, through independent means, been determined as 0.04 watts per percent increase in $Q_1$. Use the results of this experiment to estimate values for $C_p$ and $U_a$. Write your answers in the following cell.
P = 0.04
Ua = P/K
print("Heat transfer coefficient Ua =", Ua, "watts/degree C")
Cp = tau*P/K
print("Heat capacity =", Cp, "J/deg C")