# Introduction to control

Control makes a measurement follow a command. This page compares three ways to hold a block at 50 °C with a heater, from no feedback to proportional feedback.

[`Download this page as a notebook`](https://dev.nominal.io/learning/_downloads/c5df145d16107cb67fabd0f1e79fbee8/introduction-to-control.md) to run its code in JupyterLab. [Running the notebooks](https://dev.nominal.io/learning/guides/notebooks/running.md) explains how to set it up.

## Open loop and closed loop

An open-loop system sends a command and doesn’t check the result. A [closed loop](https://dev.nominal.io/learning/reference/glossary.md#closed-loop "Control that keeps adjusting a command from a measurement of the result, so the result holds at its setpoint.") measures the process variable, the quantity it controls, compares it with the [setpoint](https://dev.nominal.io/learning/reference/glossary.md#setpoint "The value a command asks for, such as a speed of 1,000 RPM."), and adjusts its output, over and over at a fixed rate.[[1]](https://dev.nominal.io/learning/guides/introduction-to-control.md#ni-pid) The difference between setpoint and measurement is the error. The three controllers below differ only in how they turn that error into heater power:

- **Open loop.** Sets a fixed power, the one that should hold 50 °C, and never looks at the temperature.
- **On/off.** Sets full power when the block is below the setpoint, and none when it’s above.
- **Proportional.** Sets a power proportional to the error, with a gain of 10 % per °C, limited to 0 to 100 %.

## A simulated heater

The block warms with the heater’s power and cools toward the room’s temperature, with a time constant of 8 s. Halfway through, at 20 s, the room cools from 20 °C to 10 °C. This is a made-up process for the simulation, not a measured one:

```ipython3
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from learning.style import set_matplotlib_style

set_matplotlib_style()
```

```ipython3
dt = 0.05  # s per control cycle
t = np.arange(0, 40, dt)
setpoint = 50.0  # °C

def simulate(controller):
    """Run the heater with a controller, and return the temperature and power of each cycle."""
    temperature = 20.0
    temps, powers = [], []
    for time in t:
        room = 20.0 if time < 20 else 10.0  # °C: the disturbance
        power = float(np.clip(controller(setpoint, temperature), 0, 100))  # %
        temperature += dt * (-(temperature - room) + 0.8 * power) / 8.0
        temps.append(temperature)
        powers.append(power)
    return np.array(temps), np.array(powers)

controllers = {
    "Open loop": lambda sp, measured: (
        37.5
    ),  # the power that holds 50 °C in a 20 °C room
    "On/off": lambda sp, measured: 100 if measured < sp else 0,
    "Proportional": lambda sp, measured: 10 * (sp - measured),
}
results = {name: simulate(c) for name, c in controllers.items()}

fig, ax = plt.subplots()
ax.axhline(setpoint, color="0.5", linestyle="--", label="Setpoint")
ax.axvline(20, color="0.7", linestyle=":")
for name, (temps, _) in results.items():
    ax.plot(t, temps, label=name)
ax.set_xlabel("Time (s)")
ax.set_ylabel("Block temperature (°C)")
ax.legend()
plt.show()

pd.DataFrame(
    {
        name: {
            "temperature at 40 s (°C)": temps[-1],
            "error at 40 s (°C)": setpoint - temps[-1],
            "switches between 0 and 100 % in the last 5 s": int(
                (np.abs(np.diff(powers[-int(5 / dt) :])) == 100).sum()
            ),
        }
        for name, (temps, powers) in results.items()
    }
).round(1)
```

![../../_images/856a593bd3045813036b56f269d1927c068de01d0e0af2221bbbadcab0a185b1.svg](https://dev.nominal.io/learning/_images/856a593bd3045813036b56f269d1927c068de01d0e0af2221bbbadcab0a185b1.svg)

|  | Open loop | On/off | Proportional |
| --- | --- | --- | --- |
| temperature at 40 s (°C) | 40.6 | 49.9 | 45.6 |
| error at 40 s (°C) | 9.4 | 0.1 | 4.4 |
| switches between 0 and 100 % in the last 5 s | 0.0 | 99.0 | 0.0 |

Each controller shows a different trade-off:

- Open loop is correct only while the room stays at the temperature it assumed. When the room cools, the block drifts away from 50 °C, and nothing corrects it.
- On/off holds the setpoint, but its output switches on and off over and over, as the table’s last row shows. A [deadband](https://dev.nominal.io/learning/reference/glossary.md#deadband "A band within which a change is ignored, so small fluctuations don't cause a reaction."), a range of error in which the output doesn’t change, reduces the switching.
- Proportional feedback follows the setpoint without chattering, but it settles short of it. A proportional controller’s output depends on the error, so it needs an error to produce any power. Raising the gain shrinks that offset, but too much gain makes the process variable oscillate.[[1]](https://dev.nominal.io/learning/guides/introduction-to-control.md#ni-pid)

The integral term removes the offset.[[1]](https://dev.nominal.io/learning/guides/introduction-to-control.md#ni-pid) [PID control](https://dev.nominal.io/learning/guides/pid-control.md) adds it, and the derivative term, to the same heater.

## In Nominal

To review a control loop, record its setpoint and process variable on the same time axis, and plot them together in a [workbook](https://dev.nominal.io/learning/reference/glossary.md#workbook "Where you analyze time-series data in Nominal, in tabs and panels, after a test or live."). This code writes both, and the controller’s output, to a dataset as the loop runs:

```python
from datetime import datetime, timezone

from nominal.core import NominalClient

client = NominalClient.from_profile("default")
dataset = client.get_dataset("<dataset RID>")

with dataset.get_write_stream() as stream:
    for _ in range(100):  # your control loop
        now = datetime.now(timezone.utc)
        stream.enqueue("heater.setpoint", now, setpoint)
        stream.enqueue("heater.temperature", now, read_temperature())
        stream.enqueue("heater.power", now, power)
```

`get_write_stream` queues each value and sends it in batches.[[2]](https://dev.nominal.io/learning/guides/introduction-to-control.md#nominal-client) A slow network can then slow the program that writes the data, so keep the writes out of a loop that has to keep time. [Network performance](https://dev.nominal.io/learning/guides/network-performance.md#example-streaming-to-nominal) explains why, and what to do instead.

## Further reading

- [Control](https://dev.nominal.io/learning/guides/control.md), on PID tuning, step responses and loop rates, with a dynamometer as the worked example.
- K. J. Åström and R. M. Murray, [Feedback Systems: An Introduction for Scientists and Engineers](https://fbswiki.org/wiki/index.php/Main_Page), a free textbook.
- NI, [The PID Controller & Theory Explained](https://www.ni.com/en/shop/labview/pid-theory-explained.html).

## References

---

[1]
([1](https://dev.nominal.io/learning/guides/introduction-to-control.md#id1),[2](https://dev.nominal.io/learning/guides/introduction-to-control.md#id2),[3](https://dev.nominal.io/learning/guides/introduction-to-control.md#id3))

NI, [“The PID Controller & Theory Explained”](https://www.ni.com/en/shop/labview/pid-theory-explained.html), updated 2025-03-07. Retrieved 2026-11-12.

[[2](https://dev.nominal.io/learning/guides/introduction-to-control.md#id4)]

Nominal, `Dataset.get_write_stream` in the [nominal](https://pypi.org/project/nominal/) Python client, version 1.186.0. Retrieved 2026-11-30.
