Trajectory planning
Two methods of planning trajectories are available
point_to_point: Generate a minimum-time point-to-point trajectory with specified start and endpoints, not exceeding specified speed and acceleration limits.traj5: Generate a 5th order polynomial trajectory with specified start and end points. Additionally allows specification of start and end values for velocity and acceleration.TrajectoryLimiters.JerkLimiterfrom TrajectoryLimiters.jl: Generate time-optimal trajectories with bounded jerk, acceleration and velocity using the Ruckig algorithm.
Components that make use of these trajectory generators is provided:
These all have output connectors of type RealOutput called q, qd, qdd for positions, velocities and accelerations.
Example
Point-to-point trajectory with bounded acceleration
using MultibodyComponents, Plots
Ts = 0.001
t = -0.5:Ts:3
q1 = [1, 1.2] # Final point (2 DOF)
qd_max = [0.7, 1.2] # Max velocity (2 DOF)
qdd_max = [0.9, 1.1] # Max acceleration (2 DOF)
q, qd, qdd = MultibodyComponents.point_to_point(t; q1, qd_max, qdd_max)
plot(t, [q qd qdd], ylabel=["\$q\$" "\$\\dot{q}\$" "\$\\ddot{q}\$"], layout=(3,1), l=2, sp=[1 1 2 2 3 3], legend=false)
hline!([qd_max' qdd_max'], l=(2, :dash), sp=[2 2 3 3], c=[1 2 1 2], legend=false)<< @example-block not executed in draft mode >>Point-to-point trajectory with bounded jerk
This kind of trajectory generator is implemented in TrajectoryLimiters.jl, it may be used as a component in a multibody model through KinematicPTPBoundedJerk.
using MultibodyComponents, Plots
Ts = 0.001
t = -0.5:Ts:3
q1 = [1, 1.2] # Final point (2 DOF)
qd_max = [0.7, 1.2] # Max velocity (2 DOF)
qdd_max = [0.9, 1.1] # Max acceleration (2 DOF)
qddd_max = [4.0, 4.0] # Max jerk (2 DOF)
lims = [MultibodyComponents.JerkLimiter(; vmax=qd_max[i], amax=qdd_max[i], jmax=qddd_max[i]) for i in 1:length(q1)] # One limiter per DOF
profiles = MultibodyComponents.calculate_trajectory(lims; pf=q1)
q, qd, qdd, qddd = profiles(t)
plot(t, [q qd qdd], ylabel=["\$q\$" "\$\\dot{q}\$" "\$\\ddot{q}\$"], layout=(3,1), l=2, sp=[1 1 2 2 3 3], legend=false)
hline!([qd_max' qdd_max'], l=(2, :dash), sp=[2 2 3 3], c=[1 2 1 2], legend=false)<< @example-block not executed in draft mode >>5th order polynomial trajectory
t = 0:Ts:3
q1 = 1
q, qd, qdd = MultibodyComponents.traj5(t; q1)
plot(t, [q qd qdd], ylabel=["\$q\$" "\$\\dot{q}\$" "\$\\ddot{q}\$"], layout=(3,1), l=2, legend=false)<< @example-block not executed in draft mode >>Docstrings
MultibodyComponents.KinematicPTPBoundedJerkMultibodyComponents.point_to_pointMultibodyComponents.ptp_qMultibodyComponents.ptp_qdMultibodyComponents.ptp_qddMultibodyComponents.traj5MultibodyComponents.traj5MultibodyComponents.traj5_qMultibodyComponents.traj5_qdMultibodyComponents.traj5_qdd
MultibodyComponents.KinematicPTPBoundedJerk Method
KinematicPTPBoundedJerk(; name, q0=0, q1=1, qd_max=1, qdd_max=1, qddd_max=10)A component emitting a time-optimal point-to-point trajectory with bounded velocity, acceleration, and jerk, generated using JerkLimiter from TrajectoryLimiters.jl.
When multiple axes are specified, the trajectories are time-synchronized so all axes reach their targets at the same time.
Arguments
name: Name of the componentq0: Initial position (scalar or vector)q1: Final position (scalar or vector)qd_max: Maximum velocity (scalar or vector)qdd_max: Maximum acceleration (scalar or vector)qddd_max: Maximum jerk (scalar or vector)
Outputs
q: Positionqd: Velocityqdd: Accelerationqddd: Jerk
MultibodyComponents.point_to_point Method
q, qd, qdd, t_end = point_to_point(time; q0=0.0, q1=1.0, t0=0, qd_max=1, qdd_max=1)Generate a minimum-time point-to-point trajectory with specified start and endpoints, not exceeding specified speed and acceleration limits.
The trajectory produced by this function will typically exhibit piecewise constant acceleration, piecewise linear velocity and piecewise quadratic position curves.
If a vector of time points is provided, the function returns matrices q,qd,qdd of size (length(time), n_dims). If a scalar time point is provided, the function returns q,qd,qdd as vectors with the specified dimension (same dimension as q0). t_end is the time at which the trajectory will reach the specified end position.
Arguments:
time: A scalar or a vector of time points.q0: Initial coordinate, may be a scalar or a vector.q1: End coordinate.t0: Time at which the motion starts.qd_max: Maximum allowed speed.qdd_max: Maximum allowed acceleration.
MultibodyComponents.ptp_q Method
ptp_q(t, q0, q1, qd_max, qdd_max)Evaluate the position of a point-to-point trajectory at scalar time t. Calls point_to_point with scalar inputs and returns the position.
MultibodyComponents.ptp_qd Method
ptp_qd(t, q0, q1, qd_max, qdd_max)Evaluate the velocity of a point-to-point trajectory at scalar time t. Calls point_to_point with scalar inputs and returns the velocity.
MultibodyComponents.ptp_qdd Method
ptp_qdd(t, q0, q1, qd_max, qdd_max)Evaluate the acceleration of a point-to-point trajectory at scalar time t. Calls point_to_point with scalar inputs and returns the acceleration.
MultibodyComponents.traj5 Method
q, qd, qdd = traj5(t, tf; q0, q1, qd0, qd1, qdd0, qdd1)Generate a 5th order polynomial trajectory. Scalar-time version that returns symbolic expressions when called with a symbolic t.
MultibodyComponents.traj5 Method
q, qd, qdd = traj5(t; q0, q1, qd0, qd1, qdd0, qdd1)Generate a 5th order polynomial trajectory with specified end points, velocities and accelerations. Vector-time version that returns arrays.
MultibodyComponents.traj5_q Method
traj5_q(t, tf, q0, q1, qd0, qd1, qdd0, qdd1)Evaluate the position component of a 5th order polynomial trajectory at time t.
MultibodyComponents.traj5_qd Method
traj5_qd(t, tf, q0, q1, qd0, qd1, qdd0, qdd1)Evaluate the velocity component of a 5th order polynomial trajectory at time t.
MultibodyComponents.traj5_qdd Method
traj5_qdd(t, tf, q0, q1, qd0, qd1, qdd0, qdd1)Evaluate the acceleration component of a 5th order polynomial trajectory at time t.