06-28-2013 12:30 PM
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.
Solved! Go to Solution.
06-28-2013 12:43 PM - edited 06-28-2013 12:44 PM
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.
06-28-2013 12:52 PM
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!
06-28-2013 01:39 PM
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.
06-28-2013 01:42 PM
@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.
06-28-2013 02:00 PM
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
06-28-2013 02:56 PM
@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.
06-28-2013 04:27 PM
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.
06-28-2013 11:10 PM
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.
07-01-2013 07:17 PM
Nicely done. I added waveform charts and and XY graph so you can see see what is happening.
Lynn