LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Field with obstacles

The field is 10*10 array composed of color boxes. Empty field is color boxes of one color. Obstacles are another color. The initial and final points and number of obstacles are set manually.

My question is how to build the shortest way from initial to final point avoiding obstacles?

0 Kudos
Message 1 of 6
(3,063 Views)

How are you defining "shortest way"? Do the paths (ways) need to travel through the center of each box or are diagonal lines permitted? In the image below two paths shown connect the initial and final points while containing three boxes each. Two other paths which are not straight also connect those points with three boxes. Which is the shortest? If multiple paths have the same length, do you need to identify all of them?

 

The use of local variables in LabVIEW for passing data around is discouraged. It breaks dataflow, is prone to race conditions, may make extra copies of the data, and forces the thread to execute in the UI thread.

 

The number of obstacles control terminal should probably be outside the loop since it does not make sense to change it while running. It should also be an integer datatype. Then do the =0? comparison outside the loops. Enclose the loops inside a case structure. wire the comparison output to the selection terminal of the case structure so that the code only executes if number of obastacles > 0.  Equal comparisons on floating point numbers are not recommended because of the way the values are stored in binary. Search the Forums for "floating point comparisons" for more information.

 

Lynn

 

obstacles.png

 

No locals.png

0 Kudos
Message 2 of 6
(3,041 Views)

The shortest can be one, but it shouldn't be 4 boxes or more for your example. And the diagonals lines are not permitted. 

Thanks for your remarks, I will take them into account

0 Kudos
Message 3 of 6
(3,027 Views)

Look up the A* algorithm.  It is usually used for pathfinding applications like this.  To make it work, you will need a priority heap.  You can get one here.  You can probably ignore the comments on why the implementation is not a queue, since, for pathfinding, you don't care about the order of two elements, just their relative rank.  Good luck.  Even with the heap, it will take some coding to get this to work.

Message 4 of 6
(3,003 Views)

It almost works, but when there are obstacles it stops. How to solve this problem?

0 Kudos
Message 5 of 6
(2,921 Views)

Hi artem7,

Here is a link that goes over how the A* algortihm works. Though the VI attached would need the robotics module to run. The basic concepts are explained though and may help you better understand the algorithm and its implementation.

Paolo F.
National Instruments
Applications Engineer
Message 6 of 6
(2,850 Views)