Four languages, one controller
IEC 61131-3 has four programming languages, and nautilus runs all of them
in one controller. This lesson shows the same small job in three of them, so
you can see what each is for, and how to mix them. About ten minutes. You need
naut (install).
The same job, three ways
Section titled “The same job, three ways”naut new can start a project in any of the four languages:
naut new p-st --template minimal --language stnaut new p-fbd --template minimal --language fbdnaut new p-sfc --template minimal --language sfcnaut new p-ld --template minimal --language ldEach is a complete project, and each passes naut check and naut test.
The first three do the same thing: the actuator follows how far the sensor
is below the setpoint, clamped to 0 to 100.
Structured Text is text, like a programming language:
PROGRAM PStVAR err : REAL;END_VAR
err := Setpoint - Sensor;Actuator := LIMIT(0.0, err, 100.0);END_PROGRAMFunction block diagram is wires and blocks, written as a netlist: each
line is a wire (name = expression) or a coil that writes a tag
(name := expression):
FBD w_err = SUB(Setpoint, Sensor) Actuator := LIMIT(0.0, w_err, 100.0)END_FBDSequential function chart is steps with actions. This starter has one step that is always active:
SFC
INITIAL_STEP Track: N UpdateActuator; END_STEP
ACTION UpdateActuator: Actuator := LIMIT(0.0, Setpoint - Sensor, 100.0); END_ACTION
END_SFCSteps are where an SFC earns its keep: a sequence (fill, heat, hold, drain) is a chart of steps, and a transition between two steps is the condition that moves on.
Ladder (--language ld) is for interlocks. Its starter raises an alarm
when the sensor passes the setpoint:
LD RUNG high (* alarm when the sensor exceeds the setpoint *) GT(Sensor, Setpoint) ( Alarm )END_LDCheck the four: naut check in each folder should say 0 with errors, and
naut test two passing tests.
Which one to use
Section titled “Which one to use”| Logic | Language | Why |
|---|---|---|
| Interlocks, permissives, latches, annunciators | Ladder | reads as the relay logic it replaces |
| Loops, signal conditioning, continuous control | Function block diagram | data flows between blocks |
| Math, arrays, structs, anything algorithmic | Structured Text | the full language; the others lower to it |
| Batch sequences, startup and shutdown | Sequential function chart | steps and transitions are the spec |
Mix them in one project
Section titled “Mix them in one project”You choose a language per task, and a controller can have several tasks. The
default project from naut new runs three:
tasks: - program: program.fbd # the control loop: pump seal-in + heater PI scan: 100ms - name: sim # the plant, simulated in IEC program: sim.st scan: 100ms - name: interlocks # the annunciator, in ladder program: interlocks.ld scan: 200msThe control loop is a function block diagram, the simulated plant is
structured text and the alarms are ladder, all against one set of tags. Nothing
about a tag, a test or a screen depends on which language wrote the logic.
(Run naut new plant to get this project; two tasks, two scan
rates explains the tasks:
list.)
See the diagrams
Section titled “See the diagrams”The graphical languages are text first. With the VS Code extension, right-click
a .ld, .fbd or .sfc file and choose Open With, then the ladder, FBD
or SFC diagram: every change you make there is an edit to the text, so it
shows in git diff as a few readable lines.
Each language has its own page: Structured Text, Ladder, Function Block Diagram and Sequential Function Chart. Four languages, one program model is the overview, and the Studio 5000 map is the way in from Logix ladder.
nautilus is free and open source (Apache 2.0), built by Joy Automation. For implementation or support on your site, see Joy Automation services. Privacy.