Skip to content

Robot motion and trajectories

Use browser-managed trajectories for timestamped motion. Use streamed velocity commands for policies that continuously produce a new target.

Play a timestamped trajectory

from sim2bot import Robot


def main() -> None:
    with Robot(auto_bridge=True, wait_for_sim=True) as sim:
        arm = sim.describe()[0]
        home = list(arm.home)
        offset = list(home)
        offset[0] += 0.25

        sim.move_trajectory(
            [
                (0.0, home),
                (1.5, offset),
                (3.0, home),
            ],
            robot=arm.index,
        )


if __name__ == "__main__":
    main()

Waypoint time is measured in seconds from trajectory start and must increase strictly. Motion-panel exports use milliseconds, so divide exported timestamps by 1000 before passing them to move_trajectory().

Stream velocity with guaranteed cleanup

import time

from sim2bot import Robot


def main() -> None:
    with Robot(auto_bridge=True, wait_for_sim=True) as sim:
        arm = sim.describe()[0]
        velocity = [0.0] * arm.dof
        velocity[0] = 0.1

        try:
            deadline = time.monotonic() + 2.0
            while time.monotonic() < deadline:
                sim.set_velocity(velocity, robot=arm.index)
                time.sleep(0.02)  # Refresh at 50 Hz.
        finally:
            sim.stop(robot=arm.index)


if __name__ == "__main__":
    main()

Velocity watchdog

Velocity commands expire after 500 ms. Always send an explicit stop() in finally as well; the watchdog is not a replacement for normal cleanup.

Relevant APIs