Reducing Repetitive Code

cd36

Member
Join Date
Nov 2018
Location
Mb
Posts
6
Hey,

I am working on a project that is a bit more involved than past ones I have done. It will be using a CompactLogix PLC, and I'm using Studio 5000 v30.

Some parts of my code are going to be very repetitive, for example I will have to control 12 gates, all 12 gates will require the exact same logic, the only thing that will change is the I/O's that they use. In the past I would just brute force this, as I was never dealing with so many repeat instances, but I'm looking to simplify my code.

Essentially I'm wanting two subroutines, one to Open the gate, and one to close the gate. All 12 gates will be controlled independently from one another, but their logic will be the exact same. Each gate has an Open Limit Switch, Closed Limit Switch, Full Bin Sensor (don't open gate if bin is already full), and an output to Open, one to Close, then just some status indicators (Opened, Closed, Transit).

Now my big question, can I write a subroutine, with the generic logic that would control all gates, and when my main routine calls that subroutine, have it pass all the appropriate I/O's to the subroutine so it opens whatever gate the user is requesting? This would be in place of have potentially 24 different subroutines (Open and Close subroutine for each gate).

Thanks for any help you may be able to provide. And I'm sorry if this is a basic question, I haven't been able to find information on how to do exactly what I'm wanting yet. Thanks,
 
As bkottaras said you could create an add on instruction, especially as your using Studio 5000 you have more functionality as to what you can pass into your AOI (structures, gsv module names etc).

Once your AOI is working OK- then just use your AOI as a multi-instance- and declare them as an array (or individually if you want better naming conventions).
 
Wow, just quickly read through AOIs and that's exactly what I'm looking for. Between them and UDTs I should be able to clean up my program quite a bit. Thanks for the quick help!
 
Wow, just quickly read through AOIs and that's exactly what I'm looking for. Between them and UDTs I should be able to clean up my program quite a bit. Thanks for the quick help!

Do remember the caveat that these cannot be modified online... and how some places specify that no AOI's will be allowed.
 
Failing that you could use a subroutine with a 'struct' passed to it as a parameter and the result passed back to the calling routine.
This can be modified online.

Steve
 
Thanks for the alternative option. Editing online isn't a requirement, so I'll look into AOIs. I appreciate everyone's help!
 
To add to the points mentioned above, the FOR instruction can also be utilized in conjunction with AOIs and UDTs to eliminate repetitive AOI calls. I've actually become very frustrated with AOIs which I had to create a lot of rungs for (for each alarm) and just added a single rung which was cycled through by a FOR loop.
 
To add to the points mentioned above, the FOR instruction can also be utilized in conjunction with AOIs and UDTs to eliminate repetitive AOI calls. I've actually become very frustrated with AOIs which I had to create a lot of rungs for (for each alarm) and just added a single rung which was cycled through by a FOR loop.

Yes, but depending on who will be maintaining the code, there is no better way to mess with a sparkie's head then to put some looping code for him to follow. Impossible to debug. I stick with the brute force method; duplicate till the cows come home but he'll have no problem following it and I won't get that late night phone call.
 
Yes, but depending on who will be maintaining the code, there is no better way to mess with a sparkie's head then to put some looping code for him to follow. Impossible to debug. I stick with the brute force method; duplicate till the cows come home but he'll have no problem following it and I won't get that late night phone call.

That's a fair point, but if you already have AOIs / UDTs, you might as well go all the way; from my experience, technicians either know everything or struggle with XICs/XIOs.

I do agree that it makes it more difficult to troubleshoot, so use with caution...
 
Yes, but depending on who will be maintaining the code, there is no better way to mess with a sparkie's head then to put some looping code for him to follow. Impossible to debug. I stick with the brute force method; duplicate till the cows come home but he'll have no problem following it and I won't get that late night phone call.

Agree. Using text files with find and replace makes duplicating rungs very easy.

“Common” routines make troubleshooting very difficult.
 
Failing that you could use a subroutine with a 'struct' passed to it as a parameter and the result passed back to the calling routine.
This can be modified online.
The question then becomes, can it be viewed online. My understanding is that Rockwell is a bit behind when it comes to online view of subroutine instances (or whatever they call them).

On the one hand, the code is no longer repeated, on the other the code can't be viewed online.
 
Dealing with both RA & Siemens daily, it a little easier to get to view the running logic of a specific instance of an AOI than Siemen's with a FB but both are basically equivalent. I have to go jump through a few more keystrokes to pull it up in Step 7 than the one mouse click in Studio. Though maybe its easier in TIA Portal, customers are sticking with Step 7 for the logic side.

Now, if your making multiple calls in Studio to the same sub-routine with different parameters, that's going to be tough. You'd have to disable all but the one call you're insterested in debugging to see that.
 
Last edited:

Similar Topics

I am deciding on components for a bayed modular enclosure containing multiple VFDs (480V/350A/321Hp each) for a dynamometer. I am concerned given...
Replies
7
Views
1,670
We have a servomotor with gearbox (i=+-20) driving a big steel disc. This disc has a high inertia. Are there mechanical compensation methods for...
Replies
3
Views
1,693
I have an application where I need to reduce the travel of an actuator and also double the force. How can you do that manually, without the help...
Replies
10
Views
2,458
Hi guys, Wondering if I can have your honest (and brutal) feedback on a PDF guide I'm creating for my customers. The intent of it is to help...
Replies
0
Views
2,493
Hi.. I want to know something about Pressure Reducing valves & pressure regulating valves. I understand their purpose. But wanted to know whether...
Replies
4
Views
1,551
Back
Top Bottom