LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to connect while loops (in series, not parallel)

Hello, I am new to LabVIEW programming; I am trying to figure out how to connect 2 while loops in series.

 

I'm trying to get the following :

 

1. all the code inside Loop A executes

2. end condition on Loop A is met

3. all the code inside Loop B executes

4. end condition on Loop B is met

 

I do not want any code in Loop B to start until Loop A finishes.

 

I've read multiple sections in my LabVIEW book, done research on NI forums as well as online in general, but I must be missing something pretty fundamental. This is a very easy thing to do I would think, but I can't figure it out.

 

I've tried the following thus far :

 

1. using the Connect Wire tool to connect the while loops

- if I connect wall of Loop A to wall of Loop B, I get an error saying I'm stringing an input to another input

- so I connect the "end condition block" of Loop A to Loop B, which works, but when I run the program, only Loop B executes (it skips Loop A); what's more, I don't necessarily want to "pass" any information from Loop A to Loop B - I just want Loop B to wait on executing until Loop A finishes

2. using the Flat Sequence Structure and placing Loop A in the left one, and Loop B in the right one

- no errors, but only Loop B executes

3. using the Stacked Sequence Structure, placing Loop A in Frame 0, and Loop B in Frame 1

- no errors, but only Loop B executes

 

Just to make it simpler, I even tried putting in basic code (without loops of any kind) into 2 frames of the Flat Sequence Structure. But, only the right frame of code executes; it ignores my code in the left frame (the frame that should execute first).

 

Thanks in advance for assistance.

0 Kudos
Message 1 of 7
(3,843 Views)
Yes, you are missing something very basic. All three solutions you gave will woek. Show your code.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 7
(3,832 Views)

Here is my code.

 

pic.PNG

 

The Flat Sequence Structure is inside of a larger container which executes when I press the START button on the Front Panel.

 

Loop A on the left; Loop B on the right.

 

Let me explain the code inside of these loops a little bit. This code controls a positioner device. The 6 orange inputs represent X, Y, Z, theta_X, theta_Y, and theta_Z (from top to bottom). So they represent the 6 degrees of freedom (translation & rotation) for the positioner device. Loop A is supposed to continuously move the positioner in the Z direction and then stop once it has moved 2 mm. Loop B is supposed to continuously move the positioner in the X direction and then stop once it has moved 2 mm. So the end result will be that the positioner first moves up 2 mm, then to the right by 2 mm.

 

Here is what I'm trying to get the code to do :

 

1. press START

2. Loop A executes

3. Loop A completes

4. Loop B executes

5. Loop B completes

6. sequence ends

 

As mentioned before, I do not want Loop B to start until Loop A finishes. That is, I do not want my positioner device moving to the right until it has finished moving up.

 

In the current setup (Flat Sequence Structure), only Loop B executes. That is, my positioner device only moves to the right by 2 mm, and does not move up. I can clearly see this when I run the program. If I place a Diagram Disable Structure over Loop B, leaving everything else the same, then only Loop A executes (confirming that the code does work). That is, I can see my positioner move up by 2 mm, but it does not translate to the right. So, it seems to me that it is "skipping" Loop A when both loops are placed inside this Flat Sequence Structure. I observe the same behavior with the Stacked Sequence Structure, as well as simply using the Connect Wire tool to connect the output of Loop A to the input of Loop B.

0 Kudos
Message 3 of 7
(3,820 Views)

I think what is actually happening is you are moving your Z axis back to 0.  Therefore it just looks like only loop B ran.  Try setting the value for Z to be 2 in loop B.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 7
(3,814 Views)

Okay, I just did that and it definitely changed. Good sign!

 

Although now, it moves to the position (0.002, 0, 0.002, 0, 0, 0) in 1 motion. That is, it translates along X and along Z simultaneously.

 

It appears like LabVIEW is still trying to run the 2 loops in parallel...

0 Kudos
Message 5 of 7
(3,807 Views)

Looking at this code a little closer, I think you will be much better off using a single FOR loop.  What you do is make two arrays of what the positions should be for each iteration, 1 array for the X and another for the Z.  Then you just autoindex on those arrays and move as needed.  Code will become simpler, more scalable, and more reliable.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 7
(3,806 Views)

@anblan25 wrote:

Okay, I just did that and it definitely changed. Good sign!

 

Although now, it moves to the position (0.002, 0, 0.002, 0, 0, 0) in 1 motion. That is, it translates along X and along Z simultaneously.

 

It appears like LabVIEW is still trying to run the 2 loops in parallel...


It is more likely that your device just can't move fast enough for your commands.  It is hard to say since I have no clue what device you are using or what that subVI does.  Try running with highlight execution on and see what happens.  You might just need to add a delay to your loop(s).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 7
(3,798 Views)