# Trellis

# Trellis

Write a short program that runs your test on live channels. It reads sensors,
sets stop conditions and safety limits, and lays out a live page. Then you
**Deploy** it. If a limit trips, Phloem drives outputs safe on its own, within
milliseconds.

Two views: **Code** (the editor) and **Panel** (the live page it builds).

```python
setup("heater")

ch = channels()
ch.read("/demo/temperature", unit="degC", range={"min": 0, "max": 100},
        limits=limits(hihi=80), checks=True)
ch.write("/demo/heater_on", dtype="bool", safe=False)

interlock(
    name="overtemp",
    when=lambda: ch["/demo/temperature"] > 90,
    then=[set(ch["/demo/heater_on"], False)],
)

page("Heater test",
     layout=col(row(gauge(ch["/demo/temperature"]), toggle(ch["/demo/heater_on"])),
                row(alarms(), log())))
```

**Deploy** arms it. **Stop** (or Shift+Esc) drives every output to its safe value.
After a trip, press **Reset** to re-arm.

## Three kinds of document

The first statement sets the kind. The kind decides what the document can do.

| First statement | Kind | Can |
|---|---|---|
| `setup("name")` | **Setup**: your test setup. One is deployed at a time | declare channels, stop conditions, interlocks, safe values, procedures, the page |
| `recipe("name", setup="…", unit="…")` | **Recipe**: judges one unit, running on the deployed setup | steps, measurements, bounds. Never an interlock |
| none | **Notebook**: analysis on live data | compute and chart. It can never drive an output |

## Parts

- [Declare reads and writes](https://phloem.ai/docs/trellis/channels/): Read sensors, write commands
- [Stop conditions](https://phloem.ai/docs/trellis/checks/): Bounds that stop the test
- [Interlocks](https://phloem.ai/docs/trellis/interlocks/): Safety limits that act
- [Alerts](https://phloem.ai/docs/trellis/alerts/): Notify Slack, Teams or email
- [Procedures](https://phloem.ai/docs/trellis/sequences/): One-click test profiles
- [User page](https://phloem.ai/docs/trellis/page/): Gauges, controls, logs
- [Peers](https://phloem.ai/docs/trellis/peers/): Test across two machines
- [Acceptance recipes](https://phloem.ai/docs/trellis/recipes/): Judge a unit: steps, measurements, verdicts
- [Run your own scripts](https://phloem.ai/docs/trellis/scripts/): exec a script; it publishes, the recipe judges
- [Notebooks](https://phloem.ai/docs/trellis/notebook/): Work out a number on live data
