The Nautilus playground: a PLC in a browser tab

VS Code, the Nautilus Runtime and a Lift Station in All Four IEC Languages, Running in One Browser Tab

Companion post for the playground video. The video covers the same ground on screen in about six and a half minutes: watch it here.

This is the Nautilus playground: VS Code with our Nautilus extension and the Nautilus runtime, running entirely in your browser. Try it at nautilus.joyautomation.com/playground.

The Nautilus playground: VS Code, the extension and the runtime in a browser tab

If you haven't seen Nautilus before, it's a soft PLC, similar to something like CODESYS, except it's open source, and instead of a proprietary IDE you program it in VS Code with our Nautilus extension, using ladder, function block, Structured Text or sequential function chart.

I wanted everyone to be able to get an idea of what working with Nautilus looks like, right on the Nautilus docs website, without having to set up VS Code and the runtime. Screenshots and videos help, but WebAssembly makes it possible to run Nautilus itself in a sandbox in the browser. So we compiled the runtime to WebAssembly first, and it became natural to keep building on top of that until the whole environment was in there.

Nautilus's HMI and diagnostics pages are built with Svelte, so we took some inspiration from the Svelte playground: you open a page, there's an example already running, you change it, and you can send it to somebody in a link. It's also nice when you're not at your own machine and just want to try something quickly. We've been talking to people who teach controls, and with the playground, a student can open a tab and have a whole Nautilus environment on whatever machine they're sitting in front of.

How a PLC runs in a browser tab

The Nautilus compiler and runtime are written in Go, and we build them to WebAssembly, which lets them run inside a web page. They run in a background worker in your browser: the compiler, the scan loop and the tag store. The website only sends static files: the WebAssembly, VS Code and the examples. Everything then runs locally in your browser.

On a real machine, the HMI gets its data from naut run, the Nautilus runtime, over HTTP. In the browser, a service worker serves the project's HMI, and requests still go to the same handler naut run uses, so the HMI works the same as it does with Nautilus on a real machine. When I switch a pump to Hand on the HMI, that write goes through the service worker to the program running in the tab, and the next scan handles it. If I close the playground tab, the HMI loses its controller.

The HMI and the handler, on a machine and in the tab

A lift station in all four languages

Most of my experience is in water and wastewater. I've programmed a lot of lift stations and sumps, so it seemed like a natural example to build: a sewer lift station with two pumps, using all four IEC languages.

Wastewater flows into a wet well, and two pumps lift it out. One pump leads, and if the level keeps rising, the other one comes on to help.

  • The sequencing is a sequential function chart, and you can see which step it's in right now.
  • The level control is a PID in function block diagram, with the live values right on the pins.
  • The permissives, hand-off-auto and which pump is lead are in ladder.
  • All the values that would be inputs from the real world are simulated in Structured Text.

Making it storm

Set the inflow to 950 gallons a minute, which is all the Storm button does, besides the rain and lightning. The level climbs past 60 percent and the lead pump starts, and when it keeps climbing past 80, the lag pump joins it. Open HMI opens the station's operator screen, running off the same program. At 950, even two pumps can't keep up, so the wet well fills and the high level alarm comes in. That's when somebody would get a phone call. And from the HMI, you can put a pump in Hand, the same way an operator would.

The lift station in a storm, in a browser tab

Both pumps running and the high level alarm in, on the station's HMI

Twenty tests in under a second

The example also includes one of my favourite features of Nautilus: tests. It has 20 of them, and they run in virtual time, so all 20 finish in well under a second. You don't wait for them in real time. Change the lead pump's call level from 60 to 70 and run them again, and half of them fail, because the first test sets the wet well level to 65 percent and expects the lead pump to start.

On a real project, you can run these tests in continuous integration on every commit, so you know it still works after every change, and you head into startup with plenty of confidence.

A sump pump from scratch

A simple sump pump controlled by two floats, in ladder: a new file and one rung. The high float starts the pump, and the pump keeps running until the water drops below the low float. Add the task and three tags in nautilus.yaml, then naut run. Water comes up past the high float and the pump starts. The high float drops, and it keeps pumping. The low float drops, and the pump stops.

The sump pump's rung: the high float starts it, the low float stops it

And we have to have a test. When both floats are underwater, the pump should run. When the high float drops, it should keep running. When the low float drops, it should stop. naut test, and it passes:

tests:
  - name: pump runs from the high float down to the low float
    given: { HighFloat: true, LowFloat: true }
    steps:
      - advance: 1s
        expect: { SumpPump: true }
      - given: { HighFloat: false }
        advance: 1s
        expect: { SumpPump: true }
      - given: { LowFloat: false }
        advance: 1s
        expect: { SumpPump: false }

Taking it with you

As soon as you change something, the playground keeps your copy in your browser, so it's still there the next time you open it. Share saves the project and copies a link, so you can send what you've built to someone; anyone with the link can open it. To take it out of the browser, Download project gives you the whole folder as a zip. Open in VS Code installs the Nautilus extension in VS Code on your computer, and Install Nautilus walks you through installing naut. Open the folder, naut run, and you're running the same project.

What it can't do

The playground can't do everything Nautilus can. WebAssembly runs in a sandbox, so it can't talk to things on the network directly: you can't connect to your remote I/O from a browser tab. In the playground the field drivers are simulated, and there's no retained memory. For real I/O, install Nautilus on your machine.

The browser's sandbox: no line out to remote I/O

Try it

You don't need to be shackled to hardware or a vendor IDE to program a PLC or an HMI. Open source tools are powerful and flexible, you can extend them, and there's a lot less friction when you're developing with AI tools.

The playground is at nautilus.joyautomation.com/playground. The Nautilus docs now have a Learn section too, and some of its lessons open next to the playground so you can check your answer as you go. It works best on a computer; on a phone you can open it anyway, or send yourself the link. I'd like to hear what examples you'd like to see in it, what features you'd want, or anything you'd like to work differently.

If you've got a project you'd like built this way, take a look at joyautomation.com/services.

Subscribe to the weekly newsletter to keep up to date: joyautomation.com/newsletter