Main Content

plan

R2026b

Plan 3D survey path through coverage area

Since R2023a

    Description

    [path,solninfo] = plan(planner,takeoff) plans a 3D survey path through the coverage area specified by the coverage planner planner. The UAV takes off from and lands at the specified position takeoff. The function returns the planned waypoints path and the solution information solninfo.

    example

    [path,solninfo] = plan(planner,takeoff,landing) additionally specifies a landing location.

    [path,solninfo] = plan(___,VerboseMode=mode)specifies the diagnostic printing mode, in addition to any combination of input arguments from previous syntaxes.

    Examples

    collapse all

    This example shows how to plan a coverage path that surveys the parking lots of the MathWorks Lakeside campus.

    Get the geodetic coordinates for the MathWorks Lakeside campus, then create the limits for our map.

    campusLocation = [42.3013 -71.375 0];
    latlim = [campusLocation(1)-0.003 campusLocation(1)+0.003];
    lonlim = [campusLocation(2)-0.003 campusLocation(2)+0.003];

    Create a figure containing the map with the longitude and latitude limits.

    fig = figure;
    gx = geoaxes(fig,Basemap="satellite");
    geolimits(latlim,lonlim)

    Get the outline of the first parking lot in longitude and latitude coordinates. Then create the polygon by concatenating them.

    parkingLot1Lat = [42.3028 42.30325 42.3027 42.3017 42.3019]';
    parkingLot1Lon = [-71.37527 -71.37442 -71.3736 -71.37378 -71.375234]';
    parkingLot1Poly = [parkingLot1Lat parkingLot1Lon];

    Repeat the process for the second parking lot.

    parkingLot2Lat = [42.30035 42.2999 42.2996 42.2999]';
    parkingLot2Lon = [-71.3762 -71.3734 -71.37376 -71.37589]';
    parkingLot2Poly = [parkingLot2Lat parkingLot2Lon];

    Create the coverage space with both polygons, and specify these properties:

    • Waypoints coordinates format: Geodetic

    • Reference location: MathWorks Lakeside campus location

    • Reference height: 25 meters

    • Width of sensor footprint: 20 meters

    parkingLotCoverage = uavCoverageSpace(Polygons={parkingLot1Poly,parkingLot2Poly},...
        UseLocalCoordinates=false,ReferenceLocation=campusLocation,...
        ReferenceHeight=25,UnitWidth=20);

    Show the coverage space on the map.

    show(parkingLotCoverage,Parent=gx);

    Figure contains an axes object with type geoaxes. The geoaxes object contains 4 objects of type line, text.

    Set the sweep angle for polygons 1 and 2 to 85 and 5 degrees, respectively, to have paths that are parallel to the roads in the parking lots. Then create the coverage planner for that coverage space with the exhaustive solver algorithm.

    setCoveragePattern(parkingLotCoverage,1,SweepAngle=85)
    setCoveragePattern(parkingLotCoverage,2,SweepAngle=5)
    lotPlanner = uavCoveragePlanner(parkingLotCoverage,Solver="Exhaustive");

    Set the takeoff position to a location in the courtyard, then plan the coverage path.

    takeoff = [42.30089 -71.3752, 0];
    [plannedPath,solution] = plan(lotPlanner,takeoff);
    hold on
    geoplot(plannedPath(:,1),plannedPath(:,2),LineWidth=1.5);
    geoplot(takeoff(1),takeoff(2),MarkerSize=25,Marker=".")
    legend("","","Path","Takeoff/Landing")
    hold off

    Figure contains an axes object with type geoaxes. The geoaxes object contains 6 objects of type line, text. These objects represent Path, Takeoff/Landing.

    This example shows how to plan a coverage path for a region in local coordinates and compares the results of using the exhaustive solver with the results of using the minimum traversal solver.

    Define the vertices for a coverage space. This cross-shaped region creates multiple sub-regions that the solvers must visit in sequence.

    area = [5 0; 5 15; 0 15; 0 25; 5 25; 5 40; 15 40; 15 25; 20 25; 20 40; ...
            30 40; 30 25; 35 25; 35 15; 30 15; 30 0; 20 0; 20 15; 15 15; 15 0];

    Because the vertices define a concave polygon and the coverage planner requires convex polygons, decompose the polygon into convex polygons. Then, create a coverage space with the polygons from the decomposition.

    polygons = coverageDecomposition(area);
    centroids = cellfun(@(p) mean(p(:,1)),polygons);
    [~,sortIdx] = sort(centroids);
    polygons = polygons(sortIdx);
    cs = uavCoverageSpace(Polygons=polygons);

    Define the takeoff and landing positions. Then, show the coverage space and plot the takeoff and landing positions.

    takeoff = [-5 20 0];
    landing = [40 20 0];
    show(cs);
    exampleHelperPlotTakeoffLandingLegend(takeoff,landing)

    Figure contains an axes object. The axes object contains 12 objects of type polygon, text, scatter. These objects represent Takeoff, Landing.

    Create a coverage planner with the exhaustive solver algorithm and another coverage planner with a minimum traversal solver algorithm.

    The exhaustive solver iterates through all permutations of sweep options to minimize the connection distance between regions. This makes it better suited for smaller or separated regions. The minimum traversal solver uses a recursive traversal through a graph of adjacent polygons, making it faster and better suited for interconnected regions.

    cpeExh = uavCoveragePlanner(cs,Solver="Exhaustive");
    cpMin = uavCoveragePlanner(cs,Solver="MinTraversal");

    Plan with both solver algorithms using the same takeoff and landing positions.

    [wptsExh,solnExh] = plan(cpeExh,takeoff,landing);
    [wptsMin,solnMin] = plan(cpMin,takeoff,landing);

    Show the planned path for both the exhaustive and the minimum traversal algorithms.

    figure
    show(cs);
    title("Exhaustive Solver Algorithm")
    exampleHelperPlotTakeoffLandingLegend(takeoff,landing,wptsExh)

    Figure contains an axes object. The axes object with title Exhaustive Solver Algorithm contains 13 objects of type polygon, text, scatter, line. These objects represent Takeoff, Landing, Path.

    figure
    show(cs);
    title("Minimum Traversal Solver Algorithm")
    exampleHelperPlotTakeoffLandingLegend(takeoff,landing,wptsMin)

    Figure contains an axes object. The axes object with title Minimum Traversal Solver Algorithm contains 13 objects of type polygon, text, scatter, line. These objects represent Takeoff, Landing, Path.

    Compare the visiting sequences chosen by each solver. The exhaustive solver finds the globally optimal ordering by evaluating all permutations, while the minimum traversal solver prioritizes traversing adjacent polygons and flies to the nearest unvisited polygon when no adjacent ones remain.

    disp("Exhaustive visiting sequence: " + mat2str(solnExh.VisitingSequence))
    Exhaustive visiting sequence: [1 2 4 5 3]
    
    disp("MinTraversal visiting sequence: " + mat2str(solnMin.VisitingSequence))
    MinTraversal visiting sequence: [1 2 3 4 5]
    

    Export the waypoints from the exhaustive solver to a .waypoints file with the reference frame set to north-east-down.

    exportWaypointsPlan(cpeExh,solnExh,"coveragepath.waypoints",ReferenceFrame="NED")

    Input Arguments

    collapse all

    Coverage path planner, specified as a uavCoveragePlanner object.

    UAV takeoff position, specified as a three-element vector.

    The format of this argument depends on the value of the UseLocalCoordinates property of the uavCoverageSpace object in the CoverageSpace property of planner.

    • If UseLocalCoordinates is true — Specify takeoff in the format [x y z], where x, y, and z are translations along the x-, y-, and z- axes, respectively, in meters.

    • If UseLocalCoordinates is false — Specify takeoff in the format [latitude longitude altitude], where latitude and longitude represent geodetic coordinates, in degrees, and altitude is the height of the position in meters.

    Data Types: double

    UAV landing position, specified as a three-element vector.

    The format of this argument depends on the value of the UseLocalCoordinates property of the uavCoverageSpace object in the CoverageSpace property of planner.

    • If UseLocalCoordinates is true — Specify landing in the format [x y z], where x, y, and z are translations along the x-, y-, and z- axes, respectively, in meters.

    • If UseLocalCoordinates is false — Specify landing in the format [latitude longitude altitude], where latitude and longitude represent geodetic coordinates, in degrees, and altitude is the height of the position in meters.

    Data Types: double

    Verbose mode, specified as a logical 0 (false) or 1 (true). A value of true specifies to output diagnostic information about the planning algorithm to the Command Window, while false specifies to output no information.

    Data Types: logical

    Output Arguments

    collapse all

    Waypoints in 3D space, returned as an N-by-3 matrix, where N is the number of waypoints that the coverage planner generates.

    Each row of the matrix contains the position of a waypoint. The format of the positions depends on the value of the UseLocalCoordinates property of the uavCoverageSpace object in the CoverageSpace property of planner.

    • If UseLocalCoordinates is true — Waypoint positions have the format of [x y z], where x, y, and z are translations along the x-, y-, and z- axes, respectively, in meters.

    • If UseLocalCoordinates is false — Waypoint positions have the format of [latitude longitude altitude], where latitude and longitude represent geodetic coordinates, in degrees, and altitude is the height of the position in meters.

    The first and last waypoints in the matrix correspond to the takeoff and landing positions of the UAV, specified by the takeoff argument or the takeoff and landing arguments, respectively

    For each other waypoint in the matrix, the altitude is the same as the ReferenceHeight property specified to the uavCoverageSpace object used to create the coverage path planner planner.

    Data Types: double

    Solution information, returned as a structure containing these fields:

    • VisitingSequence — M-element row vector denoting the visitation order of the polygons defined by the uavCoverageSpace object used to create planner, where M is the total number of polygons in the coverage space. For example, [2 1 3] indicates that the UAV first visits polygon 2, then polygon 1, and finally polygon 3.

    • SweepPattern — M-element row vector of integers denoting the sweep pattern for each polygon, where M is the total number of polygons in the coverage space. Each element is an integer in the range [1, 4] that indicates a sweep pattern:

      • 1 — Forward sweep pattern

      • 2 — Counter-clockwise sweep pattern

      • 3 — Reverse sweep pattern

      • 4 — Reverse counter-clockwise sweep pattern

      For example, [3 1 2] indicates that the UAV uses the reverse sweep pattern for polygon 1, the forward sweep pattern for polygon 2, and the counter-clockwise sweep pattern for polygon 3.

    • TransitionCost — Euclidean distance cost for transitioning between polygons, including takeoff and landing distance.

    • Takeoff — UAV takeoff location, returned in the same format as the takeoff argument.

    • Landing — UAV landing location, returned in the same format as the landing argument.

    Data Types: struct

    Extended Capabilities

    expand all

    Version History

    Introduced in R2023a

    expand all