Control in Practice: Labs with Real Data

Overview

The seven labs in this group take the course tools off the whiteboard. Each one starts from a logged experiment on a real kind of machine and carries it through the whole toolchain: a physical model, a transfer function identified from data, a root-locus or Bode design, a PID, lead or lag controller that has to cope with saturation, noise, quantization and delay, and a Nyquist or margin check of how robust the result is. Every lab has worked demos for class, a 100-point homework on a different unit or test than the demos, and a starter script.

Lab 04 uses a measurement that each student makes with a phone. The other logs are simulated from physical models with realistic sensor noise, resolution, delays and actuator limits, and each data file states that it is simulated.

Each lab page below shows the system, the overview, and the class demos. The key design steps of the demos can be run on the page: a button loads Python (Pyodide, with numpy, scipy, matplotlib and python-control) into the browser, and every change of a design parameter re-runs the original lab code and redraws the figures. The full homework sheets, the data and the starter scripts are in the lab materials on GitHub, github.com/xchen-me/control-in-practice, which can be cloned or downloaded as a zip file; the pages list the homework problems only.

Updated November 25, 2026: the demos, the lab pages and the homework sheets were checked against each other and corrected where they disagreed (commit 07d40d2). The changes that move numbers are in Lab 01 (the demo 3 PID gains), Lab 02 (0.8 s of engine lag and delay), Lab 03 (the 1 ms loop delay is now counted once), Lab 04 (one settling threshold in both demos) and Lab 07 (the settled peak-filter response). If you downloaded the materials before this date, download the zip file again or run git pull.

Which lectures each lab uses

The table marks the lectures whose tools each lab applies. The lecture numbers link to the lecture pages.

Lab \ lecture234567891011121314151617181920212223242526
01 Temperature control of a heater board●●●●●●●●●●●●●●●●●
02 Vehicle cruise control●●●●●●●●●●●●
03 DC gearmotor position control●●●●●●●●●●●
04 A phone pendulum, measured by you●●●●
05 Two-wheeled balancing robot●●●●●●●●●●●●●
06 Belt-driven stage with a resonance●●●●●●●
07 Hard disk drive track following●●●●●●●

The labs

Scene figure of Lab 01 Lab 01: Temperature control of a heater-and-sensor board A transistor heats a small aluminium fin and a thermistor measures its temperature, in the style of the open TCLab kit. The lab identifies a first-order-plus-dead-time model from a heater step, shows why proportional control leaves an error, designs a PI controller on the root locus, runs it with a saturating heater, and uses Bode and Nyquist plots to show how the dead time limits the phase margin and the bandwidth. Lectures 6-7, 12-19, 20-26 Scene figure of Lab 02 Lab 02: Vehicle cruise control A car at highway speed is a mass pushed by the engine against aerodynamic drag, rolling resistance and gravity on grades. The model is built from physics and identified from a logged throttle step; a hill is treated as a disturbance, the PI zero is placed on the root locus, a lag compensator is compared with PI, and a steep hill saturates the throttle and winds up the integrator. Lectures 2-3, 6-7, 12-19 Scene figure of Lab 03 Lab 03: DC gearmotor position control with an encoder A brushed DC gearmotor turns an arm; a quadrature encoder is read at 1 kHz and the PWM stage applies at most 12 V. The lab goes from the physics to the dominant-pole model K/(s(τs+1)), identifies K and τ from a logged voltage step, and designs the position loop on the root locus with P, PD, lead and lag/PI control, all tested with saturation, delay and encoder quantization. Lectures 3, 7-9, 12-18 Scene figure of Lab 04 Lab 04: A phone pendulum, measured by you Students hang a phone on a string, release it, and record its gyroscope with the free phyphox app. The free decay is a lightly damped second-order system: the damping ratio and natural frequency follow from the logarithmic decrement and a second-order fit, and the recording shows where the linear model stops being accurate. Lectures 6-8, 16 Scene figure of Lab 05 Lab 05: Two-wheeled balancing robot (pitch loop) Near upright the pitch dynamics of a balancing robot are an inverted pendulum with one right-half-plane pole. P control cannot stabilize it, the Nyquist plot must encircle −1 once counter-clockwise, the gain margin becomes a range, and the phase margin sets the largest loop delay the firmware may have. The logs include a robot that tips over after a firmware change added delay. Lectures 3, 10-11, 13-17, 22-26 Scene figure of Lab 06 Lab 06: Belt-driven linear stage with a resonance A servo motor moves a carriage through a timing belt. The elastic belt adds a lightly damped resonance in the tens of hertz, and that resonance, together with the drive delay, limits the position-loop bandwidth. The lab measures the frequency response, fits a model, designs a lead compensator on the low-order model, and judges it by its gain margin and sensitivity peak on the measured response. Lectures 20-26 Scene figure of Lab 07 Lab 07: Hard disk drive track following A voice-coil motor swings the actuator arm so that the head follows a track 60 nm wide, sampled once per servo sector. The lab identifies the delay, the rigid-body gain and the arm and suspension modes from a measured frequency response, designs a lead and integral controller with a notch for the butterfly mode, checks it on the measured response, and uses the sensitivity function to explain and predict the position error signal with its repeatable and non-repeatable runout. Lectures 12, 18, 20-22, 24, 26

