Python basics¶
This first complete program starts or reuses the local bridge, waits for a browser scene, discovers the model-defined home pose, commands it, and verifies that the robot arrived.
Connect, discover, and move home¶
from sim2bot import Robot
def main() -> None:
with Robot(
auto_bridge=True,
wait_for_sim=True,
wait_for_sim_timeout=30.0,
) as sim:
robots = sim.describe()
if not robots:
raise RuntimeError("The scene contains no robots")
arm = robots[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,
tol=0.02,
timeout=10.0,
)
if not reached:
raise TimeoutError("Robot did not reach its home target")
if __name__ == "__main__":
main()
Why discovery comes first¶
Robot index, joint count, joint order, limits, and home position come from the
loaded scene. Building commands from describe() keeps the same program usable
when the robot model or scene order changes.
Start locally
Use same-device loopback while developing. Add LAN addressing and an API key only after the local workflow behaves correctly.
Common startup failures¶
RuntimeError: not connectedmeans a command ran beforeconnect()or afterclose().TimeoutErrorfromwait_for_sim()means no browser scene announced a robot before the deadline.- An empty
describe()result means discovery timed out or the scene has no robots.