Main Content

plan

Find shortest obstacle-free path between two points

Since R2020b

    Description

    example

    path = plan(planner,start,goal) finds the shortest obstacle-free path, path, between a specified start point, start, and goal point, goal, specified as [row column] in grid frame with origin at top-left corner, using the specified A* path planner planner.

    path = plan(planner,start,goal,'world') finds the shortest obstacle-free path, path, between a specified start point, start, and goal point, goal, specified as [x y] in world coordinate frame with origin at bottom-left corner, using the specified A* path planner planner.

    [path,debugInfo] = plan(___) also returns debugInfo that contains the path cost, number of nodes explored, and GCost for each explored node.

    Examples

    collapse all

    Plan the shortest collision-free path through an obstacle grid map using the A* path planning algorithm.

    Generate a binaryOccupancyMap object with randomly scattered obstacles using the mapClutter function.

    rng('default');
    map = mapClutter;

    Use the map to create a plannerAStarGrid object.

    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.

    plan(planner,start,goal);

    Visualize the path and the explored nodes using the show object function.

    show(planner)

    Input Arguments

    collapse all

    A* path planner for a grid map, specified as a plannerAStarGrid object.

    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.

    Example: [2 3]

    Data Types: double

    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.

    Example: [28 46]

    Data Types: double

    Output Arguments

    collapse all

    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.

    Data Types: double

    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

    Data Types: struct

    Extended Capabilities

    C/C++ Code Generation
    Generate C and C++ code using MATLAB® Coder™.

    Version History

    Introduced in R2020b