Skip to content

sim2bot.Robot.gripper

gripper(fraction: float, robot: int = 0) -> None

Set normalized gripper openness for one robot.

Parameters:

  • fraction (float) –

    0.0 fully closed through 1.0 fully open.

  • robot (int, default: 0 ) –

    Robot index returned by describe.

Returns:

  • None

    Unsupported grippers may ignore the command.

Raises:

  • TypeError

    If fraction cannot be converted to float.

  • ValueError

    If fraction is not a numeric value.

  • 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

Robots without a supported gripper ignore the command. Discover RobotInfo.has_gripper before relying on it.

Source code in sim2bot/client.py
def gripper(self, fraction: float, robot: int = 0) -> None:
    """Set normalized gripper openness for one robot.

    Args:
        fraction: ``0.0`` fully closed through ``1.0`` fully open.
        robot: Robot index returned by
            [`describe`][sim2bot.client.Robot.describe].

    Returns:
        Unsupported grippers may ignore the command.

    Raises:
        TypeError: If ``fraction`` cannot be converted to ``float``.
        ValueError: If ``fraction`` is not a numeric value.
        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:
        Robots without a supported gripper ignore the command. Discover
        `RobotInfo.has_gripper` before relying on it.
    """
    self._send({"type": "gripper", "fraction": float(fraction), "robot": robot})

Practical examples

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

Open and close

sim.gripper(1.0, robot=arm.index)
sim.gripper(0.0, robot=arm.index)

Use a partial opening

if arm.has_gripper:
    sim.gripper(0.35, robot=arm.index)

Guidance

Usage tip

Check RobotInfo.has_gripper before presenting gripper controls in a generic application.

Common error

Robots without a supported gripper silently ignore this command.


See also