From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

2-D scanning

Hi everyone,

 

I've been writing a code in LabView for 2-D scanning purposes. I want the code to run in such a way that it moves in y from 0 to the maximum limit 75 microns, then moves 1 micron in x, then moves from 75 to 0 microns in y again, then 1 in x, then 0 to 75 in y. At the moment, my code seems to be running 1 in x, 0 to 75 in y, then 1 in x, then again 0 to 75 in y instead of 75 to 0. I want it to increment in y then decrement in y instead of being reset to 0. Any ideas?

 

I have attached an image of the block diagram.

0 Kudos
Message 1 of 5
(2,560 Views)

Hi tan,

 

when your code should execute several exactly defined steps you often can use the Statemachine architecture!

 

Make a statemachine with (atleast) those steps:

- move Y upwards (to 75)

- increment X

- move Y backwards (to 0)

 

Alternatively you could use some simple arithmetic/comparison: IF X is even THEN increment Y ELSE decrement Y…

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(2,544 Views)

Hi,

 

Thank you for your reply. 

 

I don't think I am familiar with a statemachine, could you tell me a bit more on this please?

 

At the moment, I've put this condition on the iteration. So if the iteration is even, the code subtracts one from y and if it's odd then the code adds one but for this to work I think I need to put some condition on the initial and final position too. Since the user sets the initial position, I have a feeling this is why the code returns to that initial position everytime. So I was thinking of placing a condition which would set the final position as the initial position when the iteration is even but I have no idea how to do that. As you can see from my code, both final and initial position are controls.

 

Many thanks,

 

Tan

0 Kudos
Message 3 of 5
(2,516 Views)

Anybody?

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

Hello tan893,

 

As GerdW mentioned previously, a state machine design pattern would be a convenient way to organize your program. State machines combine while loops with case structures, shift registers, and enumerators to create a very powerful framework for creating programs in LabVIEW.

 

1) This document goes into the details of how state machines function and how to implement them:

http://www.ni.com/white-paper/3024/en/

 

2) Shift registers can be used to pass the x and y position coordinates between iterations of the loop (state machine or not). You can learn more about shift registers at:

http://www.ni.com/gettingstarted/labviewbasics/shiftregisters.htm

 

3) Enumerators are useful for identifying the states of your state machine. For your 2D application the enumaerator states could be initialization, increase y, increase x, decrease y, and close. You can learn more about enumerators at: http://zone.ni.com/reference/en-XX/help/371361J-01/lvconcepts/fp_controls_indicators/#Enumerated_Typ...

 

Implementing a state machine will restructure your current code, but it will also make future changes easier to implement because new states can be added more easily. I hope these documents help you achieve the desired functionality for x and y positioning. 

Message 5 of 5
(2,472 Views)