Skip to content

Gripper Set Unit

SUMMARY

Set Unit configures the measurement unit used for position, speed, and force parameters in subsequent gripper commands.

Robotiq automatically sets default units after connect ("mm" for position, "percent" for speed and force). Call set_unit only when a different unit is needed.

The Skill

python
gripper.set_unit("position", "mm")
gripper.set_unit("speed", "percent")
gripper.set_unit("force", "percent")

The Code

Safety first!

A real robot will faithfully do whatever you ask of it - so please take a moment to clear the workspace, keep an E-Stop within reach, and be ready to disconnect.

Operating real hardware is at your own risk.

python
"""
Demonstrates setting the position unit of a parallel gripper.

Supports OnRobot and Robotiq grippers, and Isaac Sim.

Usage:
    python set_unit.py --ip <GRIPPER_IP>
    python set_unit.py --prim_path <PRIM_PATH>

Note:
    OnRobot has no multi-unit backend: only parameter="position" with
    unit="mm", and parameter="force" with unit="N", are accepted. set_unit()
    is provided for signature parity with the Robotiq wrapper.

    Experimental gripper support for Isaac Sim:  Robotiq 2F85 (USD-based simulation only); Schunk EGP and
    PZN+ are.
"""

import argparse
from loguru import logger

from telekinesis.synapse.tools.parallel_grippers import onrobot


def main(ip: str | None,
         protocol: str,
         prim_path: str | None) -> None:
    """Validates the position unit of an OnRobot gripper as millimeters."""

    #===================== Create Gripper ======================================
    gripper = onrobot.OnRobotRG6()

    try:
        #===================== Connect Gripper =================================
        if prim_path:
            gripper.connect(simulation_prim_path=prim_path)
        else:
            gripper.connect(ip=ip, protocol=protocol)

        # ==================== Run Skill ====================================
        gripper.set_unit(parameter="position", unit="mm")
        logger.success("Position unit confirmed as 'mm'.")
    except (ConnectionError, OSError) as e:
        logger.error(f"Error occurred: {e}")
    finally:
        gripper.disconnect()


if __name__ == "__main__":
    p = argparse.ArgumentParser(description="OnRobot gripper set unit")
    p.add_argument("--protocol",
                   choices=["MODBUS_TCP"],
                   default="MODBUS_TCP")
    p.add_argument("--ip", default=None, help="IP for OnRobot Gripper")
    p.add_argument("--prim_path", type=str, default=None,
                   help='Isaac Sim gripper prim path, e.g. "/World/onrobot_rg6"')
    args = p.parse_args()

    main(ip=args.ip,
         protocol=args.protocol,
         prim_path=args.prim_path)

Running the Example

bash
python set_unit.py --ip 192.168.1.100
bash
python set_unit.py --prim_path /World/onrobot_rg6

For all options:

bash
python set_unit.py --help

Parameter Configuration

Robotiq 2F-85

ParameterTypeDefaultDescription
parameterstrrequiredThe parameter to configure: "position", "speed", or "force".
unitstrrequiredPosition: "mm", "device" (0-255), "normalized" (0.0-1.0), "percent" (0-100). Speed / force: "device", "normalized", "percent".

OnRobot RG2 / RG6

ParameterTypeDefaultDescription
parameterstrrequired"position" or "force" only. "speed" is not accepted.
unitstrrequiredPosition: "mm" only. Force: "N" only.

Returns

This skill returns nothing (None).

Raises

Robotiq 2F-85

ExceptionCondition
ValueErrorparameter is not "position", "speed", or "force"; or unit is not supported for the given parameter
RuntimeErrorThe gripper is not connected

OnRobot RG2 / RG6

ExceptionCondition
TypeErrorparameter or unit is not a string
ValueErrorThe (parameter, unit) combination is not supported

How to Tune the Parameters

Prefer "mm" for position in production scripts - physical units are self-documenting and easy to validate against the gripper's datasheet.

Where to Use the Skill

  • Session initialization - Call once after connect when a non-default unit is needed
  • Unit switching - Re-call mid-session to switch between units for a specific subroutine

When Not to Use the Skill

Do not call set_unit when:

  • The default units are sufficient - after connect, position is already "mm" and speed/force are already "percent"