The primary resource for TCLab can be found at apmonitor.com.
Developed by John Hedengren at the Brigham Young University (USA).
In subsequent sections, we’ll explore the complexities of dynamic modeling, understanding system responses, and the implementation of various control strategies.
Our approach will involve utilizing Python programming to engage with the TCLab hardware, conduct data analysis, and effectively visualize the behaviors of the system.
What is TCLab?
TCLab is a compact laboratory setup that includes an Arduino microcontroller, heaters, temperature sensors, and an LED. It is designed for learning and applying control engineering principles in a hands-on manner.
The Temperature Control Laboratory hardware consists of five components:
Arduino Microcontroller (Arduino Uno, Arduino Leonardo, or equivalents): Acts as the brain of the setup.
The Temperature Control Laboratory plug-in board (also known as a shield). Includes:
Heaters: Provide thermal energy to the system.
Temperature Sensors: Measure the system’s temperature.
LED: Visual indicator for certain actions or states.
Five watt USB power supply.
5.5mm to USB power supply cable.
USB 2.0 data cable. (w/mini-USB connector for Arduino Uno, or micro-USB cable for Arduino Leonardo.)
Before going further, be sure to complete the steps outlined under Hardware setup as described in TCLab README.
Mac OS users may need to install a serial driver available here.
Normally the TCLab shield will already be mounted on the Arduino board, and the firmware driver will have been loaded on to the Arduino.
Understanding the TCLab Kit
The Core Components of TCLab
The Temperature Control Lab (TCLab) is an integrated system composed of several key components, each contributing significantly to its functionality:
Arduino Microcontroller:
Purpose: Serves as the central processing unit for the TCLab.
Functionality: Processes input data from temperature sensors and manages the operation of heaters.
Connectivity: Utilizes a USB connection for data transfer and allows for real-time control through Python scripts.
Heaters:
Description: TCLab features two heaters, each capable of generating adjustable thermal energy.
Role: Act as the main heat sources for experiments, replicating scenarios requiring temperature regulation. They function as the system’s actuators.
Temperature Sensors:
Type: These sensors are thermistors, a kind of resistor whose resistance varies with temperature changes.
Measurement Range: Capable of measuring temperatures ranging from \(-40^\circ\)C to \(150^\circ\)C.
Functionality: Positioned near each heater to accurately measure temperature, providing essential feedback for temperature control.
Heat Sinks:
Type: Comprised of transistor heat sinks.
Purpose: Employed to efficiently dissipate heat away from the transistors.
LED (Light Emitting Diode):
Purpose: Serves as a visual indicator for various states or actions, such as signaling the activation of a heater.
Operational Configurations of TCLab
TCLab can be configured in various modes depending on the educational objectives:
Single Input Single Output (SISO):
Utilizes only one heater and one sensor. Ideal for simple control experiments and learning the basics of temperature control.
Single Input Single Output (SISO) with Disturbance:
Employs one heater/sensor as the primary control system and the second heater as a source of external disturbance. This setup is useful for understanding how external factors influence control systems.
Multiple Inputs Multiple Outputs (MIMO):
Involves using both heaters and sensors simultaneously. This more advanced configuration isn’t covered here but is valuable for complex control system studies.
Each component of the TCLab plays a specific role, making it a versatile tool for teaching and experimenting with various aspects of control engineering. Whether for fundamental learning or advanced exploration, TCLab offers a practical platform for understanding the dynamics and control of temperature-based systems.
How TCLab Works
Operation Flow:
Input Signal: A Python script sends a command to the Arduino, setting the desired power level for the heaters.
Heating Action: The heaters generate heat corresponding to the received power level commands.
Temperature Measurement: The thermistors measure the resulting temperatures near the heaters.
Feedback Loop: These temperature readings are sent back to the computer.
Adjustments: The control algorithm in the Python script adjusts the heater power based on the temperature feedback, striving to reach and maintain a target temperature.
Section 2: In-Depth Look at TCLab Components
2.1 Arduino Microcontroller
Detailed Description: Provide specifics about the Arduino model used in TCLab, its capabilities, and its limitations
Ojectives:
Dynamic modeling with balance equations
The difference between manual and automatic control
Step tests to generate dynamic data
Fitting dynamic data to a First Order Plus Dead Time (FOPDT) model
Obtaining parameters for PID control from standard tuning rules
Tuning the PID controller to improve performance
Setting Up TCLab
This guide provides step-by-step instructions for setting up the Temperature Control Lab (TCLab), starting from installing Python on different operating systems to conducting initial tests with TCLab and its simulator.
Create the environment from the tclab_environment.yml file:
conda env create -f tclab_environment.yml
Activate the new environment:
conda activate tclab
To verify that the environment was installed correctly, you can use:
conda env list
Installing the TCLab Package
Activating the Environment:
Ensure your Anaconda environment is active. Open your Terminal (or Anaconda Prompt on Windows) and activate your environment:
conda activate tclab_env
Installing TCLab:
The tclab library is pivotal for interfacing with the Temperature Control Lab hardware. Install it by entering the following command:
pip install tclab
Press Enter to execute the command and complete the installation.
Installing Additional Useful Libraries
For a comprehensive experience with TCLab and to support various aspects of control engineering and data analysis, the following libraries will also be installed:
numpy:
Significance: A fundamental library for numerical computations in Python.
Installation Command:
pip install numpy
matplotlib:
Significance: Crucial for creating visual representations of data, especially for the analysis of TCLab experiments.
Installation Command:
pip install matplotlib
scipy:
Significance: Provides a broad range of tools for scientific computing, including methods for solving ordinary differential equations, useful in system modeling.
Installation Command:
pip install scipy
pandas:
Significance: Offers extensive features for data manipulation and analysis, ideal for handling complex datasets.
Installation Command:
pip install pandas
gekko:
Significance: Advanced package for optimization and control, suitable for implementing model predictive control strategies.
Installation Command:
pip install gekko
TCLab Schematics
Initial Tests with TCLab
Step 1: Connect TCLab
Connect TCLab: Plug in the TCLab device to your computer using a USB cable.
Step 2: Test TCLab Connection
Write Test Script:
Open your Python IDE or Jupyter Notebook.
Write the following Python code and run the script. If it prints the temperature, TCLab is connected properly.
import tclabwith tclab.TCLab() as lab:print(f"Connected! Heater 1 is at {lab.T1}°C")
TCLab version 1.0.0
Arduino Leonardo connected on port /dev/cu.usbmodem142101 at 115200 baud.
TCLab Firmware 3.0.0 Arduino Leonardo/Micro.
Connected! Heater 1 is at 23.477°C
TCLab disconnected successfully.
Using TCLab Simulator
Why Use a Simulator: The TCLab simulator is useful when you don’t have the physical hardware available.
Install Simulator: In Terminal or Anaconda Prompt, type pip install tclab again (it includes the simulator).
Test Script with Simulator:
from tclab import setup, clockTCLab = setup(connected=False, speedup=5)with TCLab() as lab:for t in clock(200, 2):print(f"Time {t} seconds. T1: {lab.T1}°C")
TCLab version 1.0.0
Simulated TCLab
Time 0 seconds. T1: 20.949499999999997°C
Time 2.01 seconds. T1: 20.949499999999997°C
Time 4.04 seconds. T1: 20.949499999999997°C
Time 6.03 seconds. T1: 20.949499999999997°C
Time 8.06 seconds. T1: 20.949499999999997°C
Time 10.07 seconds. T1: 20.949499999999997°C
Time 12.02 seconds. T1: 20.949499999999997°C
Time 14.03 seconds. T1: 20.949499999999997°C
Time 16.15 seconds. T1: 20.949499999999997°C
Time 18.04 seconds. T1: 20.949499999999997°C
Time 20.2 seconds. T1: 20.949499999999997°C
Time 22.01 seconds. T1: 20.949499999999997°C
Time 24.19 seconds. T1: 20.949499999999997°C
Time 26.24 seconds. T1: 20.949499999999997°C
Time 28.16 seconds. T1: 20.949499999999997°C
Time 30.03 seconds. T1: 20.949499999999997°C
Time 32.12 seconds. T1: 20.949499999999997°C
Time 34.2 seconds. T1: 20.6272°C
Time 36.04 seconds. T1: 20.949499999999997°C
Time 38.02 seconds. T1: 20.6272°C
Time 40.21 seconds. T1: 20.949499999999997°C
Time 42.14 seconds. T1: 20.949499999999997°C
Time 44.01 seconds. T1: 20.6272°C
Time 46.3 seconds. T1: 20.949499999999997°C
Time 48.22 seconds. T1: 20.949499999999997°C
Time 50.07 seconds. T1: 20.949499999999997°C
Time 52.27 seconds. T1: 20.949499999999997°C
Time 54.09 seconds. T1: 20.949499999999997°C
Time 56.28 seconds. T1: 20.949499999999997°C
Time 58.19 seconds. T1: 20.949499999999997°C
Time 60.04 seconds. T1: 20.949499999999997°C
Time 62.2 seconds. T1: 20.949499999999997°C
Time 64.11 seconds. T1: 20.949499999999997°C
Time 66.08 seconds. T1: 20.949499999999997°C
Time 68.23 seconds. T1: 20.6272°C
Time 70.13 seconds. T1: 20.949499999999997°C
Time 72.07 seconds. T1: 20.949499999999997°C
Time 74.05 seconds. T1: 20.949499999999997°C
Time 76.1 seconds. T1: 20.6272°C
Time 78.1 seconds. T1: 20.6272°C
Time 80.22 seconds. T1: 20.949499999999997°C
Time 82.28 seconds. T1: 20.949499999999997°C
Time 84.22 seconds. T1: 20.949499999999997°C
Time 86.16 seconds. T1: 20.949499999999997°C
Time 88.23 seconds. T1: 20.949499999999997°C
Time 90.0 seconds. T1: 20.949499999999997°C
Time 92.27 seconds. T1: 20.949499999999997°C
Time 94.0 seconds. T1: 20.949499999999997°C
Time 96.16 seconds. T1: 20.949499999999997°C
Time 98.02 seconds. T1: 20.949499999999997°C
Time 100.1 seconds. T1: 20.949499999999997°C
Time 102.24 seconds. T1: 20.949499999999997°C
Time 104.0 seconds. T1: 20.6272°C
Time 106.18 seconds. T1: 20.949499999999997°C
Time 108.27 seconds. T1: 20.949499999999997°C
Time 110.27 seconds. T1: 20.949499999999997°C
Time 112.1 seconds. T1: 20.949499999999997°C
Time 114.22 seconds. T1: 20.949499999999997°C
Time 116.24 seconds. T1: 20.949499999999997°C
Time 118.18 seconds. T1: 20.949499999999997°C
Time 120.19 seconds. T1: 20.949499999999997°C
Time 122.06 seconds. T1: 20.949499999999997°C
Time 124.22 seconds. T1: 20.6272°C
Time 126.19 seconds. T1: 20.949499999999997°C
Time 128.18 seconds. T1: 20.949499999999997°C
Time 130.25 seconds. T1: 20.949499999999997°C
Time 132.02 seconds. T1: 20.6272°C
Time 134.2 seconds. T1: 20.949499999999997°C
Time 136.27 seconds. T1: 20.949499999999997°C
Time 138.01 seconds. T1: 20.6272°C
Time 140.2 seconds. T1: 20.949499999999997°C
Time 142.18 seconds. T1: 20.949499999999997°C
Time 144.2 seconds. T1: 20.949499999999997°C
Time 146.23 seconds. T1: 20.949499999999997°C
Time 148.24 seconds. T1: 20.949499999999997°C
Time 150.19 seconds. T1: 20.949499999999997°C
Time 152.28 seconds. T1: 20.949499999999997°C
Time 154.25 seconds. T1: 20.949499999999997°C
Time 156.23 seconds. T1: 20.6272°C
Time 158.04 seconds. T1: 20.949499999999997°C
Time 160.11 seconds. T1: 20.949499999999997°C
Time 162.04 seconds. T1: 20.949499999999997°C
Time 164.05 seconds. T1: 20.949499999999997°C
Time 166.01 seconds. T1: 20.949499999999997°C
Time 168.23 seconds. T1: 20.6272°C
Time 170.08 seconds. T1: 20.949499999999997°C
Time 172.01 seconds. T1: 20.949499999999997°C
Time 174.14 seconds. T1: 20.949499999999997°C
Time 176.01 seconds. T1: 20.949499999999997°C
Time 178.22 seconds. T1: 20.949499999999997°C
Time 180.2 seconds. T1: 20.949499999999997°C
Time 182.2 seconds. T1: 20.949499999999997°C
Time 184.21 seconds. T1: 20.949499999999997°C
Time 186.08 seconds. T1: 20.949499999999997°C
Time 188.29 seconds. T1: 20.949499999999997°C
Time 190.24 seconds. T1: 20.949499999999997°C
Time 192.18 seconds. T1: 20.949499999999997°C
Time 194.09 seconds. T1: 20.949499999999997°C
Time 196.22 seconds. T1: 20.949499999999997°C
Time 198.26 seconds. T1: 20.949499999999997°C
Time 200.02 seconds. T1: 20.6272°C
TCLab Model disconnected successfully.