Just a simple tool to print planned paths onto a map represented as an image.
This code has been tested on Python 3.7. Whilst compatibility with other versions of Python might be possible, it is by no means assured. Any issues arising as a result of using the wrong version of Python are, therefore, the user's own responsibility.
- PIL or Pillow
- Numpy
PathPlanPrinter is hosted in GitHub, so you can clone the repository as usual in Git:
git clone https://github.com/R012/PathPlanPrinter.git
As an alternative, you can download a zip file with the printer as a direct download (checkout out the green button in the PathPlanPrinter repository).
- Insert the Python source file defining you algorithm into
/src/
. Please, be aware that your algorithm must use the definition of a node included in the file/src/node.py
. For further details, please, refer to said source file and peruse the documentation included within. - Register your algorithm into the system. Import
path_planning
into your algorithm's source file, and run the functionregister_search_method
included in it. Please, keep in mind that you must indicate the module it is coming from. Therefore, if you do not use an alias forpath_planning
, you will need to call the function usingpath_planning.register_search_method
.- This function has no return value, and will throw verbose exceptions if any problems arise.
- This function expects two arguments:
- A string, identifying the algorithm. This string will be used later on, so making it easily identified is advised.
- The function implementing the algorithm. You should not provide a full function call, only its identifier. Thus, if, for example, your function is defined as
a_star(start, goal, grid, heur='naive')
, you would need to passa_star
as the second argument forregister_search_method
.- Note that, for the sake of enabling this registering function, it is mandatory that all algorithms take in a starting point, a goal and a heuristic identifier as parameters.
- Additionally, take into account that providing anything but a function as an argument will result in faulty behavior. The program will most certainly fail to execute properly, and result in an exception being thrown.
- Import your algorithm source file at the end of
path_planning.py
, belowaStar
anddijkstra
. This step is necessary for your algorithm to be loaded into the system. - Run
run_path_planning.py
using Python from the command line. Please, keep in mind that you must provide several named arguments for the program to run. Although they are listed in the present file, you may provide the-h
or--help
modifier to the python module in order to be presented with further information.--scenario
: Path to an image file. This image represents the map over which path planning will be executed. It can use any variation of colors, but bear in mind that black areas will be considered entirely inaccessible, and that darker colors will be considered harder to traverse than lighter ones.--algorithm
: String identifying the algorithm you wish to use. This string must have been defined usingpath_planning.register_search_method
, along with the corresponding function to call. Failing to comply with either of these conditions will result in an exception being launched.--heuristic
: String identifying the heuristic to be used while calculating the shortest path. Please, refer to/src/heuristics.py
and the subsectionRegistering new heuristics
found within this document for more information.--start
: Coordinates of the starting point for the path. Must be expressed as a tuple in"(x, y)"
format. Quotation marks are mandatory in order to ensure proper input. This point existing within the presented scenario is the user's responsibility. Providing an invalid point as argument will result in an exception being thrown.--finish
: Coordinates of the goal point for the path. Must be expressed as a tuple in"(x, y)"
format. Quotation marks are mandatory in order to ensure proper input. This point existing within the presented scenario is the user's responsibility. Providing an invalid point as argument will result in an exception being thrown. Additionally, the program may throw an exception if the goal cannot be reached from the previously defined starting point.--grid_size
: Mandatory only if using a grid. Do not use it alongside--navmesh
. It must be an integer defining the number of divisions to create in both axes over the map. Therefore, a value of, for example, 40, will result in the map being split into a 40x40 grid.--navmesh
: Mandatory only if using navigation meshes. Do not use it alongside--grid_size
. It must be a path to a JSON file defining a navigation mesh for the map. Positions must be expressed in pixels. Ensuring proper definition of the navigation mesh is the user's own responsibility.
- The resulting path will be stored under the
/out/
folder, as an image displaying the path over the provided map.
- Define a function for the new heuristic within
/src/heuristics.py
. Please, note that all heuristic must observe the following conditions:- They must take in two nodes as arguments. You may name them whatever you wish, as long as you keep in mind the underlying data structure.
For further information about nodes, refer to the file
/src/node.py
. - They must return a numeric value expressing the cost of moving from the first argument to the second.
- They must take in two nodes as arguments. You may name them whatever you wish, as long as you keep in mind the underlying data structure.
For further information about nodes, refer to the file
- Register the function using a call to
pp.register_heuristic
under the definition of the new heuristic. You must provide a string identifier, as well as the name of the function you are registering, as arguments.
Once both steps are completed, the heuristic will be registered for use automatically within the program. For examples on how to perform this operation, please, refer to /src/heuristics.py
.