filou
When investigating, whether OpenPLC could be useful for my projects, I came across
a few small obstacles. They made my work although not fundamentally impossible but
quite complicated. Upon further research into the problems, I found out, that I'm
probably not alone. There were two things in particular, that gave me a headache at
the beginning. Firstly, the limited selections of Arduino platforms and secondly,
the very long compilation times with the Raspberry Pi Runtime, especially with older models.

Since I find the project very useful for my tasks, I started to take a closer look at it.
I found a starting point for each of my two wishes in the Python build scripts, to achieve
them with little effort. I tried to change as little code in the original project as possible,
to enable later an easy integration in the original sources.

If it is of interest I would like to open two posts, “Adding a new Arduino platform” and
“Cross compiling for embedded Linux"
 
 
Reply 2 0
thiagoralves
I saw that you've already written the "Adding a new Arduino platform" one. Nice job! As I mentioned on that post, if you can write it as a tutorial, I can add it as part of the Documentation section on the Autonomy website.
Reply 0 0
filou
it is just a small contribution. The real great job is OpenPLC,
which has brought the beremitz editor and matiec out of their slumber.
Big thanks to Thiago Alves.
 
The Arduino project fascinated me from the beginning, it was easy to install and ran on Linux and Windows.
I was impressed by the simplicity of realizing small projects so quickly.
Initially limited to Atmel CPUs, it grew quickly and over the years it has become a standard in the microcontroller community.
 
OpenPLC is well on its way to becoming something like Arduino for automation technology.
 
I came to MightyCore when I wanted to use an old AVR board with the Arduino IDE and the associated library.
There will be more work to be done, testing with MC libraries and take care of the specific "arduino.cpp" file,
before I write a step by step tutorial respectively a HOWTO.
 
Wishes and suggestions on this are welcome.
 
Perspective : Using this packages means, that nothing stands in the way of developing any kind of PLCs based on ATmega CPUs.
 
