Batch sequences you can diff: the Nautilus SFC editor
Sequential Function Chart (SFC) in VS Code
All posts · Nautilus ·
Companion post for the week-5 video. The editor tour covers the same ground on screen: watch it here.
This is the last of the four IEC 61131-3 languages in Nautilus: sequential function chart. Programs in structured text, function block diagram and ladder calculate values every scan. SFC is for sequencing, which makes it the language most batch logic is written in.
The example is a batch tank, examples/tank-batch-sfc as of the v0.10.0 release. It fills the tank, heats and mixes at the same time, drains, and counts the batch, with an abort branch off the fill step. It runs its own controller against a small simulated plant, so the whole thing cycles on a laptop.
A sequence in a text file
The program is program.sfc, and it's plain text using the standard's own keywords. Each step lists what the batch does while it's active:
STEP Fill:
N RunLamp;
N FillValve; (* valve open while Fill active *)
END_STEP
STEP Heat:
N RunLamp;
N HeatCtrl; (* ACTION block, below — a real thermostat *)
END_STEP
STEP Mix:
N RunLamp;
N Stir; (* ACTION block, below *)
END_STEP
Each transition sets the condition for moving to the next step:
TRANSITION t_abort FROM Fill TO Aborted := Abort;
END_TRANSITION
TRANSITION t_full FROM Fill TO (Heat, Mix) := Level >= FillSP; (* simultaneous divergence *)
END_TRANSITION
TRANSITION t_done FROM (Heat, Mix) TO Drain := (TempC >= HeatSP) AND mixT.Q;
END_TRANSITION
With the controller running, the live values show on the tags right in the text, the same as the other three languages.
The batch at a glance
nautilus: Open SFC Diagram Preview opens the same file as a chart. The double line under Fill is a simultaneous divergence: when the level reaches its setpoint, Heat and Mix both go active. The double line below them is the convergence, and that transition only fires when both branches are active and the temperature and mix timer are both done.
Off to the left is the abort branch. Fill has two ways out, and if both conditions are true on the same scan, abort wins. That priority is the declaration order in the file: t_abort is written before t_full. There's no priority number in a dialog to go looking for.
Steps, transitions, actions
The letter in front of each action is its qualifier:
Nruns while the step is active. The fill valve is open only while Fill is active, and there's no separate code to close it.P1runs once, on the scan the step activates. That'sCountBatchon Drain, the batch counter.SandRset and reset. Aborted sets the abort lamp, and it stays on until Idle resets it.
The underlined names, HeatCtrl, Stir and CountBatch, are ST action blocks written further down in the same file. Stir runs the mixer and its three-second timer:
ACTION Stir:
Mixer := Mix.X; (* track the step: drops to FALSE on the final scan *)
mixT(IN := Mix.X, PT := T#3S); (* mixing timer; falling edge resets it *)
END_ACTION
Watching it run
With the controller running, the chart highlights the active step live, from the same stream every other editor in Nautilus uses. Fill goes active and the valve opens. At eighty percent, both branches light up, the heater runs to temperature and the mixer runs its timer. When both are done the batch drains, the count goes up by one, and it starts over. The example runs a batch about every eight and a half seconds.
Change it, review it
The chart is an editor, and every gesture on it is an edit to the text. To add a sampling step that runs alongside heating and mixing, select the level transition, click + parallel branch and name it Sample. A third leg appears on the chart. In the text beside it, there's a new step, and both the divergence and the convergence now list three branches, so the batch can't drain until all three are active.
Here is the whole change in git, with the unchanged lines around each edit left out:
+ STEP Sample:
+ END_STEP
+
- TRANSITION t_full FROM Fill TO (Heat, Mix) := Level >= FillSP; (* simultaneous divergence *)
+ TRANSITION t_full FROM Fill TO (Heat, Mix, Sample) := Level >= FillSP; (* simultaneous divergence *)
- TRANSITION t_done FROM (Heat, Mix) TO Drain := (TempC >= HeatSP) AND mixT.Q;
+ TRANSITION t_done FROM (Heat, Mix, Sample) TO Drain := (TempC >= HeatSP) AND mixT.Q;
Sample has no actions yet; those are the next edit. A new step and two edited lines is a change a colleague can review in a pull request like any other code.
A reviewer who would rather see the chart can run nautilus: Diff SFC Diagram (vs git HEAD), which draws the working tree against the last commit, with the new step in green and the transitions that changed in blue.
What's next
That's all four IEC languages. Next week is the P&ID editor, with live values in VS Code.
Nautilus is open source, Apache-2.0. If you'd like help with your own plant, start with a Control System Assessment: a fixed-price review that ends in a written report you keep either way.
SFC docs: nautilus.joyautomation.com/languages/sfc · Repo: github.com/joyautomation/nautilus
Subscribe to the weekly newsletter to keep up to date: joyautomation.com/newsletter