Objective and state of the art

As part of OSIE project (Open Source Industrial Edge) we needed a way to implement an industrial line which we could control using entirely open source technologies. In a pure automation world this is usually done using PLC (Programmable Logic Controller) units. Nexedi, being a software company is still far away from the automation world, but one of our OSIE partners (Olimex) was already producing boards that could work together and control electrical circuits. All we needed was to provide an abstract layer of technology so that any automation engineer could use the already existing PLC languages of his choice (ST, Ladder Logic, etc).
Luckily of us Beremiz was already around and it could provide us the PLC control we needed. Thus all we had to do was to hook all together - which is what this article is all about.

Initial coupler prototype

Below the first design of the coupler as it was created by Nexedi.

This coupler consists of the A20-OLinuXino-LIME2 (top) and MOD-IO (bottom) board which are connected over UEXT cable.

The coupler (A20-OLinuXino-LIME2 board) has following characteristics:

  1. Running Debian Buster Linux (soon with PREEMPT-RT patch)
  2. Allwinner A20/T2 dual core Cortex-A7 processor, each core typically running at 1GHz and dual-core Mali 400 GPU
  3. 1GB of RAM
  4. 1000MBit native Ethernet

The coupler (MOD-IO) has following characteristics:

  1. Support for I2C protocol
  2. stackable design (so that multiple boards can be connected to one A20-OLinuXino-LIME2 providing multiple relays)
  3. Digital and analog input / output channels

And both boards are completely open source (incl. schematics).

Architecture

Our design had to meet several criteria from the start:

  • all components should be open-source
  • we should keep existing industry standard like IEC 61131-3
  • we should start with Modbus as a communication protocol but later switch to OPC-UA
  • We should aim to have a PLC runtime running on an x86_64 architecture and controlling our "dumb" coupler over Modbus. Still if for reasons needed we should also allow runtime to run on MCUs.
  • We should use TSN (runtime communicating a with the coupler)
  • We should NOT invent yet another ladder logic alike programming language but instead provide an IDE for development which automation engineers already are familiar with
  • We should be able to have a component base IDE (pure editor, runtime and coupler) working as a stand-alone unit which we can distribute easy in an abstract software-like fashion

After initially trying with ProviewR we discovered that it is a monolithic product which is quite hard to break into stand-alone components. We continued our search and we found Beremiz

First Goal defined: build a Modbus server at coupler which allows to control relays

Right from the beginning we knew that we need to expose a Modbus interface to the MOD-IO's relays which we wanted to control. Luckily for us using pymodbus and pyA20Lime2 we could provide a Modbus server running on the coupler fairly easy. Still, as a PLC has a deterministic nature where each cycle has a fixed execution interval and where the runtime needs to acquire Modbus status variables over the network from the coupler's Modbus server, we quickly discovered that both network latency and modbus's server implementation overhead can add sometimes significant lags to PLC's program execution - in some cases this leads to Modbus read requests timeouts after more than 30 ms. This finding quickly showed us that we need to spend time to work on improving TSN support for lime2 and improve (if possible) modbus python implementation. For a quick overview of our TSN efforts one can read our report here.

Second goal defined: Write a "Hello World" program 

Once we had a Modbus server exposing relays of MOD-IO it was time to write our first "Hello world!" PLC program - a simple program which switches ON / OFF the existing 4 relays and resets internally some counter values. We used Beremiz in the following setup:

  1. Beremiz's IDE running on Kubuntu 20.04 LTS used for writing the program, visualizing its status and controlling the runtime
  2. a runtime running on same machine (x86_64 architecture) which controls the coupler over a LAN network (notTSN yet!)
  3. a Lime2 coupler running a modbus server with one (for now) attached MOD-IO with 4 relays

Below you can see the source code of our first PLC program:

Below it's a screen shot of the program running inside the IDE itself with real time values.

And finally one can see the video of the coupler being controlled remotely from the runtime.

Third goal: have the PLC control the conveyor of a real machine

As part of OSIE project and the optical (formerly cherry-picking machine) we build there (see here) we will soon use the coupler in a real conveyor belt based machine which should be able to track movements of conveyor belt objects and perform a real-time classification on them to decide whether to select an object or not.

All the selection will be done using machine learning inference algorithms which should run on a close-by powerful server running Wendelin Big Data Platform.

With current coupler we now have the building blocks to finish our production line.

Conclusions

Our proof of concept showed that the existing tools allow us to have a complete open source based system which is not at all vendor locked and free to use.