Generate third-order polynomial trajectories
generates a third-order polynomial that achieves a given set of input waypoints with
corresponding time points. The function outputs positions, velocities, and accelerations at
the given time samples,
pp] = cubicpolytraj(
tSamples. The function also returns the
pp form of the polynomial trajectory with respect
Compute Cubic Trajectory for 2-D Planar Motion
cubicpolytraj function with a given set of 2-D xy waypoints. Time points for the waypoints are also given.
wpts = [1 4 4 3 -2 0; 0 1 2 4 3 1]; tpts = 0:5;
Specify a time vector for sampling the trajectory. Sample at a smaller interval than the specified time points.
tvec = 0:0.01:5;
Compute the cubic trajectory. The function outputs the trajectory positions (
q), velocity (
qd), acceleration (
qdd), and polynomial coefficients (
pp) of the cubic polynomial.
[q, qd, qdd, pp] = cubicpolytraj(wpts, tpts, tvec);
Plot the cubic trajectories for the x- and y-positions. Compare the trajectory with each waypoint.
plot(tvec, q) hold all plot(tpts, wpts, 'x') xlabel('t') ylabel('Positions') legend('X-positions','Y-positions') hold off
You can also verify the actual positions in the 2-D plane. Plot the separate rows of the
q vector and the waypoints as x- and y -positions.
figure plot(q(1,:),q(2,:),'-b',wpts(1,:),wpts(2,:),'or') xlabel('X') ylabel('Y')
wayPoints — Waypoints for trajectory
Points for waypoints of trajectory, specified as an n-by-p matrix, where n is the dimension of the trajectory and p is the number of waypoints.
[1 4 4 3 -2 0; 0 1 2 4 3 1]
timePoints — Time points for waypoints of trajectory
Time points for waypoints of trajectory, specified as a p-element vector.
[0 2 4 5 8 10]
Specify optional pairs of arguments as
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.
Before R2021a, use commas to separate each name and value, and enclose
Name in quotes.
'VelocityBoundaryCondition',[1 0 -1 -1 0 0; 1 1 1 -1 -1
VelocityBoundaryCondition — Velocity boundary conditions for each waypoint
zeroes(n,p) (default) | n-by-p matrix
Velocity boundary conditions for each waypoint, specified as the comma-separated
pair consisting of
'VelocityBoundaryCondition' and an
n-by-p matrix. Each row corresponds to the
velocity at all p waypoints for the respective variable in the
[1 0 -1 -1 0 0; 1 1 1 -1 -1 -1]
q — Positions of trajectory
Positions of the trajectory at the given time samples in
tSamples, returned as an m-element vector,
where m is the length of
qd — Velocities of trajectory
Velocities of the trajectory at the given time samples in
tSamples, returned as a vector.
qdd — Accelerations of trajectory
Accelerations of the trajectory at the given time samples in
tSamples, returned as a vector.
pp — Piecewise-polynomial
Piecewise-polynomial, returned as a structure that defines the polynomial for each
section of the piecewise trajectory. You can build your own piecewise polynomials using
mkpp, or evaluate the polynomial at
specified times using
ppval. The structure contains the fields:
breaks: p-element vector of times when the piecewise trajectory changes forms. p is the number of waypoints.
ordermatrix for the coefficients for the polynomials. n(p–1) is the dimension of the trajectory times the number of
pieces. Each set of n rows defines the coefficients for the polynomial that described each variable trajectory.
pieces: p–1. The number of breaks minus 1.
order: Degree of the polynomial + 1. For example, cubic polynomials have an order of 4.
dim: n. The dimension of the control point positions.