LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Beginner Question: Won't execute index to nested while loop

Problem:

 

I have a nested while loop inside a for loop. The for loop runs over and over from 0 to 587. I want the while loop to only execute when the for loop hits 587 by means of a continue condition which is on when 587 = [ i ], the for loop iteration number. However when I try to change the value sent to the while loop from 588 none of the probes execute. This is bad because the index only runs from 0 to 587 and never equals 588.

 

Context:

 

This is for real time video analysis. Trying to convert a 658 x 492 color video feed frame by frame into low resolution grayscale video. With this index error the output is currently the top left 1/4 of the image, repeated in a 2x2 grid on the image display.

 

The VI is attached. I'm very appreciative of your thoughts on this.

0 Kudos
Message 1 of 9
(3,193 Views)

The wire in the bottom of the for loop with the two large divets is the one I want to replace numeric 588 with 587. When I do this it will no longer execute. Seems like any arbitrary number 0-587 should be able to go to the while loop no problem (at this iteration in the for loop, output the image).

0 Kudos
Message 2 of 9
(3,189 Views)

When you replace the 588 with 587, or any other value that the iteration counter will reach, the while loop executes as expected.  The problem is that since you've then wired what is essentially a constant true to the while loop continue condition, the while loop never exits.  If you only want that while loop to execute once, then there's no need for a while loop at all.  A case structure is the correct structure here.

 

EDIT: By the way, consider using the LabVIEW debugging features to find this sort of problem.  If you turn on Execution Highlighting (the "light bulb" icon in the toolbar) and set the comparison to a low iteration, you will see what's wrong here very quickly.

Message 3 of 9
(3,185 Views)

Now with the case structure instead of the while loop, the iteration number remains at [ i ] = 587. The for loop is completely executing before sending [ i ] to the case structure; how can I make it send each iteration? I had this problem before when I had the while loop outside the for loop but inside the while loop inside had fixed that.

 

0 Kudos
Message 4 of 9
(3,181 Views)

With the case structure:

0 Kudos
Message 5 of 9
(3,180 Views)

If you want the contents of the case structure to execute on every iteration of the for loop, then there's no need to wrap it in any structure at all - just put it inside the for loop!  What are you actually trying to do here?

 

What's the point of the while loop that contains the for loop (the inner one, not the outer one)?  Looks to me like that should be removed.

0 Kudos
Message 6 of 9
(3,174 Views)

The for loop is responsible for processing a frame. At the completion of the execution of [ i ] from 0 to 587, the replace array VI outputs the final product of the frame. So every time [ i ] = 587, the replace array VI needs to send its array to the arraytoimage, which in turn must send the image to the image display.

 

I got rid of the while loop and replaced it with the case structure. 

 

Maybe the problem is with the false case of the case structure? I want to continue outputting the same image for the next [0, 586] each time after it sends an updated image on the [ i ] = 587 iteration.

0 Kudos
Message 7 of 9
(3,172 Views)

And I'm pretty sure the for loop can process an entire frame before the outer while loop hands it the next frame. That wouldn't be the problem would it?

0 Kudos
Message 8 of 9
(3,171 Views)

You're looping 588 times, and after this is done you want to do ArrayToImage, then repeat the process for the next image? Now look at the part between the commas. You want to do it after the loop. Place ArrayToImage outside the inner loop. 🙂

 

/Y 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 9 of 9
(3,163 Views)