LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Newbie help with a "simple" VI.

Hi all,

 

I need to write a VI with the following specifications:

 

Input: An integer

 

Output:  Two integers mapping the input integer to a coordinate system based on the following mapping system:

 

 

 22 23 24 25 ..

 21 06 07 08 09 

 20 05 00 01 10 

 19 04 03 02 11 

 18 44 45 46 12 

 17 16 15 14 13 

 

For instance, an input of 0 would be an output of (0,0). An input of 5 would be an output of (-1, 0)  and an input of 23 would be an output of (-1, 2).

 

 As you can see it is just a clockwise rectangular coordinate system starting with 0 in the middle.

 

I am new to LabVIEW and am having trouble visualizing how to do this. If I were in a text based language, I would do something like create a 2d array of booleans representing my coordinate system, and travel around in a clockwise circle marking each as true until I reached the input number, then output my current row and column. Does anyone have any suggestions of the best way to do it in LabVIEW? (In case you were curious why I don't stick with a language I know-- LabVIEW has the drivers for the motion controller I am using).

 

I know this is not as complex as many of the questions here, but any help or tips would be appreciated! 

 

 

0 Kudos
Message 1 of 4
(3,281 Views)

Here is one way to do it. The constants in the loop represent the offset of your starting point, in this case the 0 value at 2,2.

 

array search.PNG

 

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



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

22 23 24 25 ..

 21 06 07 08 09 

 20 05 00 01 10 

 19 04 03 02 11 

 18 44 45 46 12 

 17 16 15 14 13 

 

 As you can see it is just a clockwise rectangular coordinate system starting with 0 in the middle.

 
--- Actually, I'm having trouble seeing that, as the "44 45 46" seems out of place.
 
--- I'll assume that is an error in your table, not an error in your words.
 
 
 
 I know this is not as complex as many of the questions here, but any help or tips would be appreciated! 
 
--- Actually, this sort of thing is fun for me, because I get to be creative.
 
Consider the rules for generating a spiral pattern like that. 
 
Let's use a complex number to represent a position: Imag = row, Real = column
 
Let's use a complex number to represent a DIRECTION: 0-1i = up, 1+0i = right, 0+1i = down, -1+0i = left
 
Let's remember that multiplying a complex number by 0+1i is a turn of 90 degrees.
 
Let's start out with a position and a direction:
 
POSITION = 2+2i
DIRECTION = 0-1i  (up)
 
Let's start out with an array of -1 numbers (meaning empty cells)
 
To generate the array is then simple:
FOR i = 0 to N-1  // however many cells needed
    CellArray[POSITION.imag, POSITION.real] = i  // put a number into the cell.
    TURNRIGHT = DIRECTION * 0+1i //  look 90 degrees right
    if CellArray[TURNRIGHT.imag, TURNRIGHT.real] < 0  // if that cell is empty
        DIRECTION = TURNRIGHT         // turn right
    end if
    POSITION = POSITION + DIRECTION // move to next cell
 end for
 
The upper FOR loop in the code demonstrates this.
 
The lower WHILE  loop in the code is basically the same, but it:
  • stops when it reaches the input number
  • Subtracts the starting position from the current position
  • Converts the complex number to X and Y values
I believe your third example ("an input of 23 would be an output of (-1, 2).") is wrong, because of the 44-46 problem.
 
Here is the code, attached is a VI.
Spiral.PNG 
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 3 of 4
(3,237 Views)

Of course, I don't know what you are doing with this, but I would point out that whether you are generating the table, or just doing the lookup - the "30" constant, the "5x5" array initializer, and the "2+2i" starting point should all be related: computed from something common, not independent constants as I showed them.

 

 

More fun: attach an intensity graph to the generated array:

Spiral2.PNG 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 4 of 4
(3,235 Views)