Arduino compatible Cores from MCUdude (https://github.com/MCUdude):
 
MightyCore suports ATmega8535, ATmega16, ATmega32, ATmega164, ATmega324, ATmega644 and ATmega1284.
MiniCore suports ATmega328, ATmega168, ATmega88, ATmega48 and ATmega8.
MegaCore suports ATmega6490, ATmega6450, ATmega3290, ATmega3250, ATmega2561, ATmega2560, ATmega1281, ATmega1280, ATmega649, ATmega645, ATmega640, ATmega329, ATmega325, ATmega169, ATmega165, ATmega128, ATmega64, AT90CAN128, AT90CAN64, AT90CAN32
Reply 2 0
thiagoralves
Thanks for the nice words @filou! Just a word of caution on those AVR cpus. They usually come with very low RAM, which makes them a bit low spec for a full IEC runtime. I’m just saying this because I don’t want you guys to put all that effort on bringing new AVR CPUs to then realize they can’t run anything bigger than a traffic light.
Reply 0 0
filou
You're right, RAM is the limiting resource on AVRs. For medium tasks i prefer the ATMega1284 wich has 16KBytes of RAM, enough even for a small PLC. Think of applications that run on mini PLCs like Siemens LOGO. So in my "Add a Arduino" example i use MigthyCore wich supports some pin compatible controllers from ATmeg16 upwards. Staircase light control, garage door automation, pump control, etc. i think are applications, for wich such mini PLCs are quit useful.
I have worked with Siemens S7 for many years, sometimes with several hundred inputs/outputs, Profibus and Profinet. In these regions, especially when connection to IT infrastructure is required, a soft PLC on embedded Linux is the first choice. I would like to address this in the second post, Cross Compiling OpenPLC runtime.
if everything works as expected, i will also try to cross compile for xenomai real-time kernel.
Reply 1 0
mralvarado22
Thanks for creating OpenPLC
quick questions:
(1) if I want to contribute to this software to add a new controller, for example, an ARM architecture. How can I do it?
(2) if I want to contribute to this software to add a new Function Block, for example, 2 State Valve. How can I do it?
Thanks in advance for your help.
Mario
Reply 0 0
filou
The easy way, if your target can use arduino infrastructure: https://openplc.discussion.community/post/add-a-new-arduino-platform-13477511
 
 
 
The later technique can be used for baremetal too and is not limited to Linux targets. Anything is possible, if your toolchain is C99 compatible.
Reply 0 0
thiagoralves
On the first question, @filou answered nailed it and responded very well. The only thing I would add to his response is that if you try to add anything that is not "arduino compatible" or "linux compatible", you will have to rewrite a bunch of things, from the build script to the runtime code. OpenPLC is heavily dependent on Arduino API for microcontrollers and on POSIX for Linux.
 
On your second question, the easy way is to just write your block in a project and then share the project here in the forum on the Custom Function Block section: https://openplc.discussion.community/custom-function-blocks-751065
 
The hard way is to actually code the block on the editor so that it becomes permanent. Here are the instructions to add a new block to the library: https://autonomylogic.com/docs/3-3-adding-new-blocks-to-openplc-editors-library/
Reply 0 0
mralvarado22
Thank you so much both @filou and @ThiagoAlves for your help. I'll take a look at the references and most likely will come back to you with more questions.
I really appreciate the help
Reply 0 0
mralvarado22
Hi @filou
    Is there an Arduino hardware that is similar or more powerful than a 1756-L85E. For example a controller that can manage dozens of remote IOs over TCP?
Thanks
Reply 0 0
filou
    Is there an Arduino hardware that is similar or more powerful than a 1756-L85E. For example a controller that can manage dozens of remote IOs over TCP?
Thanks
Arduinos do not have a classic operating system. Network programming is therefore not their strength; Linux scores here. If the performance should be equivalent to a "ControlLogix 5580 Controller", I would use Linux-based hardware and MODBUS TCP as the I/O protocol. This works with OpenPLC and a Raspberry Pi out of the box. If the I/O hardware and thus the protocol is already specified, this may need to be supplemented. The code or the place where this is possible is in the Linux Runtime. This may also work with Python, in which case it could be easily integrated as a module.
 
You can also try a low cost, minimal Linux board like "LuckFox Pico RV1103 Linux Micro Development Board ARM Cortex-A7 RISC-V" which cost about 10€.
 
If you want to develop the hardware and PCB yourself, a Raspberry Compute Module or a SOM from another manufacturer would be a good starting point.
 
STMicroelectronics NUCLEO F767ZI Nucleo-144, ARM Cortex M4F or STM32F746G-DISCO are ARM based and have Ethernet on board. Basically there is good Arduino support for the STM32 series, from Cortex M0 to M7. I can't say exactly whether Ethernet is also supported, so this point needs more research .
Reply 0 0
mralvarado22
Thanks @filou, I'm still go thru your tutorials. Thanks for putting this together.
I got more questions
  • is Linux-based hardware capable of ensuring a deterministic scan time, for example, classic routines in controllers that execute at a predefined rate (like 20ms)?
  • What would it take to add "online changes functionality" to OpenPLC?, for example, adding a rung to the Program while it is running. Is it a combination of hardware and software redesign? Do Arduinos support this?  
Reply 0 0
filou
Linux is partially real-time capable, look online for the PREEMPT_RT patch. There are suitable real-time kernels available for Raspberry Pi. The source code in ..../OpenPLC_v3/webserver/core/main.cpp shows how real-time works under Linux. The main loop is run through every 20 milliseconds, as was set in the project configuration. The updates of the I/Os via TCP are at first not deterministic, as Ethernet is not deterministic per se. How well this works, depends on the network infrastructure, such as switches and routers. If you replace the field bus with Ethernet and need real-time behavior, you have to use special protocols and switches.
 
For the second point, are you thinking of S7 software from Siemens? It works completely differently to OpenPLC or CODESYS. A kind of virtual machine runs on an S7 PLC, that interprets the program at runtime. This makes it possible to replace individual blocks and reset the pointers at the end of a program cycle. OpenPLC always translates the entire ST program to C and then with the C compiler for the corresponding target. Swapping individual instructions on the fly is not possible.
Reply 0 0
thiagoralves
Linux targets (like a Raspberry Pi for example) with the PREEMPT_RT patch applied have a pretty good real time response running OpenPLC, comparable to modern PLCs running CODESYS.
 
As for online changes functionality, this will most certainly never come to Arduino boards due to their limited architecture. Linux and Windows targets however might see that feature in the future. Just to be clear, I don't want to sound too optimistic. This feature is something quite hard to implement, but it is possible on Linux and Windows targets. It requires a very optimized "memory transfer" routine from one OpenPLC instance to another that can happen in the middle of a scan cycle, so that the new instance can continue where the old one stopped.
Reply 0 0
mralvarado22
Linux is partially real-time capable, look online for the PREEMPT_RT patch. There are suitable real-time kernels available for Raspberry Pi. The source code in ..../OpenPLC_v3/webserver/core/main.cpp shows how real-time works under Linux. The main loop is run through every 20 milliseconds, as was set in the project configuration. The updates of the I/Os via TCP are at first not deterministic, as Ethernet is not deterministic per se. How well this works, depends on the network infrastructure, such as switches and routers. If you replace the field bus with Ethernet and need real-time behavior, you have to use special protocols and switches.
 
For the second point, are you thinking of S7 software from Siemens? It works completely differently to OpenPLC or CODESYS. A kind of virtual machine runs on an S7 PLC, that interprets the program at runtime. This makes it possible to replace individual blocks and reset the pointers at the end of a program cycle. OpenPLC always translates the entire ST program to C and then with the C compiler for the corresponding target. Swapping individual instructions on the fly is not possible.
Thank you @filou and @ThiagoAlves both for your answers. @filou You are correct, I was referring to a S7 PLC. I would like to replace individual blocks and reset the pointers at the end of a program cycle. If you know or you are aware of any literature that explains how I can implement this and what architecture to use, I would highly appreciate if you can share it. Thanks.  
Reply 0 0
Reply