I have seen many discussions about this.
Almost all of the conclusion is No. The python code can not replace PLC due to realtime requirements.
But If the realtime requirements is not critical. If the control can be extended to 1 second or even 2 second. I think it is possible.
Actually I have done a small control system of 1 sec scan time on about 100 in/out signals using python and mysql, using RPI, so far no issue. But I haven't try to create a PID loop which maybe a challenge.
The next scale up is whether I can create a complete python code with DI, DO, AI, AO, VFD, PID, Timers, Ramp all setup to control a process plant, 1 sec scan time, using RPI or industrial PC.
Welcome everyone to discuss and share your experience on it.
Are you saying that python, as a language, can not be used due to realtime requirements?
I am a purely python user, don't know the fundamental structure of python language, but a lot of saying is that compare with C or other language, python does not meet the realtime requirements like the PLC does.
for example, siemens 1200 PLC can scan at rate of 5-10ms, rockwell compactlogix can go at similar rate, but if the program is heavy, it may go up to 100-500ms, that's it.
But for the little project I did using python on RPI to read data, calculation in the code, send data to the DO, it takes around 300ms already.
This is just a simple control system, no batch, no sequences, maybe my coding structure is not ideal, maybe it can be improved to dramatically reduce the scan rate, but I don't think python is efficient enough to handle 5-10ms scan rate logic requirements.
A lot of this is because there is a whole OS 'between' your code and the hardware
Yes, it has been discussed by many people. I like the one below:
My thinking that, compare with the CNC system, which requires ms feedback, the process control system usually does not have strong real time requirements, the python may have better chance to replace PLC. Of cause, the code needs to be well written to protect the site in case, a lot of exceptional handle logic to add in.
The key to this topic is a language's memory management. Scripting languages in general, and java in particular, typically use "garbage collection" to determine when memory can be reclaimed and then recycled. This requires pauses while the language infrastructure examines all of the objects to determine which ones have been discarded. Depending on the language and the garbage collection algorithm, these pauses may be tens or hundreds of milliseconds, or more. Java (and therefore Ignition), when both memory and CPU are plentiful, can be tuned to keep these pauses in the low tens of milliseconds.
Other languages use other techniques to track memory usage and release resources in a more timely fashion--possibly even completely manually (like C). If you can match an application's requirements to a language's maximum pause time, you can do control in that language.
FWIW, PLCs typically don't even try to manage memory--every bit of memory used by the program is pre-allocated before starting RUN mode and there are no pauses in the PLC's infrastructure at all.
For most control applications, the issue is reliable timing in the single-digit millisecond range, or perhaps a bit faster. Servo and robotic applications typically have positioning control loops operating in the hundred-microsecond range.
I think this may be tangentially related - https://micropython.org/
I've personally never used it but I've seen it mentioned a bunch in other discussions about embedded solutions using python.
LOL, I do my embedded stuff in Rust