メインコンテンツ

minsnappolytraj

Generate minimum snap trajectory through waypoints

Since R2021b

    Description

    [q,qd,qdd,qddd,qdddd,pp,tPoints,tSamples,status] = minsnappolytraj(waypoints,timePoints,numSamples) generates a minimum snap polynomial trajectory that passes through a set of input waypoints with their corresponding time points. The function returns positions, velocities, accelerations, jerks, and snaps at the number of samples that you specified. The function also returns the piecewise polynomial of the trajectory, time points for the output trajectory, time points for the output trajectory samples, and the trajectory generation status.

    example

    [q,qd,qdd,qddd,qdddd,pp,tPoints,tSamples,status] = minsnappolytraj(___,Name=Value) specifies options using one or more name-value arguments in addition to the input arguments from the previous syntax. For example, VelocityBoundaryCondition=[1 0 -1 -1; 1 1 1 -1] specifies the velocity boundary conditions for each waypoint of the minimum snap trajectory.

    Examples

    collapse all

    Specify the trajectory waypoints in these XY coordinates:

    1. (1,0) m

    2. (4,1) m

    3. (4,2) m

    4. (3,4) m

    5. (-2,3) m

    6. (0,1) m

    wpts = [1 4 4 3 -2 0; 0 1 2 4 3 1];

    Specify the time points for trajectory waypoints, starting at 0 seconds at the first waypoint, to 5 second at the last waypoint, at 1 second increments.

    tpts = 0:5;

    Specify the number of samples in the output trajectory.

    numsamples = 100;

    Specify the maximum number of iterations, and the maximum solver time.

    MaxIter = 1600;
    MaxTime = 15;

    Compute minimum snap trajectory.

    [q,qd,qdd,qddd,qdddd,pp,timepoints,tsamples,status] = minsnappolytraj(wpts,tpts,numsamples,TimeAllocation=true,MaxNumIterations=MaxIter,MaxSolverTime=MaxTime);

    Plot the x- and y-positions of the minimum snap trajectory with respect to the output trajectory sample time.

    plot(tsamples,q)
    hold on
    plot(timepoints,wpts,"x")
    xlabel("Sample time (s)")
    ylabel("Position (m)")
    legend("X-positions","Y-positions")
    grid on
    hold off
    title("Minimum Snap Trajectory Position vs Sample Time")

    Figure contains an axes object. The axes object with title Minimum Snap Trajectory Position vs Sample Time, xlabel Sample time (s), ylabel Position (m) contains 4 objects of type line. One or more of the lines displays its values using only markers These objects represent X-positions, Y-positions.

    Plot the minimum snap trajectory in the 2-D plane, and show the waypoints.

    plot(q(1,:),q(2,:),".b")
    hold on
    plot(wpts(1,:),wpts(2,:),"or")
    xlabel("X-positions (m)")
    ylabel("Y-positions (m)")
    legend("Minimum Snap Trajectory Samples","Waypoints")
    grid on
    hold off

    Figure contains an axes object. The axes object with xlabel X-positions (m), ylabel Y-positions (m) contains 2 objects of type line. One or more of the lines displays its values using only markers These objects represent Minimum Snap Trajectory Samples, Waypoints.

    Show the trajectory generation status. The status indicates that the function is able to converge to an optimal trajectory without singularity, and within the maximum number of iterations and solver time.

    status
    status = struct with fields:
             Singularity: 0
        MaxNumIterations: 0
           MaxSolverTime: 0
    
    

    Input Arguments

    collapse all

    Trajectory waypoints, specified as an n-by-p matrix. n is the number of dimensions in each waypoint, and p is the number of waypoints. Each column of the matrix specifies the position of a waypoint. Units are in meters.

    Example: [2 5 8 4; 3 4 10 12] creates 2-D waypoints located at the coordinates (2, 3), (5, 4), (8, 10), and (4, 12).

    Data Types: single | double

    Time points for the trajectory waypoints, specified as a p-element row vector where p is the number of waypoints. Each element in the vector corresponds to the desired time of arrival at the corresponding waypoint specified to the waypoints argument. Units are in seconds.

    Example: [1 2 3 5] specifies time points of 1, 2, 3, and 5 seconds for waypoints 1, 2, 3, and 4, respectively.

    Data Types: single | double

    Number of output trajectory samples, specified as a positive integer.

    Data Types: single | double

    Name-Value Arguments

    collapse all

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: minsnappolytraj(waypoints,timePoints,numSamples,VelocityBoundaryCondition=[1 0 -1 -1; 1 1 1 -1]) generates a two-dimensional minimum snap trajectory and specifies the velocity boundary conditions in each dimension for each waypoint.

    Velocity boundary conditions, specified as an n-by-p matrix. n is the number of dimensions in each waypoint, and p is the number of waypoints. Each column of the matrix specifies the velocity boundary condition of the corresponding waypoint. Units are in m/s.

    If you do not specify this argument, the function sets the velocity boundary condition at the first and last waypoints to 0 m/s, and the velocity boundary condition at the other waypoints to NaN.

    Example: VelocityBoundaryCondition=[1 0 -1 -1; 1 1 1 -1] specifies velocity boundary conditions of (1, 1), (0, 1), (–1, 1), (–1, –1) m/s for waypoints 1, 2, 3, 4, and 5, respectively.

    Data Types: single | double

    Acceleration boundary conditions, specified as an n-by-p matrix. n is the number of dimensions in each waypoint, and p is the number of waypoints. Each column of the matrix specifies the acceleration boundary condition of the corresponding waypoint. Units are in m/s2.

    If you do not specify this argument, the function sets the acceleration boundary condition at the first and last waypoints to 0 m/s2, and the acceleration boundary condition at the other waypoints to NaN.

    Example: AccelerationBoundaryCondition=[1 0 -1 -1; 1 1 1 -1] specifies acceleration boundary conditions of (1, 1), (0, 1), (–1, 1), (–1, –1) m/s2 for waypoints 1, 2, 3, 4, and 5, respectively.

    Data Types: single | double

    Jerk boundary conditions, specified as an n-by-p matrix. n is the number of dimensions in each waypoint, and p is the number of waypoints. Each column of the matrix specifies the jerk boundary condition of the corresponding waypoint. Units are in m/s3.

    If you do not specify this argument, the function sets the jerk boundary condition at the first and last waypoints to 0 m/s3, and the jerk boundary condition at the other waypoints to NaN.

    Example: JerkBoundaryCondition=[1 0 -1 -1; 1 1 1 -1] specifies jerk boundary conditions of (1, 1), (0, 1), (–1, 1), (–1, –1) m/s3 for waypoints 1, 2, 3, 4, and 5, respectively.

    Data Types: single | double

    Snap boundary conditions, specified as an n-by-p matrix. n is the number of dimensions in each waypoint, and p is the number of waypoints. Each column of the matrix specifies the snap boundary condition of the corresponding waypoint. Units are in m/s4.

    If you do not specify this argument, the function sets the snap boundary condition at the first and last waypoints to 0 m/s4, and the snap boundary condition at the other waypoints to NaN.

    Example: SnapBoundaryCondition=[1 0 -1 -1; 1 1 1 -1] specifies snap boundary conditions of (1, 1), (0, 1), (–1, 1), (–1, –1) m/s4 for waypoints 1, 2, 3, 4, and 5, respectively.

    Data Types: single | double

    Time allocation flag, specified as a logical 0 (false) or 1 (true). Enable this flag to add the total segment time to the cost function. For more details, see Algorithms.

    Data Types: logical

    Weight of the total segment time in the cost function, specified as a positive scalar.

    Dependencies

    To use this argument, you must specify the TimeAllocation argument as true.

    Data Types: single | double

    Minimum segment time, specified as a positive scalar or (p–1)-element row vector. Units are in seconds.

    • To set a uniform minimum segment time for all segments, specify the minimum segment time as a positive scalar.

    • To set a different minimum segment time for each segment, specify the minimum segment time as a (p-1)-element row vector, where p is the number of trajectory waypoints.

    Dependencies

    To use this argument, you must specify the TimeAllocation argument as true.

    Data Types: single | double

    Maximum segment time, specified as a positive scalar or (p–1)-element row vector. Units are in seconds.

    • To set a uniform maximum segment time for all segments, specify the minimum segment time as a positive scalar.

    • To set a different maximum segment time for each segment, specify the minimum segment time as a (p-1)-element row vector, where p is the number of trajectory waypoints.

    Dependencies

    To use this argument, you must specify the TimeAllocation argument as true.

    Data Types: single | double

    Maximum time for the solver, specified as a positive scalar. Units are in seconds.

    Dependencies

    To use this argument, you must specify the TimeAllocation argument as true.

    Data Types: single | double

    Maximum iterations for the solver, specified as a positive scalar.

    Dependencies

    To use this argument, you must specify the TimeAllocation argument as true.

    Data Types: single | double

    Output Arguments

    collapse all

    Output trajectory sample positions, returned as an n-by-m matrix. n is the number of dimensions in the trajectory, and m is the number of output trajectory samples. Each column of the matrix contains the location of a trajectory sample. Units are in meters.

    Data Types: single | double

    Output trajectory sample velocities returned as an n-by-m matrix. n is the number of dimensions in the trajectory, and m is the number of output trajectory samples. Each column of the matrix contains the velocity of a trajectory sample. Units are in m/s.

    Data Types: single | double

    Output trajectory sample acceleration, returned as an n-by-m matrix. n is the number of dimensions in the trajectory, and m is the number of output trajectory samples. Each column of the matrix contains the acceleration of a trajectory sample. Units are in m/s2.

    Data Types: single | double

    Output trajectory sample jerks, returned as an n-by-m matrix. n is the number of dimensions in the trajectory, and m is the number of output trajectory samples. Each column of the matrix contains the jerk of a trajectory sample. Units are in m/s3.

    Data Types: single | double

    Output trajectory sample snaps, returned as an n-by-m matrix. n is the number of dimensions in the trajectory, and m is the number of output trajectory samples. Each column of the matrix contains the snap of a trajectory sample. Units are in m/s4.

    Data Types: single | double

    Output trajectory piecewise polynomials, returned as a structure that contains these fields:

    FieldDescription
    form'pp' for piecewise polynomial.
    breaksStart and end times of each interval of the piecewise trajectory, returned as a p-element vector. p is the number of waypoints in the trajectory.
    coefsCoefficients of the piecewise polynomials, returned as a n(pieces)-by-order matrix. Each set of n rows contains the coefficients for the polynomials that describe each dimension of the corresponding trajectory piece.
    piecesNumber of pieces, p – 1.
    orderOrder of the polynomials, equal to the degree of polynomial + 1. The output polynomial trajectory of minsnappolytraj has an order of 10.
    dimNumber of dimensions of the trajectory, n

    Data Types: struct

    Time points for output trajectory, returned as a p-element row vector. p is the number of waypoints. Each element in the vector is the calculated time of arrival at the corresponding waypoint of the waypoints argument. Units are in seconds.

    Note

    • If you specify the TimeAllocation argument as false, then the calculated time of arrival at each waypoint for the output trajectory is the same as the time points specified in the timePoints argument.

    • If you set the TimeAllocation argument to true, then the minsnappolytraj function uses the time points specified in the timePoints argument as an initial guess to calculate the time of arrival at each waypoint for the output trajectory.

    Data Types: single | double

    Time points of the output trajectory samples, returned as an m-element row vector. m is the number of trajectory samples. Units are in seconds.

    Data Types: single | double

    Trajectory generation status, returned as a structure that contains these fields:

    • Singularity — Singularity during optimization, returned as 0 or 1. A value of 1 indicates that the function encountered singularity when optimizing the trajectory.

    • MaxNumIterations — Maximum iterations reached, returned as 0 or 1. A value of 1 indicates that the solver reached the number of iterations specified to the MaxNumIterations argument.

    • MaxSolverTime — Maximum time reached, returned as 0 or 1. A value of 1 indicates that the solver reached the time specified to the MaxSolverTime argument.

    Tip

    If singularity occurs, reduce the ratio of MaxSegmentTime relative to MinSegmentTime.

    Data Types: struct

    Algorithms

    The minsnappolytraj function generates an optimized trajectory using the polynomial trajectory optimization algorithm [1]. The algorithm minimizes a cost function that consists of squares of the derivatives of the polynomial, and trajectory segment times. To constrain the optimization algorithm, you can specify the velocity, acceleration, jerk, and snap boundary conditions for each waypoint using the VelocityBoundaryCondition, AccelerationBoundaryCondition, JerkBoundaryCondition, and SnapBoundaryCondition arguments, respectively.

    You can also add the total segment time to the cost function by setting the TimeAllocation argument to true, and adjust the weight using the TimeWeight argument. Increasing the weight of time allocation reduces the total segment time of the output trajectory at the expense of more snap [2]. If you set the TimeAllocation argument to true, the function uses the time points you specify for the trajectory waypoints as initial guesses from which to calculate the time of arrival at each waypoint.

    The minsnappolytraj function performs optimization until convergence, or until the solver reaches the maximum time or number of iterations. To verify whether the solver has achieved convergence before reaching the maximum time or number of iterations, see the status output. To adjust the maximum number of iterations and solver time, specify the MaxNumIterations and MaxSolverTime arguments, respectively.

    References

    [1] Bry, Adam, Charles Richter, Abraham Bachrach, and Nicholas Roy. “Aggressive Flight of Fixed-Wing and Quadrotor Aircraft in Dense Indoor Environments.” The International Journal of Robotics Research 34, no. 7 (June 2015): 969–1002. https://doi.org/10.1177/0278364914558129.

    [2] Richter, Charles, Adam Bry, and Nicholas Roy. “Polynomial Trajectory Planning for Aggressive Quadrotor Flight in Dense Indoor Environments.” In Robotics Research: The 16th International Symposium ISRR, edited by Masayuki Inaba and Peter Corke. Springer International Publishing, 2016. https://doi.org/10.1007/978-3-319-28872-7_37.

    Extended Capabilities

    expand all

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

    Version History

    Introduced in R2021b

    expand all

    See Also

    Functions