04-09-2019 03:33 PM
Hello all. I am definitely a LV noob. So, the problem I am trying to solve is my boss wants a control that will prevent a piece of equipment from running more than 1 minute within a running 5 minutes. I assumed I could create a 2D array with 300 lines (number of seconds in 5 minutes), and 2 columns. The first line would just be 0-299, and the second column would contain "1" if the power is on during that loop, and "0" if it is off during that loop. At the end of each loop, I would add up the second column and if it equaled 60, then I would automatically turn off the equipment and disable the button. After all 300 registers have been filled, I would like the first record to drop off, and the most recent record to be placed at the end. In other words, it will take 5 minutes for the last record to be purged.
Can someone point me in the right direction to accomplish such a thing? Maybe an easier way?
Thanks,
LV_noob
Solved! Go to Solution.
04-09-2019 03:43 PM
Have you ever heard of a "circular buffer"? In the Good Old Days, we would take a fixed-length Array, say 300 elements, and would create a index, call it "Index", that could take values of 0 - 299. We would initialize the Index to 0, and would have an operation "Add to Buffer" that would put something in the Array at the position pointed to by Index and then move Index to the next position. But what to do when you reach the end of the Array? How to make it count 298, 299, 0, 1, 2, ...? Can you think of a numerical operation that does this? [Hint -- look at the Functions on the Numerical Palette].
As you frame your question, there's no need to move the elements in the Array -- it is so much simpler to move the Index. And why do you use "0" and "1" in your array? What does "1" mean? [Is there another, say, more "logical", type of Array element that suggests itself?]
Bob Schor
04-09-2019 03:56 PM
Thank you Bob_Schor, I will look into this. The reason that I am using "1" and "0" is because I figured I could just total the "1s" and check to see if it added up to 60. Or are you hinting at something? Maybe the Increment Array Element.vim?
Thanks again,
Mike
04-09-2019 03:59 PM
Whenever I need to use a circular buffer, I always just use a queue with fixed length and lossy enqueue. You could do something like this.
04-09-2019 04:58 PM
Thank you prettypwnie. That looks promising. I will definitely start playing around with that. I would have never figured out the use of all the different functions and the event structure. Gonna have to start reading more. 🙂
I will report back...
Mike
04-10-2019 08:00 AM
Actually, your notion of using 0 and 1 instead of (say) Booleans makes sense -- there's an Add Array Elements function that will turn your Array into a number "all at once", just what you need. However, you can also do the same thing with Booleans -- you just need a function that turns F/T into 0/1 (which LabVIEW thoughtfully supplies). Here's an example that generates an array of 1000 Booleans, computing the number of generated random numbers that are greater than 0.5 (which should be about half of them, or around 500):
Note that the function Boolean to 0, 1 works for both single Booleans and Arrays (thanks to polymorphism).
Bob Schor