Polynomial Trajectory Generation
This example introduces linear, cubic, and quintic point-to-point trajectories and shows how their numerical arrays integrate with inverse kinematics and visualization.
1. Linear, cubic, and quintic comparison
import numpy as np
from moro.trajectory import joint_trajectory
t = np.linspace(0.0, 2.0, 101)
linear = joint_trajectory(
0.0,
1.0,
t,
method="linear",
)
cubic = joint_trajectory(
0.0,
1.0,
t,
method="cubic",
)
quintic = joint_trajectory(
0.0,
1.0,
t,
method="quintic",
)
The three trajectories share the same endpoint positions but differ in derivative behavior.
Linear interpolation has constant velocity inside the interval. The default cubic trajectory begins and ends at zero velocity. The default quintic trajectory begins and ends at zero velocity and zero acceleration.
The public arrays can be plotted directly:
import matplotlib.pyplot as plt
plt.plot(t, linear.q[:, 0], label="linear")
plt.plot(t, cubic.q[:, 0], label="cubic")
plt.plot(t, quintic.q[:, 0], label="quintic")
plt.legend()
The same comparison can be made with qd and qdd.
2. Multi-joint quintic trajectory
traj = joint_trajectory(
[0.0, 0.3, -0.5],
[0.8, -0.2, 0.4],
t,
method="quintic",
)
The time-major result is:
traj.q.shape == (101, 3)
Nonzero derivative conditions can also be prescribed explicitly:
traj = joint_trajectory(
[0.0, 0.3, -0.5],
[0.8, -0.2, 0.4],
t,
method="quintic",
qd0=[0.1, 0.0, 0.0],
qdf=[0.0, 0.0, -0.1],
)
3. Cartesian trajectory plus inverse kinematics
Generate a Cartesian position trajectory:
from moro.trajectory import position_trajectory
cart = position_trajectory(
[1.5, 0.0, 0.0],
[1.2, 0.6, 0.0],
t,
method="quintic",
)
Then pass only the position samples to the IK layer:
from moro.inverse_kinematics import solve_position_trajectory
ik = solve_position_trajectory(
robot,
cart.p,
q0=q_initial,
)
The time vector remains available as cart.t, while the IK result stores the solved joint configurations.
4. Joint trajectory plus visualization
A JointTrajectory can be animated by passing its numerical joint
matrix traj.q (shape (N, robot.dof)) and its time vector traj.t
to the Three.js visualizer:
from moro.visualization import RobotVisualizer
viz = RobotVisualizer(robot)
viz.animate(traj.q, times=traj.t)
The visualization layer accepts these arrays structurally and does not
import or depend on JointTrajectory. T-06 reproduces nonuniform
traj.t explicitly; without times, the older fixed-interval
mode continues to work and loops. Matplotlib currently supports only
the fixed-interval path.
See Physical-Time Animation Playback for a runnable RR example with nonuniform sample times.
5. Synchronized trapezoidal joint motion
Moro also provides a limit-driven point-to-point generator:
from moro.trajectory import joint_trapezoidal_trajectory
trapezoidal = joint_trapezoidal_trajectory(
[0.0, 0.0], [1.2, -0.8],
v_max=[0.6, 0.4], a_max=[1.0, 0.8],
)
Its velocity is piecewise linear with a constant-speed phase when the distance is sufficient; otherwise the speed profile is triangular. Unlike quintic interpolation, it directly enforces the supplied speed and acceleration limits along a straight path in joint space.
For complete R/RR code, physical-limit checks, plots and a same-duration quintic comparison, see Trapezoidal Joint-Space Trajectories.