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:
For camera decoding, install the optional OpenCV extra:
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:
What happened¶
auto_bridge=Truereused or started the local bridge.wait_for_sim=Truewaited 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¶
- Python SDK workflows for telemetry, cameras, TCP control, trajectories, and multi-robot examples.
sim2bot.Robot.move_tofor the exact signature, units, and safety notes.- Bridge and networking for WebSocket, TCP, and UDP.