Professional Documents
Culture Documents
The trapveltraj function creates trajectories with trapezoidal velocity profiles. These
trajectories follow a three-segment path of acceleration, constant velocity, and Copy Command
deceleration between all of their waypoints. You can alter these trajectories by
specifying parameters to construct your desired profile, but there are many applications
that require a set of bounds instead, such as limits on acceleration or velocity. In such applications, you must first
translate these bounds into a parameterized trajectory that is both feasible and satisfies the expected bounds. In this
example, use the helperProfileForMaxVel helper function to create feasible trapezoidal profiles given a velocity
bound.
Visualize the results by using the helperPlotTaskSpaceTraj helper function, which creates a figure that plots the 2-D
trajectory on the left and the position and velocity with respect to time on the right. Since all of the end times match, this
trajectory hits both its vertical and horizontal waypoints simultaneously, making it suitable for numerous applications.
tpts = 0:size(wpts,2)-1;
helperPlotTaskSpaceTraj("EndTime = 1",t,q,qd,wpts,tpts);
https://www.mathworks.com/help/robotics/ug/design-a-trajectory-with-velocity-limits-using-a-trapezoidal-velocity-profile.html 1/12
12/11/22, 12:33 PM Design Trajectory with Velocity Limits Using Trapezoidal Velocity Profile - MATLAB & Simulink
Visualize the results. The generated trajectory is acceptable if the AI must only connect the first and last waypoints in
time, but the different segment lengths along dimensions, can make it insufficient for additional tasks, such as collision
avoidance, or if using the trajectory to meet points in 3-D space. If the trajectory must meet every waypoint, you can
improve it by specifying the end time. This ensures that each segment has the same length.
[q,qd,qdd,t] = trapveltraj(wpts,100,PeakVelocity=0.5);
helperPlotTaskSpaceTraj("PeakVelocity = 0.5 rad/s",t,q,qd,wpts);
https://www.mathworks.com/help/robotics/ug/design-a-trajectory-with-velocity-limits-using-a-trapezoidal-velocity-profile.html 2/12
12/11/22, 12:33 PM Design Trajectory with Velocity Limits Using Trapezoidal Velocity Profile - MATLAB & Simulink
https://www.mathworks.com/help/robotics/ug/design-a-trajectory-with-velocity-limits-using-a-trapezoidal-velocity-profile.html 3/12
12/11/22, 12:33 PM Design Trajectory with Velocity Limits Using Trapezoidal Velocity Profile - MATLAB & Simulink
As shown in the image above, the velocity profile has four parameters:
Acceleration Time — Time spent in the acceleration and deceleration phases of each segment
Peak Acceleration — Magnitude of the acceleration applied during the acceleration and deceleration phases of each
segment
You can fully define a profile by specifying two of these. When you provide only one parameter, trapveltraj
automatically assigns a second parameter so that the average velocity of each segment is halfway between the two
allowable bounds detailed in Constraints for Combining Parameter Specifications.
https://www.mathworks.com/help/robotics/ug/design-a-trajectory-with-velocity-limits-using-a-trapezoidal-velocity-profile.html 4/12
12/11/22, 12:33 PM Design Trajectory with Velocity Limits Using Trapezoidal Velocity Profile - MATLAB & Simulink
Mathematically, this profile defines segments on the interval [0, endTime], where each segment has an acceleration
phase, constant speed phase, and a deceleration phase. The lengths of the acceleration and deceleration phases,
accelTime, are equal.
2 2
d d t
1. Acceleration Phase — For t = [0, accelTime],
2
s(t ) = a, s(t ) = at, s(t ) = a
dt dt 2
2 2
d d v
2. Constant Speed Phase — For t = [accelTime, endTime – accelTime], 2
s(t ) = 0, s(t ) = v, s(t ) = vt −
dt dt 2a
s(endTime) − s(0)
Peak velocity must be greater than the average speed: peakVelocity >
endTime
s(endTime) − s(0)
Peak velocity must be less than or equal to twice the average speed: peakVelocity < 2
( )
endTime
‾
‾
These constraints are derived from the total segment length ∣s∣ = ∣s(End Time) − s(0)∣ , which is fixed with any two
waypoints and results from the integral of the velocity, i.e. the area of the trapezoid:
The first constraint sets the lowest allowable peak velocity magnitude. This occurs when the motion spends the most
amount of time at constant speed:
https://www.mathworks.com/help/robotics/ug/design-a-trajectory-with-velocity-limits-using-a-trapezoidal-velocity-profile.html 5/12
12/11/22, 12:33 PM Design Trajectory with Velocity Limits Using Trapezoidal Velocity Profile - MATLAB & Simulink
In the second case, the acceleration and deceleration phases are infinitesimal, resulting in a nearly rectangular velocity
profile that has a total area A = (Width ∗ Length) , or ∣s∣ = ∣peakVelocity∣ ∗ (endTime) . Hence for this case to
∣s∣
succeed, the magnitude of the peak velocity must equal the average speed . In practice, the acceleration /
endTime
deceleration phases can never be truly infinitesimal (Acceleration Time > 0), which instead makes this an inequality
∣s∣
constraint: peakVelocity > .
endTime
The second constraint defines the highest allowable peak velocity. This occurs when the motion spends as much time as
possible accelerating to a peak velocity:
https://www.mathworks.com/help/robotics/ug/design-a-trajectory-with-velocity-limits-using-a-trapezoidal-velocity-profile.html 6/12
12/11/22, 12:33 PM Design Trajectory with Velocity Limits Using Trapezoidal Velocity Profile - MATLAB & Simulink
In this situation, there is no constant speed phase, resulting in a triangular velocity profile, which has a total area
Height ∗ Length ∣Peak Velocity∣ ∗ (End Time)
A = or ∣s∣ = . Therefore, in this extreme, the magnitude of the peak
2 2
2∣s∣
velocity must equal twice the peak speed, resulting in the second constraint, ∣Peak Velocity∣ > .
endTime
These two constraints define the viable range of trapezoidal velocity profiles for a given segment. The following graphic
compares three such trajectories, with the first constraint shown using dotted lines, the second shown with dashed lines,
and an example of a trapezoidal profile within these constraints shown as a solid line. All plausible trapezoidal profile
trajectories for this segment must fall between the dotted and dashed lines, as some variation of the solid line example.
https://www.mathworks.com/help/robotics/ug/design-a-trajectory-with-velocity-limits-using-a-trapezoidal-velocity-profile.html 7/12
12/11/22, 12:33 PM Design Trajectory with Velocity Limits Using Trapezoidal Velocity Profile - MATLAB & Simulink
[q,qd]=trapveltraj([0 1],100,'EndTime',1,'PeakVelocity',1);
Given the constraints derived above, for the segment from s = 0 to s = 1, the constraints imply that:
∣Peak Velocity∣(End Time) > 1 and ∣Peak Velocity∣(End Time) < 2 , whereas with the values used above, the first
condition is not met. This could be resolved e.g. by raising the peak velocity to 1.5.
Limitations can also arise because the constraints work for one dimension of a segment, but not for all of them. For
example, suppose there is a segment between [0 0] and [1 2], with assigned values for the segment duration and peak
velocity:
[q,qd]=trapveltraj([0 1; 0 2],100,'EndTime',1,'PeakVelocity',1.5);
This will fail because the constraints only work for the first dimension:
For the first dimension, from s = 0 to s = 1, the constraints imply that: ∣Peak Velocity∣(End Time) > 1 and
∣Peak Velocity∣(End Time) < 2
For the second dimension, from s= 0 to s = 2, the constraints imply that: ∣Peak Velocity∣(End Time) > 2 and
∣Peak Velocity∣(End Time) < 4
It is evident that these constraints cannot be met if the same values are used for both dimensions. Instead, it is
necessary to use different peak velocities for each dimension to ensure that the waypoints can be hit with the same end
times. For example, the following solution works:
wpts2 = [0 1; 0 2];
[q,qd,qdd,t]=trapveltraj(wpts2,100,'EndTime',1,'PeakVelocity',[1.5; 2.5]);
helperPlotTaskSpaceTraj('Different Peak Velocities for each Dimension',t,q,qd,wpts2);
https://www.mathworks.com/help/robotics/ug/design-a-trajectory-with-velocity-limits-using-a-trapezoidal-velocity-profile.html 8/12
12/11/22, 12:33 PM Design Trajectory with Velocity Limits Using Trapezoidal Velocity Profile - MATLAB & Simulink
Choosing parameters that satisfy all constraints along each dimension can be challenging. In the next section, a helper
function is instead created to help simplify this process.
https://www.mathworks.com/help/robotics/ug/design-a-trajectory-with-velocity-limits-using-a-trapezoidal-velocity-profile.html 9/12
12/11/22, 12:33 PM Design Trajectory with Velocity Limits Using Trapezoidal Velocity Profile - MATLAB & Simulink
% Determine min and max peak velocity for each segment and dimension
% Choose largest velocity that doesn't exceed maximum velocity
minPeakVels = segLengths./endTimes;
maxPeakVels = 2*segLengths./endTimes;
peakVels = min(maxPeakVels,maxVelocity);
peakVels = max(minPeakVels,peakVels);
Use the helper function to create a trajectory for the waypoints that has a maximum velocity bound of 0.5 rad/s.
[endTimes,peakVels] = helperProfileForMaxVel(wpts,0.5);
[q,qd,qdd,t,pp] = trapveltraj(wpts,100,EndTime=endTimes,PeakVelocity=peakVels);
tpts = [0 cumsum(endTimes(1,:))];
helperPlotTaskSpaceTraj("Helper Function with Maximum Velocity 0.5 rad/s",t,q,qd,wpts,tpts);
https://www.mathworks.com/help/robotics/ug/design-a-trajectory-with-velocity-limits-using-a-trapezoidal-velocity-profile.html 10/12
12/11/22, 12:33 PM Design Trajectory with Velocity Limits Using Trapezoidal Velocity Profile - MATLAB & Simulink
References
[1] Lynch, Kevin M., and Frank C. Park. Modern Robotics: Mechanics, Planning and Control. Cambridge: Cambridge
University Press, 2017.
https://www.mathworks.com/help/robotics/ug/design-a-trajectory-with-velocity-limits-using-a-trapezoidal-velocity-profile.html 11/12
12/11/22, 12:33 PM Design Trajectory with Velocity Limits Using Trapezoidal Velocity Profile - MATLAB & Simulink
https://www.mathworks.com/help/robotics/ug/design-a-trajectory-with-velocity-limits-using-a-trapezoidal-velocity-profile.html 12/12