Skip to content

sim2bot.Robot.wait_until_reached

wait_until_reached(q: Sequence[float], robot: int = 0, tol: float = 0.02, timeout: float = 10.0) -> bool

Wait until every addressed joint is within a target tolerance.

Parameters:

  • q (Sequence[float]) –

    Target joint positions in radians and discovered joint order.

  • robot (int, default: 0 ) –

    Robot index returned by describe.

  • tol (float, default: 0.02 ) –

    Absolute per-joint tolerance in radians.

  • timeout (float, default: 10.0 ) –

    Maximum wait in seconds.

Returns:

  • bool

    True when all supplied joints reach tolerance; False on timeout.

Source code in sim2bot/client.py
def wait_until_reached(
    self,
    q: Sequence[float],
    robot: int = 0,
    tol: float = 0.02,
    timeout: float = 10.0,
) -> bool:
    """Wait until every addressed joint is within a target tolerance.

    Args:
        q: Target joint positions in radians and discovered joint order.
        robot: Robot index returned by
            [`describe`][sim2bot.client.Robot.describe].
        tol: Absolute per-joint tolerance in radians.
        timeout: Maximum wait in seconds.

    Returns:
        ``True`` when all supplied joints reach tolerance; ``False`` on timeout.
    """
    deadline = time.time() + timeout
    while time.time() < deadline:
        state = self.state(robot)
        if state and state.q and len(state.q) >= len(q):
            if all(abs(state.q[i] - q[i]) <= tol for i in range(len(q))):
                return True
        time.sleep(0.02)
    return False

Practical examples

Examples use objects discovered from the current scene rather than hard-coded robot metadata.

Wait for home

sim.move_to(arm.home, robot=arm.index)
if not sim.wait_until_reached(arm.home, robot=arm.index):
    raise TimeoutError("Robot did not reach home")

Use a tighter tolerance

reached = sim.wait_until_reached(
    target,
    robot=arm.index,
    tol=0.005,
    timeout=20.0,
)

Guidance

Usage tip

Choose tolerance based on controller stiffness and task needs; an unrealistically small value may never pass in physics mode.


See also