简体   繁体   中英

Java pathfinding in a real 2D area

I'm making a research project on orientating an RC car using raspberry pi and a LIDAR 2D scanner. Basically a car will run through the place with scanner to get 2D representation of the place, and then it will return to the starting point. After that you will be able to select a point in place and it would find a path in it. Since I'm pretty much a starter in programming it will be probably almost impossible to do that in 1 month but I'll try my best :) Well what I wanted to know for now is which algorithm for pathfinding should I use? Since the resolution of 2D place will be around 5000 x 5000 "pixels" that would represent the place in centimeters I believe that I'll need quite an efficient one. Is there any specific algorithm that would work fast enough on a raspberry pi to do the job almost instantly? If there is, is there any efficient implementation?

Some additional info: I'm using a “Pixel” 2D array in which values mean this:

EMPTY_SPACE = 0
FILLED_SPACE = 1
START_POINT = 2
END_POINT = 3
PROCESSING = 4
PROCESSED = 5
VISUAL_ASSISTANCE_POINTS = 6

Also they have second, optional parameter which means distance to the end point since I've found that necessary for the pathfinding.

You might find this a dupe of this: Pathfinding in 2D Arrays , but I didn't really find a solution for all of my questions since I'm searching for more specific answer.

EDIT:

I found this code implementing A* algorithm, but i find it very slow... Is there any way of speeding it up? I used image related below to test it out and it took around 80 minutes to solve.

A* pathfinding is one of your best bets. It's widely used in games where there is a need for finding a path between A and B in a 2D grid. It uses heuristics to identify favorable nodes (call them pixels if you want) and hence achieves a good performance (although depends on how well you choose your heuristics function). The implementation is easy enough compared to any specific/heavily optimized algorithms. In addition there are various implementations available.

As regards "almost instantly" speed, I doubt you can get that with the algorithm alone. When such performance is required, domain-specific modifications will need to be applied. One solution might be to pre-compute certain paths. The paths may represent a complete mapping of a single node to every other node (in your case with a 5000x5000 grid it is not practical). Alternatively pre-computed paths may treat a block of nodes in the grid as a single node, ie from area x,y in 0..10,0..10 any movement into area x,y in 10..20,0..10 use a single pre-computed path. This may not give you the best path but it will definitely be faster. As with virtually anything in computing, there's always the trade-off between memory and speed.

It is also worth clarifying whether "pixel" in your question refers to a single movement unit by the car. It may be the case that the area is 5000x5000 but the car actually occupies 50 pixels at a time. Then you might use a single node to represent 50 pixels to speed up computation and get more precise results.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM