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: 

Array problems

Solved!
Go to solution

Hello NI Forums, I currently develping a VI to specify voltages that will be send to device which will be directing two mirrors. The idea and set-up are pretty basic, but actually programming it is an issue. The X and Y arrays both have elements that correspond to a point on a coordinate grid. For example, my elements in my grid for the X might be [-2,-1,0,1,2] and my Y could be [-2,-2,-2,-2,-2]. The problem however is that I need one more X and Y value so I can step down in the grid and trace back in the X array. For example, my next row of elements will be [-2,-1,0,1,2] for X and [-3,-3,-3,-3,-3] for Y. However,the way my program is written my last Y value is one less than than previous element. Thus, ideally I would form an array that would have an extra X element which would correspond to the step down in voltage on the Y axis. This would be ideal : [-2,-1,0,1,2,2] for x and [-3,-3,-3,-3,-3,-4] for y. 

 

Sorry for this question is a little poorly worded. The application of this program is quite simple, but I seem a little stumped. 

 

 

0 Kudos
Message 1 of 10
(3,069 Views)

Try to place reasonable defaults in all your controls. Make the current values default (menu...edit...make current values the default), then save and re-attach your VI.

0 Kudos
Message 2 of 10
(3,062 Views)

Attached are my default values. Using the default values, I can describe my problem better.

If the elements in the array correspond to coordinate points on an X-Y plane, then my issue is that for the rows I need an extra column that repeats the last X value in the row and the corresponding Y value is one less than the previous Y value in that row. Hopefully that makes sense.

 

In addition, I am trying to think of a way to switch the sign on every other X row. That way if you were to track each point with a line the pattern would be serpentine. 

 

Thanks!

0 Kudos
Message 3 of 10
(3,056 Views)

Just use the Ramp Pattern VI for your arrays.  I don't see a point in creating a large array for your X and Y when they are just repeating.  Generate a ramp for your X and another ramp for your Y.  You can then use a FOR loop inside of another FOR loop.  Have the outer FOR loop iterate on the Y and the inner FOR loop iterate on the X.  With that setup, you can set up your coordinates and have much smaller arrays.

 

Give this VI a try to see if it helps simplify your program.


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 10
(3,041 Views)

@crossrulz wrote:

Give this VI a try to see if it helps simplify your program.


Your y ramp has zero elements using the defaults control values.

0 Kudos
Message 5 of 10
(3,036 Views)
Solution
Accepted by topic author UWEC977

So you want to begin at (Start X, Start Y) then proceed to (Start X+Step X, Start Y). Continue to (Last X, Start Y). Then go to (Start X, Start Y+Step Y) and increment through the X array again. Repeat for all Y.

 

Is this a correct understanding of what you want?

 

If so, you can do this with one array of the X values and one array of the Y values, or even with no arrays at all.  Create a state machine with states for Scan X, Retrace, and whatever states are needed for intialization and shutdown.  Have two shift registers to keep track of the X and Y values or indexes. Each time through the Scan X state you increment X. When X reaches the maximum value or the index reaches the last X index, go to the Retrace state. It increments Y and resets X to Start X or the equivalent for the indexes. When you reach Max X and Max Y, go to the Shutdown state or start over.

 

No complicated array manipulation required.

 

Lynn

0 Kudos
Message 6 of 10
(3,030 Views)

@altenbach wrote:

@crossrulz wrote:

Give this VI a try to see if it helps simplify your program.


Your y ramp has zero elements using the defaults control values.


Yes, I realized that after posting.  The default Y Step should be -1.


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 10
(3,016 Views)

Thanks for all the input. Lynn, the standard state machine seems like it would give me the best control over my device, because the user has to specify how many points in this grid. I will give this a shot and post here again if I have any issues.

0 Kudos
Message 8 of 10
(3,005 Views)

I think the attached VI is the solution to my program. I used constants as the defaults this time. The values varying from -5 to 5 for X and 5 to -5 for Y. Once Y reaches -5 the program stops. 

0 Kudos
Message 9 of 10
(2,987 Views)

Nicely done.  I added waveform charts and and XY graph so you can see see what is happening.

 

Lynn

0 Kudos
Message 10 of 10
(2,925 Views)