Skip to content

Scripting TrajectoryApi

Nishendra Singh edited this page Sep 16, 2026 · 2 revisions

Part of the Scripting API. TrajectoryApi wraps one Trajectory object. See Trajectory for the panel.

from freecad.robotics.App.rbt_api import get_robot
rob = get_robot()
traj = rob.add_trajectory()        # or: traj = rob.trajectories[0]

Members

Member Function
traj.robot The parent robot as RobotApi
traj.waypoints The waypoint list. Read and write
traj.teach(name="", motion=PTP) Record the current pose as a joint waypoint
traj.add_cartesian(target, name="", motion=PTP) Add a Cartesian waypoint at a placement
traj.goto(idx) Move the robot to waypoint idx
traj.plan() The trajectory plan and the validated waypoints
traj.duration Duration of the plan in seconds
traj.q_at(t_sec) Joint values at time t_sec along the plan
traj.sample_path(n_per_seg=20) World TCP polyline for each segment

Motion types: PTP (point-to-point in joint space) and LIN (linear in Cartesian space).

Teach a trajectory

from freecad.robotics.App.rbt_api import LIN

traj.teach("start")

rob.q = [0, -30, 45, 0, 60, 0]
traj.teach("pick")

tgt = rob.tcp.copy()
tgt.Base.z += 100
traj.add_cartesian(tgt, "lift", motion=LIN)

Examine the plan

print(traj.duration)               # seconds, None when the plan fails

q = traj.q_at(1.5)                 # pose at t = 1.5 s
pts = traj.sample_path()           # TCP polyline, world coordinates

traj.goto(0)                       # robot to the first waypoint

Edit the waypoints

wps = traj.waypoints               # list of Waypoint
wps[1].name = "pick_2"
traj.waypoints = wps               # write back, the plan cache resets

Back: RobotApi · Next: RobotBuilder

Clone this wiki locally