LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Incrementing Value of Cluster Element Within an Array

Full disclosure, this is for a homework assignment. I am not looking for someone to do my assignment for me.  I am looking for advice on what functions to use to accomplish the task.  Here is the problem:

 

I have an array of four, two element clusters.  One is element is the pump position and the other one is the pump hours.  I am trying to track the hours that each pump has run for so that I can stage them.  I would like the pump with the least amount of run time to run first.  There are four pumps and the amount of pumps needed depends on the vacuum level.

 

I was trying to use a local variable from a boolean indicator to determine whether or not the pump was running and then increment the the "hour" counter every second.  (I didn't want to watch the program for hours to see if it was working.)  I tried to index the array and write those into clusters.  Then I unbundled the clusters to access the pump hours element and tried to increment that in a while loop, bundle it back up, and put it back into the array.

 

The whole thing has kind of gotten messy at this point.  I realize that it is probably poorly written but I am just trying to achieve functional rather than efficient at this point.  I am new to LabVIEW so any pointers are appreciated.

 

Thank you!

0 Kudos
Message 1 of 18
(3,786 Views)

I'm not sure I totally understand your VI, but here is an example how you could count your pump time. I think it's better to use Get Date/Time VI rather than rely on your loop taking a certain amount of time.

 

snippet.png

Message 2 of 18
(3,778 Views)

@jrsnydley wrote:

Full disclosure, this is for a homework assignment. I am not looking for someone to do my assignment for me.  I am looking for advice on what functions to use to accomplish the task.  Here is the problem:

 

I have an array of four, two element clusters.  One is element is the pump position and the other one is the pump hours.  I am trying to track the hours that each pump has run for so that I can stage them.  I would like the pump with the least amount of run time to run first.  There are four pumps and the amount of pumps needed depends on the vacuum level.

 

I was trying to use a local variable from a boolean indicator to determine whether or not the pump was running and then increment the the "hour" counter every second.  (I didn't want to watch the program for hours to see if it was working.)  I tried to index the array and write those into clusters.  Then I unbundled the clusters to access the pump hours element and tried to increment that in a while loop, bundle it back up, and put it back into the array.

 

The whole thing has kind of gotten messy at this point.  I realize that it is probably poorly written but I am just trying to achieve functional rather than efficient at this point.  I am new to LabVIEW so any pointers are appreciated.

 

Thank you!


Welcome to data flow programing!  Yes, those locals are introducing "Race Conditions"   And it is a mess!

 

What would happen if you attempted to remove all of the local variables?  Did you ask for the "user's story" on what information is really needed on the Front Panel? 

 

Now lets look at a bunch of race conditions

DontDoThat.png

Should be replaced with:

ccc.png

First the index array does not need any constants (Read the help!) the default is 0 and expanding the node increments the index

So, what order are the indicators for SA-n written and the Local Variables Read from?  Since there is no wire between SA-n Terminal and the Local Variable the read the value from the terminal SA-n it is possible to read an old value! Or, that is a classic "Race Condition"  

 

Get rid of every Local in that vi!  Then thank me:D


"Should be" isn't "Is" -Jay
0 Kudos
Message 3 of 18
(3,769 Views)

So since my clusters are in an array, do I have to index the array and to get each cluster isolated in order to perform that?  Can I write back in to the same cluster and then put it back into the array or would I need to write it to a separate cluster?

0 Kudos
Message 4 of 18
(3,767 Views)

Can I use the Number of Pumps Needed as an indicator and control?  I think I would have to use a local variable in some places wouldn't I?  I don't really quite understand the flow of things yet.

0 Kudos
Message 5 of 18
(3,763 Views)

This is what I have now.  I have taken the hour counters out because they weren't working anyway.  Any good ideas on how to eliminate all the local variables for Number of Pumps Needed or what functions I should use to increment the pump hours?  I guess I just don't understand how to access the pump hours in each cluster, increment them, and put them back into the array to be sorted so that the pumps are in the correct position.

0 Kudos
Message 6 of 18
(3,755 Views)

@jrsnydley wrote:

This is what I have now.  I have taken the hour counters out because they weren't working anyway.  Any good ideas on how to eliminate all the local variables for Number of Pumps Needed or what functions I should use to increment the pump hours?  I guess I just don't understand how to access the pump hours in each cluster, increment them, and put them back into the array to be sorted so that the pumps are in the correct position.


That is a lot more readable:)

The delays are a problem (Stall Dataflow.vim) all they do for you is guarantee that the data read from the local variables is stale (most likely the data was updated by another section of code that ran between when the terminal was read and when the calculation was done to update the value)

 

What you are looking for is called a "State Machine" where your code executes a set of instructuctions in an order based on current values.  Look into the shipping examples (Help>>Find examples) for State Machine  and you will also learn about a "Shift Register" and a "Feedback Node"

 

There are also free training resources available!

Capture.png


"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 18
(3,739 Views)

 

Screenshot.pngLike this?  For each pump?  Then how do I get the hours back into the array so the pumps can be sorted?  This isn't incrementing either

0 Kudos
Message 8 of 18
(3,710 Views)

We don't have your requirements document- that makes it hard for us to provide you with guidance

 

There is definitely "Local Variable Abuse" in that code.  Try to get rid of as many of them as possible.  You should have none of them in a parallel process! each read from a local variable had no data dependency so it WILL read the original value even if you update the value later the value on the wire is still the value when the local was read.  This is "Dataflow 101" A node can execute as soon as all of its inputs are satisfied.   

 

You have to create the data dependencies with WIRES. 


"Should be" isn't "Is" -Jay
0 Kudos
Message 9 of 18
(3,703 Views)

I need to track the hours of each pump so that I know how long each one has been running.  From this information, I need to put the pumps in order from 1 to 4 with 1 being the fewest hours and 4 being the most.  As the vacuum level drops below the set point, more pumps are commanded to run starting with the lowest position and working up to the highest.  If the vacuum level gets too high, the pumps drop out starting with the highest position and working down to the lowest.

 

I got rid of the local variables for the position numbers.  Would I need to use a state machine and shift register to eliminate all of the local variables for number of pumps needed?

0 Kudos
Message 10 of 18
(3,699 Views)