Skip to content

sim2bot.Robot.set_velocity

set_velocity(qd: Sequence[float], robot: int = 0) -> None

Stream a joint-velocity target to one robot.

Parameters:

  • qd (Sequence[float]) –

    Joint velocities in radians per second and discovered joint order.

  • robot (int, default: 0 ) –

    Robot index returned by describe.

Returns:

  • None

    The velocity target is sent asynchronously.

Raises:

  • RuntimeError

    If the client is not connected.

  • ConnectionClosed

    If the WebSocket closes while sending the command.

  • OSError

    If the selected transport cannot send the command.

Notes

Velocity control has a 500 ms safety watchdog. Refresh the command faster than that while motion should continue; stale targets expire. Commands may be sent faster than the browser applies them, in which case the newest value wins.

Warning

This command does not generate collision-free motion. Stop streaming or call stop before leaving a control loop.

Examples:

Stream a small velocity for 250 ms, then hold::

sim.set_velocity([0.1] + [0.0] * 6)
time.sleep(0.25)
sim.stop()
Source code in sim2bot/client.py
def set_velocity(self, qd: Sequence[float], robot: int = 0) -> None:
    """Stream a joint-velocity target to one robot.

    Args:
        qd: Joint velocities in radians per second and discovered joint order.
        robot: Robot index returned by
            [`describe`][sim2bot.client.Robot.describe].

    Returns:
        The velocity target is sent asynchronously.

    Raises:
        RuntimeError: If the client is not connected.
        ConnectionClosed: If the WebSocket closes while sending the command.
        OSError: If the selected transport cannot send the command.

    Notes:
        Velocity control has a 500 ms safety watchdog. Refresh the command
        faster than that while motion should continue; stale targets expire.
        Commands may be sent faster than the browser applies them, in which
        case the newest value wins.

    Warning:
        This command does not generate collision-free motion. Stop streaming
        or call [`stop`][sim2bot.client.Robot.stop] before leaving a control
        loop.

    Examples:
        Stream a small velocity for 250 ms, then hold::

            sim.set_velocity([0.1] + [0.0] * 6)
            time.sleep(0.25)
            sim.stop()
    """
    self._send({"type": "joint_velocity", "qd": list(qd), "robot": robot})

Practical examples

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

Send a short velocity pulse

import time

velocity = [0.1] + [0.0] * (arm.dof - 1)
sim.set_velocity(velocity, robot=arm.index)
time.sleep(0.2)
sim.stop(robot=arm.index)

Refresh inside a control loop

import time

for _ in range(100):
    sim.set_velocity(policy_velocity(), robot=arm.index)
    time.sleep(0.02)  # 50 Hz, safely inside the watchdog
sim.stop(robot=arm.index)

Guidance

Usage tip

Use a finally block that calls stop() around long-running velocity-control loops.

Important behavior

Velocity targets expire after 500 ms. This protects against stale commands but is not a certified emergency stop.

Common error

Sending one velocity command and then waiting longer than 500 ms will not produce continuous motion.


See also