Skip to content

Your first Python script

This guide connects Python to the browser, discovers the loaded robot, sends its home target, and reads back telemetry. Discovery is important: it avoids hard-coding a robot's degree of freedom, joint order, or home pose.

1. Install the SDK

From the repository root:

python3 -m venv .venv
source .venv/bin/activate
pip install -e services/bridge/sim2bot

For camera decoding, install the optional OpenCV extra:

pip install -e "services/bridge/sim2bot[cv2]"

2. Open the simulator

Run the web app, open Sim2Bot, and keep its browser tab visible. In the app, open Tools → Bridge and connect to the local bridge.

3. Run a controller

Save this as first_move.py:

from sim2bot import Robot

with Robot(auto_bridge=True, wait_for_sim=True) as sim:
    arm = sim.describe()[0]
    print(f"Controlling {arm.name}: {arm.dof} joints")

    sim.move_to(arm.home, robot=arm.index)
    reached = sim.wait_until_reached(
        arm.home,
        robot=arm.index,
        timeout=10.0,
    )

    state = sim.state(robot=arm.index)
    print("Reached:", reached)
    print("Joint position [rad]:", state.q if state else None)

Run it:

python first_move.py

What happened

  • auto_bridge=True reused or started the local bridge.
  • wait_for_sim=True waited for the browser to announce a scene.
  • describe() returned model-derived metadata.
  • move_to() sent joint positions in radians to one addressed robot.
  • state() returned the newest packet rather than a backlog of old telemetry.

Next steps