VI High 36 - Conditional Loop Output Tunnels

This new feature saves us a ton of time, take a look at the old way and new way of conditionally outputting values in an array from a loop.

You can also keep up with us at:

http://facebook.com/sixclear

http://twitter.com/#!/sixclear

http://gplus.to/Sixclear

Experience level: Basic

(start transcription)

In LabVIEW 2012, there’s a handy new feature on conditionally processing loop outputs. To understand why it’s valuable, it’s helpful to take a look at how things were before LabVIEW 2012. Let’s say I want to create an array of random numbers between 0.5 and 1.So how can I do that in LabVIEW?

Well, I can go grab a Random Number Generator, but as we see from the Context Help, it generates a random number between 0 and 1. How do I make it between 0 and 0.5? Well, I can use a Greater Than function and say 0.5. Then if it’s true, then this should go into an array. Well, I’ll need an array to do that.

So I’ll go and grab an Array Constant, put it over here, of the correct data type, which is a Double Numeric, and I want to go and concatenate this value onto that array. So I’ll use the Build Array function. So the array goes into the top input, and this value goes into the bottom.

If I wire it like this, with the array in the top, scalar in the bottom, we automatically will concatenate the inputs, as chosen for us. And so I want this to happen whenever this value is above 0.5. So, a Case Structure is needed, with the true output going to the Case Selector Terminal. Then, I want all this happening in a loop. Let’s Disable Indexing, because we want to bring in the entire array, and wire the output of the Build Array function to the border of the loop.

Now, each loop iteration, I want that new random number, if it passes the threshold, to be added to the existing array. So that means I need a Shift Register. Right click, Replace with Shift Register. And my cursor wants me to select the Output Tunnel to correspond to the right Shift Register, so here it is. Now the output of the Shift Register will be the desired array, and then we have a hollow tunnel because in the false case, we don’t want to concatenate anything. So I’ll just wire this existing array straight through.

How many times will I run this loop? Let’s just say 10 times. Let’s go and expand this and run it, and that looks good. Out of those ten iterations, however many values are above 0.5 will show up in here, and it varies because it’s random.

Now, that wasn’t terrifically difficult, but a bit time consuming. In LabVIEW 2012, though, it’s much easier. Watch this. I’ll make another For Loop, running ten times again, grab this little chunk of code, hold down CTRL, click and drag. Let’s give this a little space. And I’ll just take my random number value and wire it to the border, which would ordinarily just create an array of ten values, but in this case, I’m going to right click on the tunnel, go to Tunnel Mode, and then Conditional. And now below this, we have a Conditional input.

And we’ll wire the output of that Greater Than function right into there. And then from the output, Create an Indicator, expand it, run this a few times, and indeed, we’re getting essentially the same types of results. Now different random number generators will generate an array of different random numbers, as the name implies, but we see that these two loops are doing the same thing, except this one: much easier.

And there’s a good example program in the Example Finder. If you watched the last VI High, you saw Find Out of Range Elements. Here it is. And on its Block Diagram, we’re using the Conditional Terminal, and the tunnel we saw last time, which auto-concatenates our outputs. Very succinct.

We’ll be back next week with cool new LabVIEW 2012 features. See you then.

(end transcription)