Code Abstraction in Industrial Control

Hello All,

Can you guys share your opinion on code abstraction or OOP for discreet industrial control operation.

My view is that when it is a discreet process ( turning a pump on or off), it is more beneficial to make the process as apparent as possible using a language like ladder or FBD to visually show the process without any abstraction.

As oppose to presenting the same functionality using Structure Text by abstracting away the input, the output, creating an object or function or many function and objects and calling them.

Yes many rungs or function block can be condense in to a handful of ST lines.

What are the pros and cons? our PLC are super powerful nowadays, isn't it better to see the process activating on one ladder or sheet as oppose to having to jump through several function call?
 
There is no point in using a FB for a simple motor start using say buttons, calling FB's usually means a little overhead of processing time i.e. passing the parameters, however, there is a benefit for many systems for example where what may be considered a multipal motor system where each motor has a number of parameters i.e. Start, Rotation, alarm(s), perhaps a variable for HMI information like colour, to hard code each one is not efficient & the fact is if an FB is designed right there is no need to look into the workings as it is common for all those motors, just consider it a block like a ladder so you can see the status of the controlling bits that is all the information you need It's the inputs & outputs that show if there is a problem
 
Hello All,

Can you guys share your opinion on code abstraction or OOP for discreet industrial control operation.

My view is that when it is a discreet process ( turning a pump on or off), it is more beneficial to make the process as apparent as possible using a language like ladder or FBD to visually show the process without any abstraction.

As oppose to presenting the same functionality using Structure Text by abstracting away the input, the output, creating an object or function or many function and objects and calling them.

Yes many rungs or function block can be condense in to a handful of ST lines.

What are the pros and cons? our PLC are super powerful nowadays, isn't it better to see the process activating on one ladder or sheet as oppose to having to jump through several function call?
You're conflating language with program design. They are mutually exclusive. Abstraction is used with LD by many.

Nothing is inherently "abstracted" away simply by using ST.

Output := (Start OR Output) AND Stop;
 
the way I view it is a given programming language is just a tool. Different tools excel for different jobs. I could probably drive a nail into wood with a wrench, but a hammer works better.

If I’m programming manual mode for a machine, you bet your ass its ladder. If I’m writing an automated sequence it’s likely gonna be ST.

If a FB is well developed the end-user shouldn’t really have to look inside. The exterior of the block where you drop it in your ladder will make it apparent what’s wrong.

My 2 cents
 
Perhaps I did not make it too clear, if it's a simple motor control like just a start, stop & output then it makes sense to do it as simple ladder, if it is more complicated i.e. other functions like reversing, VFD, alarms & display animation for an HMI then rather than many rungs of code for each motor then create a function (AOI) call that for each motor, it is easy to debug as once you know what the information passed to/from the function does you can see why it is not running or what ever, & on many IDE's right klicking on the function for that particular motor will display the code in the function & it's status for that particular call (instance).
 
I have worked both in PLC programming and in computer programming using OOP with C++ and Java mainly.

Actually, current PLC programming is very far from being OOP, there is no base class library, it does not support fundamental OOP concepts such as inheritance or polymorphism.

There is also a main difference: in a computer program it does not matter much that when a button is pressed it takes 0.5 - 1 sec to execute, but in a PLC it is inadmissible.

Programs written with OOP have a lot of execution overhead that makes them slower and need lots of memory, whereas in a PLC it is time critical.
 
IMO transparency and intuitive representation of logic is one of the main reasons for using a PLC, so ladder or FBD should be used whenever possible. If that is not your priority; if you intend to use ST or IL because that is what is most convenient for you as a programmer (even if it makes troubleshooting by maintenance personnel impossible or challenging in most instances), then you might as well control the process with a computer which can vastly expand the functionality, or a microcontroller for a fraction of the cost.

I try to only use textual programming for mathematical operations that would take many rungs and look unnecessarily complicated in ladder form. Other times I have used it is when pressed for time and having a lot of identical logic (ex: start/stop of 65 motors instead of just one). But I have since written python scripts which can iterate ladder instructions for N number; they open a project and insert 65 individual ladder sequences.
 
My view is that when it is a discreet process ( turning a pump on or off), it is more beneficial to make the process as apparent as possible using a language like ladder or FBD to visually show the process without any abstraction.

I'm sure in Codesys you can represent a method call in FBD or Ladder... Use of methods is OOP and doesn't require ST to be used.

Looking at this thread there's still people talking about just implementing a ladder rung rather than creating a function/FunctionBlock... this is, in my opinion, the first barrier to OOP.

The other is that whereas in computers the programming is typically event based (user interacting with the software), in a PLC the user is, hopefully, less than 10% of the software interaction. This means that where you'd have a lot of methods being linked to user events, in a PLC, having a method for starting/stopping a pump brings little benefit because that method won't deal with checking if the pump actually started/stopped, whether it needs alarming, etc... so you'd call a method and somewhere down the code have another (typically the instance) being called to run the background logic. Does changing from