Running the lab materials

The demos are plain Python files in notebook-cell format, and they share a small library, ctrlprac, for identification (fit_fopdt, fit_second_order_step, log_decrement, etfe, fit_tf), for simulating a sampled-data loop with saturation, noise, quantization and delay (PID, LTIController, simulate_loop), and for loading the logs. The materials are in the GitHub repository github.com/xchen-me/control-in-practice. Clone it with git clone https://github.com/xchen-me/control-in-practice.git, or download it as a zip file, which unpacks into a folder named control-in-practice-main. Put the folder on a local disk, not inside Google Drive, OneDrive or iCloud. All commands below are typed in a terminal (macOS: Terminal; Windows: PowerShell); cd control-in-practice* enters the folder under either name.

Option 1: JupyterLab in Docker (recommended). Docker gives everyone the same environment. Install Docker Desktop and start it, then run

cd control-in-practice*
docker compose up --build        # the first time builds the image (a few minutes); afterwards: docker compose up

When the terminal shows a line with http://127.0.0.1:8888/lab, open http://localhost:8888 in your browser. In the file browser on the left, open notebooks/ and the folder of your lab (for example 02_cruise/), and double-click a demo notebook. Run its cells in order with Shift+Enter; the figures appear under the cells. Your changes are saved in the folder on your disk. To stop, press Ctrl+C in the terminal and run docker compose down. To run all demos and the homework starter of one lab without the browser, for example Lab 02:

docker compose run --rm lab python run_all.py 02_    # numbers in the terminal, figures in out/

Option 2: Python on your own computer. You need Python 3.11 or newer. Set up an environment once:

cd control-in-practice*
python -m venv .venv
source .venv/bin/activate        # Windows PowerShell: .venv\Scripts\Activate.ps1
python -m pip install -r requirements.txt

Then, in every new terminal:

cd control-in-practice*
source .venv/bin/activate        # Windows PowerShell: .venv\Scripts\Activate.ps1
export PYTHONPATH=$PWD           # Windows PowerShell: $env:PYTHONPATH = $PWD
python labs/02_cruise/demo_1_model_ident.py    # one demo; each figure opens in a window, close it to continue
python run_all.py 02_            # all demos and hw_starter.py of Lab 02, figures saved in out/
jupyter lab                      # the notebooks in your browser, as in Option 1

The README of each lab folder ends with a “How to run” section that lists its notebooks and the commands for that lab. For a homework, write your solution either in labs/<lab>/hw_starter.py or in notebooks/<lab>/hw_starter.ipynb, and submit the file you worked in.

The interactive versions on these pages run the same ctrlprac code and the same lab helper files in the browser. The figures they draw are recomputed each time, so they can differ from the class figures in layout but not in the numbers for the same parameters.