Arrays in ControlLogix

HarleyHetz

Member
Join Date
Jun 2012
Location
Memphis, TN
Posts
39
Hey guys,
In the spirit of true "Object Oriented Programming", I am attempting to create a dynamic array of UDT "Objects". I need to add and delete objects from this array as they are needed/used, I need to loop through the array and perform mathematical operations on a member or two of each "Object" in the array while they exist. And, I'd like to do it in Structured Text.

I will be using an L81, probably V31.

For those who are familiar with Visual Basic, I am essentially looking for a way to create a "Collection".

Anyone have any insights as how to best approach this??

Thanks in advance for any suggestions!!
 
As far as I remember (and I'm not the expert on Rockwell), the program can't create it's own tags so it will be tricky to do what you're after I think.

So, I'm not necessarily looking to "create" the tags, just "assign them to a collection" of tags. In other words, when I "need" one, I will grab one that already exists, fill in the members of the UDT with the values that are pertinent, and then "add it to a collection of like UDT's". When I'm done with it, I will clear out all of the members, and remove it from the "collection".

This is pretty common practice in computer programming, just can't figure out how to do it in PLC!!! :p

EDIT: So, I thought I should add WHY I'm trying to accomplish the above...the main reason is to speed up this operation. The system will be conveying packages, a barcode will be read, and decisions about diverting packages must be made, as well as tracking the positions of the packages. So a lot of heavy lifting by the PLC!! If I can look at only the UDT's that actually represent a package at any given point, it will speed the calculation process up considerably!!
 
Last edited:
Seriously, this sounds silly, PLC's are to handle specific tasks, not be word-processors, but whatever.


And your example doesn't actually help. Again, whatever.


Make an array of UDT's.
Assign it to a FIFO.
On program initialization, load up the FIFO completely with empty UDT's.
As you need one, unload it from the stack. When you are done with it, load it back in.
Easy Peasy.
 
what rdrast said. the difference between a PLC and a computer is that you will have to specify the size of your array of UDTs so that it is larger than your collection will ever need to be.
 
what rdrast said. the difference between a PLC and a computer is that you will have to specify the size of your array of UDTs so that it is larger than your collection will ever need to be.

One of the "benefits" of PLCs vs other embedded systems is that they typically limit you to only statically defined memory (no dynamic memory). This prevents things like memory leaks, which have been the bane of PC users since forever.

That said you could potentially create a master UDT of of all possible UDTs, and then create an array of them for as big as you would need. Include in one of the UDTs some status flags for which UDTs are actually meaningful for that array entry, and you can sort of dynamically limit which ones are actually processed.
 
This is pretty common practice in computer programming, just can't figure out how to do it in PLC!!! :p

Keep in mind PLC programming and computer programming are not the same, so you're better off learning how a PLC handles things rather than trying to force the PLC to do something it isn't meant to do.

Sounds like you just need need a buffer. As you mentioned create some type of array

CustomUDT[0...###], define the UDT parameters, make the array lenth as long as you might need it.

Probably had a flag in the UDT to determine if it is in use or not, have your logic find an unused array element, then use it. Clear and unflag it when it's not in use?
 
Harley, arrays can not be dynamically sized in A-Bs 5000 series s/w, they are fixed in size. So you have to do tricks, specify a member in your UDT that indicates its a valid record, something along those lines.
 
The speed of execution of a PLC program is a major factor.

I assure you that if the PLC program ran on a virtual machine, as most computer programs actually run, then it would go at least 10 times slower and need 10 times more memory.

And part of this slowness is thanks to things like dynamically allocated arrays.

You can do other things in PLC programming to be more OOP, for example function blocks that avoid the use of global variables and that are reusable between projects.
 
So, first of all, sorry for the delayed response...have been working diligently on the issue.
Secondly, thank you to all who responded. It was actually the first response that led me to the solution which I will share in a moment.
Thirdly, allow me to apologize for the less than revealing description of the problem. My intent was that someone with experience in both programming languages, like myself, would have run across the issue before and solved the problem. It was not to get you strictly PLC guys all riled up about word processors and dynamic arrays!! :D
Fourth allow me to say to those of you how saw "Object Oriented Programming" and pooh poohed it right away. It is the wave of the future, Control Logix is capable of it, but it takes a bit of creativity to accomplish. Learn it, you are going to need it!!

Now, for the solution:
What I wound up doing was taking three arrays, and using two FIFO's to create my "Collection" which I could add and remove elements from. I will be happy to share this with anyone who is interested, but it is MUCH too much to go into in a post. What that did for me was allow me to move an "Object" (aka a package in my instance) from one FIFO to another with a transition in between so I could manipulate the values as needed. These values are not strings, they are Booleans and DINT's, and they must be manipulated as I have a multitude of products being presented to me and they are different sizes, and have different destinations. All of this information is stored in each "Object", and then tracked down a conveyor using an encoder, the packages may or may not have to switch lanes at the end of tracking, and I am slowing down the conveyor whose package is behind, be it the one switching sides, or the other one. This way I can create a "Gap" to insert the package into. This certainly might have been done differently, but I believe my method is quite efficient as I am operating only on array elements which are actually on the conveyor at any given time, not the complete array.
As I mentioned, there is quite a bit of calculation involved in not only tracking the packages, but figuring out which one needs to slow down and for how long. And, to make it more difficult, the conveyors are traveling quite quickly, so these calculations must be performed as quickly as possible!!

Again, thanks to those who tried to help, and special thanks to the feller who posted the suggestion about the FIFO, it put me on the right track!!🍻
 
Sounds like what we do for material handling and object tracking for years now. Siemen's Step 7 and RA's 5000 s/w allows data types to be created ( UDTs ) so objects instances can carry multiple pieces of information per object. I learned OOP first early in my career and rejoiced when OOP concepts showed up in PLCs ( 20 years ago ).
 
You can write code to handle arrays that are not of a known size using the size keyword and pass an array without knowing its size but there is no dynamic memory management available to the PLC runtime.
 
So, first of all, sorry for the delayed response...have been working diligently on the issue.
Secondly, thank you to all who responded. It was actually the first response that led me to the solution which I will share in a moment.
Thirdly, allow me to apologize for the less than revealing description of the problem. My intent was that someone with experience in both programming languages, like myself, would have run across the issue before and solved the problem. It was not to get you strictly PLC guys all riled up about word processors and dynamic arrays!! :D
Fourth allow me to say to those of you how saw "Object Oriented Programming" and pooh poohed it right away. It is the wave of the future, Control Logix is capable of it, but it takes a bit of creativity to accomplish. Learn it, you are going to need it!!

Now, for the solution:
What I wound up doing was taking three arrays, and using two FIFO's to create my "Collection" which I could add and remove elements from. I will be happy to share this with anyone who is interested, but it is MUCH too much to go into in a post. What that did for me was allow me to move an "Object" (aka a package in my instance) from one FIFO to another with a transition in between so I could manipulate the values as needed. These values are not strings, they are Booleans and DINT's, and they must be manipulated as I have a multitude of products being presented to me and they are different sizes, and have different destinations. All of this information is stored in each "Object", and then tracked down a conveyor using an encoder, the packages may or may not have to switch lanes at the end of tracking, and I am slowing down the conveyor whose package is behind, be it the one switching sides, or the other one. This way I can create a "Gap" to insert the package into. This certainly might have been done differently, but I believe my method is quite efficient as I am operating only on array elements which are actually on the conveyor at any given time, not the complete array.
As I mentioned, there is quite a bit of calculation involved in not only tracking the packages, but figuring out which one needs to slow down and for how long. And, to make it more difficult, the conveyors are traveling quite quickly, so these calculations must be performed as quickly as possible!!

Again, thanks to those who tried to help, and special thanks to the feller who posted the suggestion about the FIFO, it put me on the right track!!🍻
That isn't object oriented programming.
It's also been around for decades, hardly wave of the future.

Personally I would avoid using tons of VB to do things, rather keep it simple and try not to re-invent the automation industry ;)
 

Similar Topics

I have an application that requires the addition of multiple arrays in a controllogix program. First of all, I have an array of 250 tag name...
Replies
15
Views
3,543
I have a controllogix processor with a few boolean arrays set up.. For example, one array is Step_Cycle_Complete. Basically, the addressing goes...
Replies
4
Views
7,015
Hi. This is pretty basic but I'm struggling to find an efficient solution. I have a float value of let say 666.555 that I want to move / split...
Replies
3
Views
146
Hello. I've been using the answers in this forum for a while now, so thank you. Usually I can find the answer I'm looking for with a basic...
Replies
8
Views
733
Hello, first time poster here! A belated "thank you" for the direction I've already received from this forum! So, can I do this? Move value 1...
Replies
6
Views
676
Back
Top Bottom