Code:
P200.ProgStart :=1;

to

Code:
P200.AutoStart();

Make a difference?

Lastly, it's SCADA/HMI which is the final barrier for another 5 to 10 years. Most SCADA/HMI systems out there also can't call methods... so on our pump example we have to create methods and boolean input/output interface to receive commands and send feedback out.

Mind as well that some of the OOP concepts are now debated and advised against... inheritance versus composition is an interesting debate, for example...

I'd be happy if we, as a whole, instead focused on modular code as a default first and worry about OOP features later.
 
In OOP there should be a hierarchy of classes, containing functions and data variables, and these classes are the ones that are inherited and modified in the derived classes.

Instances (objects) are created from these classes.

It is not easy to adapt and understand the OOP paradigm and, above all, to design an appropriate class herarchy for what we want to do.

I have done some small automation tasks in Java, such as connecting to a scale and printing a label if the weight is correct and stable.

Let's hope that some manufacturer dares to create a true OOP for PLCs
 
In OOP there should be a hierarchy of classes, containing functions and data variables, and these classes are the ones that are inherited and modified in the derived classes.

Instances (objects) are created from these classes.

It is not easy to adapt and understand the OOP paradigm and, above all, to design an appropriate class herarchy for what we want to do.

I guess my point was that the main obstacle to OOP isn't the PLC manufacturers, but the users themselves. It is possible to create hierarchies of data that you instance to describe functionality, just as it's possible to create abtraction so that you don't duplicate efforts too without OOP behind. And yet we, the royal we, still fail at it. My comment above about having a rung instead of a block because it's "simple logic" is an example.

Another example is that many here would program one block to interface with VFD type A and then program another block for VFD type B that contains pretty much the same code rather than have a VFD block that has a unified interface to a block A/B/C/D representing the data interface to different VFDs.

All of these constructs can be created without OOP (granted that at times one will have to rely on variable naming), but we regularly don't... and until that changes, a manufacturer coming out with a true OOP platform won't make a lot of difference.
 
I guess my point was that the main obstacle to OOP isn't the PLC manufacturers, but the users themselves. ...
+1

There is no point to making it easier to code the PLC application, because the cost of code development is minuscule compared to the operational costs of that process, and OOP buys you nothing, and is more likely a detriment, during operation because no one will know how to diagnose problems during operation if the code uses OOP.
 
I think the big problem people get themselves into is they keep thinking of the PLC as a computer that nobody is going to access, but the program and the ladder are basically another layer of UI themselves. due to the need to use it for active process troubleshooting on unique systems that can't be fixed with an update pushed over the internet like mobile code.

Think of the ladder program like an application on a phone that allows someone to change the settings of their phone. The programmer would be fired for making it so somebody had to physically type in each and every change, then rewrite the IF/Then/Else to enable/disable different portions of options on the phone...

The user IS the maintenance guys in the plant or the plant engineer with minimal PLC experience, using it as a troubleshooting tool. and it needs to be built like a UI when programmed. Just trying to minimize things down for the sake of looking neat and clean and small is removing any and all ability for someone to use the UI of that layer of the machine.
 
I think the big problem people get themselves into is they keep thinking of the PLC as a computer that nobody is going to access, but the program and the ladder are basically another layer of UI themselves. due to the need to use it for active process troubleshooting on unique systems that can't be fixed with an update pushed over the internet like mobile code.

Think of the ladder program like an application on a phone that allows someone to change the settings of their phone. The programmer would be fired for making it so somebody had to physically type in each and every change, then rewrite the IF/Then/Else to enable/disable different portions of options on the phone...

The user IS the maintenance guys in the plant or the plant engineer with minimal PLC experience, using it as a troubleshooting tool. and it needs to be built like a UI when programmed. Just trying to minimize things down for the sake of looking neat and clean and small is removing any and all ability for someone to use the UI of that layer of the machine.
I like your perspective
 

Similar Topics

This is basic stuff, but I'm returning to this code after a few years... What does "K5" mean in this code? For context, we've got a motor & it's...
72
Replies
1,177
Views
Hi, I'm in need of a real life code example for any industrial setting for the given PLCs: SIEMENS S7-300 and S7-1500 I need it for a masters...
8
Replies
407
Views
Greetings all. Not having a ton of experience with Siemens PLC's, I was hoping to get some advice selecting a mid-budget (about $500), cordless 1d...
5
Replies
245
Views
Hi all. Software test engineer here. I've never been the one called out to a faulted machine and I'm not going to pretend otherwise. I'm also not...
27
Replies
904
Views
Firstly, sorry I know another post exists for this which I've looked at and nothing in that post helps me to get this working. I have the SOPAS...
9
Replies
603
Views
Top