Find shortest obstacle-free path between two points
Plan Obstacle-Free Path in Grid Map Using A-Star Path Planner
Plan the shortest collision-free path through an obstacle grid map using the A* path planning algorithm.
binaryOccupancyMap object with randomly scattered obstacles using the
rng('default'); map = mapClutter;
Use the map to create a
planner = plannerAStarGrid(map);
Define the start and goal points.
start = [2 3]; goal = [248 248];
Plan a path from the start point to the goal point.
Visualize the path and the explored nodes using the
show object function.
planner — A* path planner for grid map
A* path planner for a grid map, specified as a
start — Start position in grid or world
Start position in the grid or world, specified as a two-element vector of the form [row column], or [x y]. The location is in grid positions or world coordinates based on syntax.
goal — Goal position in grid or world
Goal position in the grid or world, specified as a two-element vector of the form [row column], or [x y]. The location is in grid positions or world coordinates based on syntax.
path — Shortest obstacle-free path
Shortest obstacle-free path, returned as an n-by-2 matrix. n is the number of waypoints in the path. Each row represents the [row column], or [x y] location of a waypoint along the solved path from the start location to the goal. The location is in grid positions or world coordinates based on syntax.
debugInfo — Debugging information for path result
Debugging information for the path result, returned as a structure with these fields:
PathCost— Cost of the path
NumNodesExplored— Number of nodes explored
GCostMatrix— GCost for each explored node
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Introduced in R2020b