LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Make one loop wait for another?

I'm trying to run two laser scanners, one in the X direction and one in the Y. I need them to work in sync, so after the X deflector travels all the way to a point, I need the Y to change positions, and then the X deflector scan again (sort of in a zig zag pattern). Right now I put each deflector in a different loop, and was thinking I could make the Y scanner "wait" for the X one to get in position, however, I'm not sure if that would even work. I'm running on my R series multi function RIO, and have attached a snippet some code I've started. Thank you for any advice!

0 Kudos
Message 1 of 4
(2,561 Views)

First.  Index Array is expandable!  Delete all but one.  Drag the bottom border downwards.  You can even get rid of all the constants because it will default to index 0, 1, 2, 3.....  Less nodes, less wiring.

 

There are several ways of communicating between loops telling one to wait for another.  Look at Notifiers or Queues.

0 Kudos
Message 2 of 4
(2,555 Views)

Are the DIO2 through DIO16 channels of a 16-bit DIO Register?  Instead of splitting all of the bits out one at a time, set DIO1 (why are they numbered 1..16 instead of 0..15?) as appropriate and write the register all-at-once as a U16.  [In most NI DAQ devices, a DIO device can be addressed either as a Port (multiple lines) or as individual Lines (I hope I didn't get Ports and Lines mixed up ...][nope, MAX agrees with this terminology].

 

There's a function on the Boolean palette that turns a number into an array of Booleans.  You have 14 "bits", and want them to go into Bits 1..15, so you need to shift all the bits up by one.  If you think of this as a number, this is a "multiply by 2", and if you consider it as an array of 16 booleans, there's an Array operation "Rotate 1D Array" (you pays your money, you takes your choice).

 

Why bother to worry about this?  Makes your Block Diagram much neater (and smaller), may "map" better with what you are really trying to do (I'm assuming that you are not turning bits on and off completely independently).

 

How do you discover these things?  Pay (much) more attention to what you want to do, and put off as long as possible how you are going to do it.  So thinking of 14 bits as a "thing", manipulating it, and keeping it together may lead you to the "all-at-once" idea.

 

Bob Schor

0 Kudos
Message 3 of 4
(2,534 Views)

I'm not sure how the code you attached relates to the problem you described, but to create a zig-zag pattern for 2D translation stage motion, you can use nested loops.

 

Put your X loop inside your Y loop, then change the Y value after the X For loop finishes. In order to avoid moving all the way back to the beginning of your X values (if that's not desired) you can invert the array used as the input to the X loop. Be careful - when I first did this I tried flipping the array on each iteration but didn't use a shift register. You need to either use a SR and flip every time, or use a tunnel and flip only half of the time. I don't think any of that is problematic on RIO.


GCentral
0 Kudos
Message 4 of 4
(2,491 Views)