From 172c7ea335649ff368eec235521b35688f25fe1d Mon Sep 17 00:00:00 2001 From: Tobias Juelg Date: Mon, 5 Oct 2026 19:51:15 -0700 Subject: [PATCH 01/16] refactor(digit)!: digit into own extension --- .github/workflows/build_wheels.yaml | 1 + .github/workflows/ci.yaml | 1 + Makefile | 2 +- docs/extensions/index.md | 1 + docs/extensions/overview.md | 1 + docs/extensions/rcs_digit.md | 20 +++++++ extensions/rcs_digit/README.md | 53 +++++++++++++++++++ extensions/rcs_digit/pyproject.toml | 23 ++++++++ .../rcs_digit/src/rcs_digit/__init__.py | 1 + .../rcs_digit/src/rcs_digit/camera.py | 25 ++++++++- extensions/rcs_fr3/src/rcs_fr3/creators.py | 4 +- .../rcs_panda/src/rcs_panda/creators.py | 4 +- .../rcs_so101/src/rcs_so101/creators.py | 4 +- extensions/rcs_ur5e/src/rcs_ur5e/creators.py | 4 +- .../rcs_xarm7/src/rcs_xarm7/creators.py | 4 +- pyproject.toml | 5 +- python/rcs/envs/utils.py | 19 ------- 17 files changed, 140 insertions(+), 32 deletions(-) create mode 100644 docs/extensions/rcs_digit.md create mode 100644 extensions/rcs_digit/README.md create mode 100644 extensions/rcs_digit/pyproject.toml create mode 100644 extensions/rcs_digit/src/rcs_digit/__init__.py rename python/rcs/camera/digit_cam.py => extensions/rcs_digit/src/rcs_digit/camera.py (65%) diff --git a/.github/workflows/build_wheels.yaml b/.github/workflows/build_wheels.yaml index 327e7165c..b37c97f14 100644 --- a/.github/workflows/build_wheels.yaml +++ b/.github/workflows/build_wheels.yaml @@ -82,6 +82,7 @@ jobs: fail-fast: false matrix: extension: + - rcs_digit - rcs_flexiv - rcs_realsense - rcs_robotiq2f85 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5ecb53f85..227c4199f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -87,6 +87,7 @@ jobs: extension: # Python extensions - rcs_xarm7 + - rcs_digit - rcs_realsense - rcs_robotiq2f85 - rcs_tacto diff --git a/Makefile b/Makefile index 201547786..760d08e88 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ WHEELHOUSE = wheelhouse CORE_WHEELHOUSE = ${WHEELHOUSE}/core PY_EXT_WHEELHOUSE = ${WHEELHOUSE}/py_extensions CPP_EXT_WHEELHOUSE = ${WHEELHOUSE}/cpp_extensions -PY_EXTENSIONS ?= rcs_flexiv rcs_realsense rcs_robotiq2f85 rcs_ur5e rcs_usb_cam rcs_xarm7 rcs_zed +PY_EXTENSIONS ?= rcs_digit rcs_flexiv rcs_realsense rcs_robotiq2f85 rcs_ur5e rcs_usb_cam rcs_xarm7 rcs_zed CPP_EXTENSIONS ?= rcs_fr3 rcs_panda rcs_so101 # set to pypi to publish to the real index PYPI_REPOSITORY ?= testpypi diff --git a/docs/extensions/index.md b/docs/extensions/index.md index 74935733c..91e4d778a 100644 --- a/docs/extensions/index.md +++ b/docs/extensions/index.md @@ -13,6 +13,7 @@ rcs_so101 rcs_yam rcs_flexiv rcs_realsense +rcs_digit rcs_usb_cam rcs_tacto rcs_robotiq2f85 diff --git a/docs/extensions/overview.md b/docs/extensions/overview.md index b318a25a5..97f3bef26 100644 --- a/docs/extensions/overview.md +++ b/docs/extensions/overview.md @@ -43,6 +43,7 @@ RCS comes with several supported extensions: - **rcs_flexiv**: Support for Flexiv arms (Rizon 4s) and the Flexiv Grav gripper. - **rcs_realsense**: Support for Intel RealSense cameras. - **rcs_usb_cam**: Support for generic USB webcams. +- **rcs_digit**: Support for DIGIT tactile sensors. - **rcs_tacto**: Integration with the Tacto tactile sensor simulator. - **rcs_robotiq2f85**: Integration with the Robotiq 2F-85 Gripper. diff --git a/docs/extensions/rcs_digit.md b/docs/extensions/rcs_digit.md new file mode 100644 index 000000000..86e76b182 --- /dev/null +++ b/docs/extensions/rcs_digit.md @@ -0,0 +1,20 @@ +# RCS DIGIT Extension + +This extension provides support for [DIGIT](https://digit.ml) tactile sensors in RCS. + +The sensor is exposed as an RCS `HardwareCamera`, so it is configured and polled like any other +camera in a camera set. The robot extensions register a `digit` camera type that resolves once +this extension is installed. + +## Installation + +```shell +pip install rcs-digit +``` + +For local development: + +```shell +pip install -ve . --no-build-isolation +pip install -ve extensions/rcs_digit +``` diff --git a/extensions/rcs_digit/README.md b/extensions/rcs_digit/README.md new file mode 100644 index 000000000..9c699b4c0 --- /dev/null +++ b/extensions/rcs_digit/README.md @@ -0,0 +1,53 @@ +# RCS DIGIT Extension + +Support for the [DIGIT](https://digit.ml) tactile sensor in RCS, built on the +[`digit-interface`](https://pypi.org/project/digit-interface/) driver. + +This extension depends on [`rcs-core`](https://pypi.org/project/rcs-core/). +Documentation: + +## Installation + +Install from PyPI: + +```shell +pip install rcs-digit +``` + +Warning: plain `pip install rcs-digit` will install the published `rcs-core` dependency from PyPI. + +Install from a local checkout: + +```shell +pip install -ve . +``` + +If you want this extension to use your local RCS checkout instead of the published `rcs-core` package, first install the main package from the repository root: + +```shell +pip install -ve . --no-build-isolation +pip install -ve extensions/rcs_digit +``` + +## Usage + +The robot extensions register a `digit` camera type that resolves to `DigitCam` once this +extension is installed, so a DIGIT is configured like any other hardware camera: + +```python +from rcs.envs.base import HardwareCameraCreatorConfig + +camera_cfgs["digit"] = HardwareCameraCreatorConfig( + camera_type_id="digit", + camera_cfgs={"digit": BaseCameraConfig(identifier="D00001")}, +) +``` + +`default_digit` builds those configs from a name-to-serial mapping, using the resolution and +frame rate of a named `digit-interface` stream: + +```python +from rcs_digit.camera import default_digit + +cameras = default_digit({"thumb": "D00001", "index": "D00002"}, stream_name="QVGA") +``` diff --git a/extensions/rcs_digit/pyproject.toml b/extensions/rcs_digit/pyproject.toml new file mode 100644 index 000000000..4653afbfa --- /dev/null +++ b/extensions/rcs_digit/pyproject.toml @@ -0,0 +1,23 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "rcs_digit" +version = "0.7.2" +description = "RCS DIGIT tactile sensor module" +readme = "README.md" +license = "AGPL-3.0-or-later" +dependencies = ["rcs-core>=0.7.2", "digit-interface"] +maintainers = [ + { name = "Tobias Juelg", email = "tobias.juelg@utn.de" }, +] +authors = [{ name = "Tobias Juelg", email = "tobias.juelg@utn.de" }] +requires-python = ">=3.11" + +[tool.black] +line-length = 120 +target-version = ["py310"] + +[tool.isort] +profile = "black" diff --git a/extensions/rcs_digit/src/rcs_digit/__init__.py b/extensions/rcs_digit/src/rcs_digit/__init__.py new file mode 100644 index 000000000..bc8c296f6 --- /dev/null +++ b/extensions/rcs_digit/src/rcs_digit/__init__.py @@ -0,0 +1 @@ +__version__ = "0.7.2" diff --git a/python/rcs/camera/digit_cam.py b/extensions/rcs_digit/src/rcs_digit/camera.py similarity index 65% rename from python/rcs/camera/digit_cam.py rename to extensions/rcs_digit/src/rcs_digit/camera.py index bb7113fbe..1e128a74e 100644 --- a/python/rcs/camera/digit_cam.py +++ b/extensions/rcs_digit/src/rcs_digit/camera.py @@ -1,4 +1,10 @@ -from digit_interface.digit import Digit +"""DIGIT tactile sensor support, built on the `digit-interface` driver. + +The sensor is exposed as an RCS `HardwareCamera`, so it is configured and polled like any other +camera in a camera set. `default_digit` builds the per-sensor configs from a name-to-serial map. +""" + +from digit_interface import Digit from rcs._core.common import BaseCameraConfig from rcs.camera.hw import HardwareCamera from rcs.camera.interface import CameraFrame, DataFrame, Frame @@ -55,3 +61,20 @@ def config(self, camera_name) -> BaseCameraConfig: def calibrate(self) -> bool: """No calibration needed for DIGIT cameras.""" return True + + +def default_digit(name2id: dict[str, str] | None, stream_name: str = "QVGA") -> DigitCam | None: + """Build a `DigitCam` for `name -> serial`, sized from the named `digit-interface` stream.""" + if name2id is None: + return None + stream_dict = Digit.STREAMS[stream_name] + cameras = { + name: BaseCameraConfig( + identifier=identifier, + resolution_width=stream_dict["resolution"]["width"], + resolution_height=stream_dict["resolution"]["height"], + frame_rate=stream_dict["fps"]["30fps"], + ) + for name, identifier in name2id.items() + } + return DigitCam(cameras=cameras) diff --git a/extensions/rcs_fr3/src/rcs_fr3/creators.py b/extensions/rcs_fr3/src/rcs_fr3/creators.py index 57a1f7b05..f32393e4d 100644 --- a/extensions/rcs_fr3/src/rcs_fr3/creators.py +++ b/extensions/rcs_fr3/src/rcs_fr3/creators.py @@ -100,9 +100,9 @@ def _create_zed_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: def _create_digit_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: try: - from rcs.camera.digit_cam import DigitCam + from rcs_digit.camera import DigitCam except ImportError as e: - msg = "DIGIT camera support requires the `digit_interface` package to be installed." + msg = "DIGIT camera support requires the `rcs_digit` extension to be installed." raise ImportError(msg) from e return typing.cast(HardwareCamera, DigitCam(cameras=cfg.camera_cfgs)) diff --git a/extensions/rcs_panda/src/rcs_panda/creators.py b/extensions/rcs_panda/src/rcs_panda/creators.py index 9ac11494a..6aa47a9f9 100644 --- a/extensions/rcs_panda/src/rcs_panda/creators.py +++ b/extensions/rcs_panda/src/rcs_panda/creators.py @@ -61,9 +61,9 @@ def _create_realsense_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera def _create_digit_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: try: - from rcs.camera.digit_cam import DigitCam + from rcs_digit.camera import DigitCam except ImportError as e: - msg = "DIGIT camera support requires the `digit_interface` package to be installed." + msg = "DIGIT camera support requires the `rcs_digit` extension to be installed." raise ImportError(msg) from e return typing.cast(HardwareCamera, DigitCam(cameras=cfg.camera_cfgs)) diff --git a/extensions/rcs_so101/src/rcs_so101/creators.py b/extensions/rcs_so101/src/rcs_so101/creators.py index 7381b497c..1b04d4e2d 100644 --- a/extensions/rcs_so101/src/rcs_so101/creators.py +++ b/extensions/rcs_so101/src/rcs_so101/creators.py @@ -49,9 +49,9 @@ def _create_realsense_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera def _create_digit_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: try: - from rcs.camera.digit_cam import DigitCam + from rcs_digit.camera import DigitCam except ImportError as e: - msg = "DIGIT camera support requires the `digit_interface` package to be installed." + msg = "DIGIT camera support requires the `rcs_digit` extension to be installed." raise ImportError(msg) from e return typing.cast(HardwareCamera, DigitCam(cameras=cfg.camera_cfgs)) diff --git a/extensions/rcs_ur5e/src/rcs_ur5e/creators.py b/extensions/rcs_ur5e/src/rcs_ur5e/creators.py index aa943714c..2c8627bb8 100644 --- a/extensions/rcs_ur5e/src/rcs_ur5e/creators.py +++ b/extensions/rcs_ur5e/src/rcs_ur5e/creators.py @@ -50,9 +50,9 @@ def _create_realsense_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera def _create_digit_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: try: - from rcs.camera.digit_cam import DigitCam + from rcs_digit.camera import DigitCam except ImportError as e: - msg = "DIGIT camera support requires the `digit_interface` package to be installed." + msg = "DIGIT camera support requires the `rcs_digit` extension to be installed." raise ImportError(msg) from e return typing.cast(HardwareCamera, DigitCam(cameras=cfg.camera_cfgs)) diff --git a/extensions/rcs_xarm7/src/rcs_xarm7/creators.py b/extensions/rcs_xarm7/src/rcs_xarm7/creators.py index 36c198154..71ea1c4f7 100644 --- a/extensions/rcs_xarm7/src/rcs_xarm7/creators.py +++ b/extensions/rcs_xarm7/src/rcs_xarm7/creators.py @@ -53,9 +53,9 @@ def _create_realsense_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera def _create_digit_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: try: - from rcs.camera.digit_cam import DigitCam + from rcs_digit.camera import DigitCam except ImportError as e: - msg = "DIGIT camera support requires the `digit_interface` package to be installed." + msg = "DIGIT camera support requires the `rcs_digit` extension to be installed." raise ImportError(msg) from e return typing.cast(HardwareCamera, DigitCam(cameras=cfg.camera_cfgs)) diff --git a/pyproject.toml b/pyproject.toml index 9af1e7f8b..36046e159 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,6 @@ dependencies = [ "python-dotenv>=1.0.1", "opencv-python~=4.10.0.84", "tilburg-hand", - "digit-interface", "pyopengl>=3.1.9", "ompl>=1.7.0; sys_platform == 'linux'", "rpyc~=6.0.2", @@ -213,6 +212,10 @@ version_files = [ "extensions/rcs_so101/pyproject.toml:\"rcs-core>=(.*)\"", # --- Other Extensions --- + "extensions/rcs_digit/pyproject.toml:version", + "extensions/rcs_digit/src/rcs_digit/__init__.py:__version__", + "extensions/rcs_digit/pyproject.toml:\"rcs-core>=(.*)\"", + "extensions/rcs_realsense/pyproject.toml:version", "extensions/rcs_realsense/src/rcs_realsense/__init__.py:__version__", "extensions/rcs_realsense/pyproject.toml:\"rcs-core>=(.*)\"", diff --git a/python/rcs/envs/utils.py b/python/rcs/envs/utils.py index 4319b059c..718916609 100644 --- a/python/rcs/envs/utils.py +++ b/python/rcs/envs/utils.py @@ -1,9 +1,6 @@ import logging -from digit_interface import Digit -from rcs._core.common import BaseCameraConfig from rcs._core.sim import SimCameraConfig -from rcs.camera.digit_cam import DigitCam from rcs import sim @@ -15,22 +12,6 @@ def default_sim_tilburg_hand_cfg() -> sim.SimTilburgHandConfig: return sim.SimTilburgHandConfig() -def default_digit(name2id: dict[str, str] | None, stream_name: str = "QVGA") -> DigitCam | None: - if name2id is None: - return None - stream_dict = Digit.STREAMS[stream_name] - cameras = { - name: BaseCameraConfig( - identifier=identifier, - resolution_width=stream_dict["resolution"]["width"], - resolution_height=stream_dict["resolution"]["height"], - frame_rate=stream_dict["fps"]["30fps"], - ) - for name, identifier in name2id.items() - } - return DigitCam(cameras=cameras) - - def default_mujoco_cameraset_cfg() -> dict[str, SimCameraConfig]: # Kept for backwards compatibility in docs/comments while examples migrate. return { From ba5ebcee49cf6b9f2501517ef2c6f12900bed8b6 Mon Sep 17 00:00:00 2001 From: Tobias Juelg Date: Mon, 5 Oct 2026 20:17:51 -0700 Subject: [PATCH 02/16] refactor(tilburg hand): moved tilburg hand into own extension --- .github/workflows/build_wheels.yaml | 1 + .github/workflows/ci.yaml | 1 + Makefile | 2 +- docs/extensions/index.md | 1 + docs/extensions/overview.md | 1 + docs/extensions/rcs_tilburg_hand.md | 22 +++++++++ extensions/rcs_fr3/pyproject.toml | 2 +- extensions/rcs_fr3/src/rcs_fr3/creators.py | 11 ++--- extensions/rcs_panda/pyproject.toml | 2 +- .../rcs_panda/src/rcs_panda/creators.py | 9 ++-- extensions/rcs_tilburg_hand/README.md | 48 +++++++++++++++++++ extensions/rcs_tilburg_hand/pyproject.toml | 23 +++++++++ .../src/rcs_tilburg_hand/__init__.py | 1 + .../src/rcs_tilburg_hand/hand.py | 0 extensions/rcs_xarm7/pyproject.toml | 2 +- .../rcs_xarm7/src/rcs_xarm7/creators.py | 2 +- .../rcs_xarm7/src/rcs_xarm7/env_grasp.py | 2 +- pyproject.toml | 8 +++- python/rcs/__init__.py | 3 +- python/rcs/hand/__init__.py | 0 20 files changed, 121 insertions(+), 20 deletions(-) create mode 100644 docs/extensions/rcs_tilburg_hand.md create mode 100644 extensions/rcs_tilburg_hand/README.md create mode 100644 extensions/rcs_tilburg_hand/pyproject.toml create mode 100644 extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/__init__.py rename python/rcs/hand/tilburg_hand.py => extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/hand.py (100%) delete mode 100644 python/rcs/hand/__init__.py diff --git a/.github/workflows/build_wheels.yaml b/.github/workflows/build_wheels.yaml index b37c97f14..8d0d0d4bb 100644 --- a/.github/workflows/build_wheels.yaml +++ b/.github/workflows/build_wheels.yaml @@ -86,6 +86,7 @@ jobs: - rcs_flexiv - rcs_realsense - rcs_robotiq2f85 + - rcs_tilburg_hand - rcs_ur5e - rcs_usb_cam - rcs_xarm7 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 227c4199f..3f1cb87c5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -88,6 +88,7 @@ jobs: # Python extensions - rcs_xarm7 - rcs_digit + - rcs_tilburg_hand - rcs_realsense - rcs_robotiq2f85 - rcs_tacto diff --git a/Makefile b/Makefile index 760d08e88..d58b7bdec 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ WHEELHOUSE = wheelhouse CORE_WHEELHOUSE = ${WHEELHOUSE}/core PY_EXT_WHEELHOUSE = ${WHEELHOUSE}/py_extensions CPP_EXT_WHEELHOUSE = ${WHEELHOUSE}/cpp_extensions -PY_EXTENSIONS ?= rcs_digit rcs_flexiv rcs_realsense rcs_robotiq2f85 rcs_ur5e rcs_usb_cam rcs_xarm7 rcs_zed +PY_EXTENSIONS ?= rcs_digit rcs_flexiv rcs_realsense rcs_robotiq2f85 rcs_tilburg_hand rcs_ur5e rcs_usb_cam rcs_xarm7 rcs_zed CPP_EXTENSIONS ?= rcs_fr3 rcs_panda rcs_so101 # set to pypi to publish to the real index PYPI_REPOSITORY ?= testpypi diff --git a/docs/extensions/index.md b/docs/extensions/index.md index 91e4d778a..a4fdd03cd 100644 --- a/docs/extensions/index.md +++ b/docs/extensions/index.md @@ -17,5 +17,6 @@ rcs_digit rcs_usb_cam rcs_tacto rcs_robotiq2f85 +rcs_tilburg_hand rcs_zed ``` diff --git a/docs/extensions/overview.md b/docs/extensions/overview.md index 97f3bef26..4b7f37a27 100644 --- a/docs/extensions/overview.md +++ b/docs/extensions/overview.md @@ -44,6 +44,7 @@ RCS comes with several supported extensions: - **rcs_realsense**: Support for Intel RealSense cameras. - **rcs_usb_cam**: Support for generic USB webcams. - **rcs_digit**: Support for DIGIT tactile sensors. +- **rcs_tilburg_hand**: Support for the Tilburg Hand (hardware; the simulated hand is in `rcs-core`). - **rcs_tacto**: Integration with the Tacto tactile sensor simulator. - **rcs_robotiq2f85**: Integration with the Robotiq 2F-85 Gripper. diff --git a/docs/extensions/rcs_tilburg_hand.md b/docs/extensions/rcs_tilburg_hand.md new file mode 100644 index 000000000..5c82b6ccd --- /dev/null +++ b/docs/extensions/rcs_tilburg_hand.md @@ -0,0 +1,22 @@ +# RCS Tilburg Hand Extension + +This extension provides support for the Tilburg Hand in RCS. + +It covers the **hardware** hand only. The simulated hand, `rcs.sim.SimTilburgHand`, is implemented +in C++ inside `rcs-core` and needs nothing from this extension. + +The arm extensions accept a `THConfig` wherever they take a gripper config, and attach the hand +through a `HandWrapper` once this extension is installed. + +## Installation + +```shell +pip install rcs-tilburg-hand +``` + +For local development: + +```shell +pip install -ve . --no-build-isolation +pip install -ve extensions/rcs_tilburg_hand +``` diff --git a/extensions/rcs_fr3/pyproject.toml b/extensions/rcs_fr3/pyproject.toml index dd9703fac..ce5b53f4b 100644 --- a/extensions/rcs_fr3/pyproject.toml +++ b/extensions/rcs_fr3/pyproject.toml @@ -16,7 +16,7 @@ build-backend = "scikit_build_core.build" name = "rcs_fr3" version = "0.7.4" description = "RCS libfranka integration" -dependencies = ["rcs-core>=0.7.4", "frankik"] +dependencies = ["rcs-core>=0.7.4", "rcs-tilburg-hand>=0.7.2", "frankik"] readme = "README.md" license = "AGPL-3.0-or-later" maintainers = [{ name = "Tobias Juelg", email = "tobias.juelg@utn.de" }] diff --git a/extensions/rcs_fr3/src/rcs_fr3/creators.py b/extensions/rcs_fr3/src/rcs_fr3/creators.py index f32393e4d..52203a10a 100644 --- a/extensions/rcs_fr3/src/rcs_fr3/creators.py +++ b/extensions/rcs_fr3/src/rcs_fr3/creators.py @@ -4,8 +4,6 @@ import gymnasium as gym import numpy as np -import rcs.hand.tilburg_hand -from frankik import FrankaKinematics from rcs._core.common import BaseCameraConfig, Gripper, GripperConfig, Kinematics, Pose from rcs.camera.hw import ( CalibrationStrategy, @@ -27,11 +25,12 @@ RobotWrapper, ) from rcs.envs.scenes import RCSEnvCreator, WrapperConfig -from rcs.hand.tilburg_hand import TilburgHand from rcs_fr3._core import hw from rcs_fr3.envs import FR3HW +from rcs_tilburg_hand.hand import THConfig, TilburgHand import rcs +from frankik import FrankaKinematics logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) @@ -159,7 +158,7 @@ def _create_robotiq_gripper(cfg: GripperConfig) -> Gripper: class FR3HardwareEnvCreatorConfig: robot_cfg: hw.FR3Config control_mode: ControlMode - gripper_cfg: GripperConfig | rcs.hand.tilburg_hand.THConfig | None = None + gripper_cfg: GripperConfig | THConfig | None = None camera_cfgs: dict[str, HardwareCameraCreatorConfig] | None = None max_relative_movement: float | tuple[float, float] | None = None relative_to: RelativeTo = RelativeTo.LAST_STEP @@ -172,7 +171,7 @@ class FR3HardwareEnvCreatorConfig: class FR3MultiHardwareEnvCreatorConfig: robot_cfgs: dict[str, hw.FR3Config] control_mode: ControlMode - gripper_cfgs: dict[str, GripperConfig | rcs.hand.tilburg_hand.THConfig | None] | None = None + gripper_cfgs: dict[str, GripperConfig | THConfig | None] | None = None camera_cfgs: dict[str, HardwareCameraCreatorConfig] | None = None max_relative_movement: float | tuple[float, float] | None = None relative_to: RelativeTo = RelativeTo.LAST_STEP @@ -195,7 +194,7 @@ def create_env(self, cfg: FR3HardwareEnvCreatorConfig) -> gym.Env: env: gym.Env = HardwareEnv(frequency=cfg.frequency) env = RobotWrapper(env, robot, cfg.control_mode, home_on_reset=cfg.wrapper_cfg.home_on_reset) env = FR3HW(env) - if isinstance(cfg.gripper_cfg, rcs.hand.tilburg_hand.THConfig): + if isinstance(cfg.gripper_cfg, THConfig): hand = TilburgHand(cfg.gripper_cfg) env = HandWrapper(env, hand, binary=cfg.wrapper_cfg.binary_gripper) elif cfg.gripper_cfg is not None: diff --git a/extensions/rcs_panda/pyproject.toml b/extensions/rcs_panda/pyproject.toml index c8b9bf55f..f176e8d56 100644 --- a/extensions/rcs_panda/pyproject.toml +++ b/extensions/rcs_panda/pyproject.toml @@ -15,7 +15,7 @@ build-backend = "scikit_build_core.build" name = "rcs_panda" version = "0.7.4" description = "RCS libfranka integration" -dependencies = ["rcs-core>=0.7.4"] +dependencies = ["rcs-core>=0.7.4", "rcs-tilburg-hand>=0.7.2"] readme = "README.md" license = "AGPL-3.0-or-later" maintainers = [{ name = "Tobias Juelg", email = "tobias.juelg@utn.de" }] diff --git a/extensions/rcs_panda/src/rcs_panda/creators.py b/extensions/rcs_panda/src/rcs_panda/creators.py index 6aa47a9f9..f39d91bbb 100644 --- a/extensions/rcs_panda/src/rcs_panda/creators.py +++ b/extensions/rcs_panda/src/rcs_panda/creators.py @@ -3,7 +3,6 @@ from dataclasses import dataclass, field import gymnasium as gym -import rcs.hand.tilburg_hand from rcs._core.common import BaseCameraConfig, Gripper, GripperConfig, GripperType from rcs.camera.hw import ( CalibrationStrategy, @@ -24,9 +23,9 @@ RobotWrapper, ) from rcs.envs.scenes import RCSEnvCreator, WrapperConfig -from rcs.hand.tilburg_hand import TilburgHand from rcs_panda._core import hw from rcs_panda.envs import PandaHW +from rcs_tilburg_hand.hand import THConfig, TilburgHand import rcs @@ -119,7 +118,7 @@ def _create_robotiq_gripper(cfg: GripperConfig) -> Gripper: class PandaHardwareEnvCreatorConfig: robot_cfg: hw.PandaConfig control_mode: ControlMode - gripper_cfg: GripperConfig | rcs.hand.tilburg_hand.THConfig | None = None + gripper_cfg: GripperConfig | THConfig | None = None camera_cfgs: dict[str, HardwareCameraCreatorConfig] | None = None max_relative_movement: float | tuple[float, float] | None = None relative_to: RelativeTo = RelativeTo.LAST_STEP @@ -132,7 +131,7 @@ class PandaHardwareEnvCreatorConfig: class PandaMultiHardwareEnvCreatorConfig: robot_cfgs: dict[str, hw.PandaConfig] control_mode: ControlMode - gripper_cfgs: dict[str, GripperConfig | rcs.hand.tilburg_hand.THConfig | None] | None = None + gripper_cfgs: dict[str, GripperConfig | THConfig | None] | None = None camera_cfgs: dict[str, HardwareCameraCreatorConfig] | None = None max_relative_movement: float | tuple[float, float] | None = None relative_to: RelativeTo = RelativeTo.LAST_STEP @@ -155,7 +154,7 @@ def create_env(self, cfg: PandaHardwareEnvCreatorConfig) -> gym.Env: env: gym.Env = HardwareEnv(frequency=cfg.frequency) env = RobotWrapper(env, robot, cfg.control_mode, home_on_reset=cfg.wrapper_cfg.home_on_reset) env = PandaHW(env) - if isinstance(cfg.gripper_cfg, rcs.hand.tilburg_hand.THConfig): + if isinstance(cfg.gripper_cfg, THConfig): hand = TilburgHand(cfg.gripper_cfg) env = HandWrapper(env, hand, binary=cfg.wrapper_cfg.binary_gripper) elif cfg.gripper_cfg is not None: diff --git a/extensions/rcs_tilburg_hand/README.md b/extensions/rcs_tilburg_hand/README.md new file mode 100644 index 000000000..042269690 --- /dev/null +++ b/extensions/rcs_tilburg_hand/README.md @@ -0,0 +1,48 @@ +# RCS Tilburg Hand Extension + +Support for the Tilburg Hand in RCS, built on the +[`tilburg-hand`](https://pypi.org/project/tilburg-hand/) driver. + +This extension depends on [`rcs-core`](https://pypi.org/project/rcs-core/). +Documentation: + +This covers the **hardware** hand only. The simulated hand, `rcs.sim.SimTilburgHand`, is built into +`rcs-core` and needs nothing from here. + +## Installation + +Install from PyPI: + +```shell +pip install rcs-tilburg-hand +``` + +Warning: plain `pip install rcs-tilburg-hand` will install the published `rcs-core` dependency from PyPI. + +Install from a local checkout: + +```shell +pip install -ve . +``` + +If you want this extension to use your local RCS checkout instead of the published `rcs-core` package, first install the main package from the repository root: + +```shell +pip install -ve . --no-build-isolation +pip install -ve extensions/rcs_tilburg_hand +``` + +## Usage + +The arm extensions accept a `THConfig` wherever they take a gripper config, and attach the hand +through a `HandWrapper` once this extension is installed: + +```python +from rcs_tilburg_hand.hand import THConfig + +cfg.gripper_cfg = THConfig( + calibration_file="/path/to/calibration.json", + grasp_percentage=1, + hand_orientation="right", +) +``` diff --git a/extensions/rcs_tilburg_hand/pyproject.toml b/extensions/rcs_tilburg_hand/pyproject.toml new file mode 100644 index 000000000..d31df0618 --- /dev/null +++ b/extensions/rcs_tilburg_hand/pyproject.toml @@ -0,0 +1,23 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "rcs_tilburg_hand" +version = "0.7.2" +description = "RCS Tilburg Hand module" +readme = "README.md" +license = "AGPL-3.0-or-later" +dependencies = ["rcs-core>=0.7.2", "tilburg-hand"] +maintainers = [ + { name = "Tobias Juelg", email = "tobias.juelg@utn.de" }, +] +authors = [{ name = "Tobias Juelg", email = "tobias.juelg@utn.de" }] +requires-python = ">=3.11" + +[tool.black] +line-length = 120 +target-version = ["py310"] + +[tool.isort] +profile = "black" diff --git a/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/__init__.py b/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/__init__.py new file mode 100644 index 000000000..bc8c296f6 --- /dev/null +++ b/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/__init__.py @@ -0,0 +1 @@ +__version__ = "0.7.2" diff --git a/python/rcs/hand/tilburg_hand.py b/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/hand.py similarity index 100% rename from python/rcs/hand/tilburg_hand.py rename to extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/hand.py diff --git a/extensions/rcs_xarm7/pyproject.toml b/extensions/rcs_xarm7/pyproject.toml index 70ffe2fc9..057745b8d 100644 --- a/extensions/rcs_xarm7/pyproject.toml +++ b/extensions/rcs_xarm7/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" name = "rcs_xarm7" version = "0.7.4" description = "RCS xArm7 module" -dependencies = ["rcs-core>=0.7.4", "xarm-python-sdk==1.17.0"] +dependencies = ["rcs-core>=0.7.4", "rcs-tilburg-hand>=0.7.2", "xarm-python-sdk==1.17.0"] readme = "README.md" license = "AGPL-3.0-or-later" maintainers = [ diff --git a/extensions/rcs_xarm7/src/rcs_xarm7/creators.py b/extensions/rcs_xarm7/src/rcs_xarm7/creators.py index 71ea1c4f7..8ba21f0ac 100644 --- a/extensions/rcs_xarm7/src/rcs_xarm7/creators.py +++ b/extensions/rcs_xarm7/src/rcs_xarm7/creators.py @@ -18,7 +18,7 @@ RobotWrapper, ) from rcs.envs.scenes import RCSEnvCreator, WrapperConfig -from rcs.hand.tilburg_hand import THConfig, TilburgHand +from rcs_tilburg_hand.hand import THConfig, TilburgHand from rcs_xarm7.hw import XArm7, XArm7Config import rcs diff --git a/extensions/rcs_xarm7/src/rcs_xarm7/env_grasp.py b/extensions/rcs_xarm7/src/rcs_xarm7/env_grasp.py index 53f4d1a48..4115487c9 100644 --- a/extensions/rcs_xarm7/src/rcs_xarm7/env_grasp.py +++ b/extensions/rcs_xarm7/src/rcs_xarm7/env_grasp.py @@ -5,7 +5,7 @@ from rcs._core.common import RobotPlatform from rcs.envs.base import ControlMode, RelativeTo from rcs.envs.configs import EmptyWorldXArm7 -from rcs.hand.tilburg_hand import THConfig +from rcs_tilburg_hand.hand import THConfig from rcs_xarm7.configs import DefaultXArm7HardwareEnv logger = logging.getLogger(__name__) diff --git a/pyproject.toml b/pyproject.toml index 36046e159..50b4b1dce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,6 @@ dependencies = [ "pillow>=10.3", "python-dotenv>=1.0.1", "opencv-python~=4.10.0.84", - "tilburg-hand", "pyopengl>=3.1.9", "ompl>=1.7.0; sys_platform == 'linux'", "rpyc~=6.0.2", @@ -198,12 +197,14 @@ version_files = [ "extensions/rcs_fr3/src/rcs_fr3/_core/__init__.pyi:__version__", "extensions/rcs_fr3/pyproject.toml:version", "extensions/rcs_fr3/pyproject.toml:\"rcs-core>=(.*)\"", + "extensions/rcs_fr3/pyproject.toml:\"rcs-tilburg-hand>=(.*)\"", # --- Panda Extension --- "extensions/rcs_panda/CMakeLists.txt:VERSION", "extensions/rcs_panda/src/rcs_panda/_core/__init__.pyi:__version__", "extensions/rcs_panda/pyproject.toml:version", "extensions/rcs_panda/pyproject.toml:\"rcs-core>=(.*)\"", + "extensions/rcs_panda/pyproject.toml:\"rcs-tilburg-hand>=(.*)\"", # --- SO101 --- "extensions/rcs_so101/CMakeLists.txt:VERSION", @@ -223,6 +224,11 @@ version_files = [ "extensions/rcs_xarm7/pyproject.toml:version", "extensions/rcs_xarm7/src/rcs_xarm7/__init__.py:__version__", "extensions/rcs_xarm7/pyproject.toml:\"rcs-core>=(.*)\"", + "extensions/rcs_xarm7/pyproject.toml:\"rcs-tilburg-hand>=(.*)\"", + + "extensions/rcs_tilburg_hand/pyproject.toml:version", + "extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/__init__.py:__version__", + "extensions/rcs_tilburg_hand/pyproject.toml:\"rcs-core>=(.*)\"", "extensions/rcs_ur5e/pyproject.toml:version", "extensions/rcs_ur5e/src/rcs_ur5e/__init__.py:__version__", diff --git a/python/rcs/__init__.py b/python/rcs/__init__.py index 778210847..6b4d8966e 100644 --- a/python/rcs/__init__.py +++ b/python/rcs/__init__.py @@ -15,7 +15,7 @@ import requests from rcs._core import __version__, common -from rcs import camera, envs, hand, sim +from rcs import camera, envs, sim GITHUB_ASSET_ARCHIVE_URL = "https://github.com/RobotControlStack/robot-control-stack/archive/refs/tags/{tag}.zip" # written into the assets directory after a complete download, holds the version the assets belong to @@ -408,7 +408,6 @@ class RobotMetaConfig: "sim", "camera", "envs", - "hand", "ROBOTS", "GRIPPER_PATHS", "SCENE_PATHS", diff --git a/python/rcs/hand/__init__.py b/python/rcs/hand/__init__.py deleted file mode 100644 index e69de29bb..000000000 From dbf2e4455bf180fe79e69e93d74e5e43f7eb615b Mon Sep 17 00:00:00 2001 From: Tobias Juelg Date: Mon, 5 Oct 2026 21:14:56 -0700 Subject: [PATCH 03/16] chore: added handtype type for robotic hands --- extensions/rcs_fr3/src/rcs_fr3/creators.py | 37 ++++++++++++++++--- .../rcs_panda/src/rcs_panda/creators.py | 36 +++++++++++++++--- .../src/rcs_tilburg_hand/hand.py | 2 +- .../rcs_xarm7/src/rcs_xarm7/creators.py | 22 +++++++++-- include/rcs/Robot.h | 8 ++++ python/rcs/_core/common.pyi | 15 +++++++- src/pybind/rcs.cpp | 13 ++++++- 7 files changed, 117 insertions(+), 16 deletions(-) diff --git a/extensions/rcs_fr3/src/rcs_fr3/creators.py b/extensions/rcs_fr3/src/rcs_fr3/creators.py index 52203a10a..d3540b581 100644 --- a/extensions/rcs_fr3/src/rcs_fr3/creators.py +++ b/extensions/rcs_fr3/src/rcs_fr3/creators.py @@ -4,7 +4,15 @@ import gymnasium as gym import numpy as np -from rcs._core.common import BaseCameraConfig, Gripper, GripperConfig, Kinematics, Pose +from rcs._core.common import ( + BaseCameraConfig, + Gripper, + GripperConfig, + Hand, + HandConfig, + Kinematics, + Pose, +) from rcs.camera.hw import ( CalibrationStrategy, DummyCalibrationStrategy, @@ -154,11 +162,24 @@ def _create_robotiq_gripper(cfg: GripperConfig) -> Gripper: } +def _create_tilburg_hand(cfg: HandConfig) -> Hand: + if not isinstance(cfg, THConfig): + msg = f"Expected THConfig for tilburg hand, got {type(cfg).__name__}" + raise TypeError(msg) + return TilburgHand(cfg) + + +HARDWARE_HAND_CREATORS: dict[str, typing.Callable[[HandConfig], Hand]] = { + rcs.common.HandType.TilburgHand.id: _create_tilburg_hand, +} + + @dataclass(kw_only=True) class FR3HardwareEnvCreatorConfig: robot_cfg: hw.FR3Config control_mode: ControlMode - gripper_cfg: GripperConfig | THConfig | None = None + gripper_cfg: GripperConfig | None = None + hand_cfg: HandConfig | None = None camera_cfgs: dict[str, HardwareCameraCreatorConfig] | None = None max_relative_movement: float | tuple[float, float] | None = None relative_to: RelativeTo = RelativeTo.LAST_STEP @@ -171,7 +192,8 @@ class FR3HardwareEnvCreatorConfig: class FR3MultiHardwareEnvCreatorConfig: robot_cfgs: dict[str, hw.FR3Config] control_mode: ControlMode - gripper_cfgs: dict[str, GripperConfig | THConfig | None] | None = None + gripper_cfgs: dict[str, GripperConfig | None] | None = None + hand_cfgs: dict[str, HandConfig | None] | None = None camera_cfgs: dict[str, HardwareCameraCreatorConfig] | None = None max_relative_movement: float | tuple[float, float] | None = None relative_to: RelativeTo = RelativeTo.LAST_STEP @@ -194,8 +216,12 @@ def create_env(self, cfg: FR3HardwareEnvCreatorConfig) -> gym.Env: env: gym.Env = HardwareEnv(frequency=cfg.frequency) env = RobotWrapper(env, robot, cfg.control_mode, home_on_reset=cfg.wrapper_cfg.home_on_reset) env = FR3HW(env) - if isinstance(cfg.gripper_cfg, THConfig): - hand = TilburgHand(cfg.gripper_cfg) + if cfg.hand_cfg is not None: + hand_type_id = cfg.hand_cfg.hand_type.id + if hand_type_id not in HARDWARE_HAND_CREATORS: + msg = f"Unknown hardware hand type id: {hand_type_id}" + raise ValueError(msg) + hand = HARDWARE_HAND_CREATORS[hand_type_id](cfg.hand_cfg) env = HandWrapper(env, hand, binary=cfg.wrapper_cfg.binary_gripper) elif cfg.gripper_cfg is not None: gripper_type_id = cfg.gripper_cfg.gripper_type.id @@ -232,6 +258,7 @@ def create_env(self, cfg: FR3MultiHardwareEnvCreatorConfig) -> gym.Env: robot_cfg=robot_cfg, control_mode=cfg.control_mode, gripper_cfg=cfg.gripper_cfgs[robot_name] if cfg.gripper_cfgs is not None else None, + hand_cfg=cfg.hand_cfgs[robot_name] if cfg.hand_cfgs is not None else None, camera_cfgs=None, max_relative_movement=cfg.max_relative_movement, relative_to=cfg.relative_to, diff --git a/extensions/rcs_panda/src/rcs_panda/creators.py b/extensions/rcs_panda/src/rcs_panda/creators.py index f39d91bbb..19eccaa03 100644 --- a/extensions/rcs_panda/src/rcs_panda/creators.py +++ b/extensions/rcs_panda/src/rcs_panda/creators.py @@ -3,7 +3,14 @@ from dataclasses import dataclass, field import gymnasium as gym -from rcs._core.common import BaseCameraConfig, Gripper, GripperConfig, GripperType +from rcs._core.common import ( + BaseCameraConfig, + Gripper, + GripperConfig, + GripperType, + Hand, + HandConfig, +) from rcs.camera.hw import ( CalibrationStrategy, DummyCalibrationStrategy, @@ -114,11 +121,24 @@ def _create_robotiq_gripper(cfg: GripperConfig) -> Gripper: } +def _create_tilburg_hand(cfg: HandConfig) -> Hand: + if not isinstance(cfg, THConfig): + msg = f"Expected THConfig for tilburg hand, got {type(cfg).__name__}" + raise TypeError(msg) + return TilburgHand(cfg) + + +HARDWARE_HAND_CREATORS: dict[str, typing.Callable[[HandConfig], Hand]] = { + rcs.common.HandType.TilburgHand.id: _create_tilburg_hand, +} + + @dataclass(kw_only=True) class PandaHardwareEnvCreatorConfig: robot_cfg: hw.PandaConfig control_mode: ControlMode - gripper_cfg: GripperConfig | THConfig | None = None + gripper_cfg: GripperConfig | None = None + hand_cfg: HandConfig | None = None camera_cfgs: dict[str, HardwareCameraCreatorConfig] | None = None max_relative_movement: float | tuple[float, float] | None = None relative_to: RelativeTo = RelativeTo.LAST_STEP @@ -131,7 +151,8 @@ class PandaHardwareEnvCreatorConfig: class PandaMultiHardwareEnvCreatorConfig: robot_cfgs: dict[str, hw.PandaConfig] control_mode: ControlMode - gripper_cfgs: dict[str, GripperConfig | THConfig | None] | None = None + gripper_cfgs: dict[str, GripperConfig | None] | None = None + hand_cfgs: dict[str, HandConfig | None] | None = None camera_cfgs: dict[str, HardwareCameraCreatorConfig] | None = None max_relative_movement: float | tuple[float, float] | None = None relative_to: RelativeTo = RelativeTo.LAST_STEP @@ -154,8 +175,12 @@ def create_env(self, cfg: PandaHardwareEnvCreatorConfig) -> gym.Env: env: gym.Env = HardwareEnv(frequency=cfg.frequency) env = RobotWrapper(env, robot, cfg.control_mode, home_on_reset=cfg.wrapper_cfg.home_on_reset) env = PandaHW(env) - if isinstance(cfg.gripper_cfg, THConfig): - hand = TilburgHand(cfg.gripper_cfg) + if cfg.hand_cfg is not None: + hand_type_id = cfg.hand_cfg.hand_type.id + if hand_type_id not in HARDWARE_HAND_CREATORS: + msg = f"Unknown hardware hand type id: {hand_type_id}" + raise ValueError(msg) + hand = HARDWARE_HAND_CREATORS[hand_type_id](cfg.hand_cfg) env = HandWrapper(env, hand, binary=cfg.wrapper_cfg.binary_gripper) elif cfg.gripper_cfg is not None: gripper_type_id = cfg.gripper_cfg.gripper_type.id @@ -190,6 +215,7 @@ def create_env(self, cfg: PandaMultiHardwareEnvCreatorConfig) -> gym.Env: robot_cfg=robot_cfg, control_mode=cfg.control_mode, gripper_cfg=cfg.gripper_cfgs[robot_name] if cfg.gripper_cfgs is not None else None, + hand_cfg=cfg.hand_cfgs[robot_name] if cfg.hand_cfgs is not None else None, camera_cfgs=None, max_relative_movement=cfg.max_relative_movement, relative_to=cfg.relative_to, diff --git a/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/hand.py b/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/hand.py index 9800dc316..3a297b5e3 100644 --- a/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/hand.py +++ b/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/hand.py @@ -25,7 +25,7 @@ def __init__( hand_orientation: str = "right", grasp_type: common.GraspType = common.GraspType.POWER_GRASP, ) -> None: - super().__init__() + super().__init__(hand_type=common.HandType.TilburgHand) self.calibration_file = calibration_file self.grasp_percentage = grasp_percentage self.control_unit = control_unit diff --git a/extensions/rcs_xarm7/src/rcs_xarm7/creators.py b/extensions/rcs_xarm7/src/rcs_xarm7/creators.py index 8ba21f0ac..8eded4f47 100644 --- a/extensions/rcs_xarm7/src/rcs_xarm7/creators.py +++ b/extensions/rcs_xarm7/src/rcs_xarm7/creators.py @@ -5,7 +5,7 @@ from pathlib import Path import gymnasium as gym -from rcs._core.common import BaseCameraConfig +from rcs._core.common import BaseCameraConfig, Hand, HandConfig from rcs.camera.hw import CalibrationStrategy, HardwareCamera, HardwareCameraSet from rcs.envs.base import ( CameraSetWrapper, @@ -27,6 +27,18 @@ logger.setLevel(logging.INFO) +def _create_tilburg_hand(cfg: HandConfig) -> Hand: + if not isinstance(cfg, THConfig): + msg = f"Expected THConfig for tilburg hand, got {type(cfg).__name__}" + raise TypeError(msg) + return TilburgHand(cfg=cfg, verbose=True) + + +HARDWARE_HAND_CREATORS: dict[str, typing.Callable[[HandConfig], Hand]] = { + rcs.common.HandType.TilburgHand.id: _create_tilburg_hand, +} + + @dataclass(kw_only=True) class HardwareCameraCreatorConfig: camera_type_id: str @@ -87,7 +99,7 @@ class XArm7HardwareEnvCreatorConfig: control_mode: ControlMode calibration_dir: PathLike | str | None = None camera_cfgs: dict[str, HardwareCameraCreatorConfig] | None = None - hand_cfg: THConfig | None = None + hand_cfg: HandConfig | None = None max_relative_movement: float | tuple[float, float] | None = None relative_to: RelativeTo = RelativeTo.LAST_STEP frequency: float | None = None @@ -117,7 +129,11 @@ def create_env(self, cfg: XArm7HardwareEnvCreatorConfig) -> gym.Env: logger.info("CameraSet started") env = CameraSetWrapper(env, camera_set, include_depth=True) if cfg.hand_cfg is not None: - hand = TilburgHand(cfg=cfg.hand_cfg, verbose=True) + hand_type_id = cfg.hand_cfg.hand_type.id + if hand_type_id not in HARDWARE_HAND_CREATORS: + msg = f"Unknown hardware hand type id: {hand_type_id}" + raise ValueError(msg) + hand = HARDWARE_HAND_CREATORS[hand_type_id](cfg.hand_cfg) env = HandWrapper(env, hand, cfg.wrapper_cfg.binary_gripper) if cfg.relative_to != RelativeTo.NONE: diff --git a/include/rcs/Robot.h b/include/rcs/Robot.h index cf33b36d6..9cf5dcf17 100644 --- a/include/rcs/Robot.h +++ b/include/rcs/Robot.h @@ -93,7 +93,15 @@ enum GraspType { LATERAL_GRASP, TRIPOD_GRASP }; +struct HandType : public TypeBase { + using TypeBase::TypeBase; + + static const HandType TilburgHand; +}; +inline const HandType HandType::TilburgHand{"TilburgHand"}; + struct HandConfig { + HandType hand_type = HandType::TilburgHand; virtual ~HandConfig() {}; }; struct HandState { diff --git a/python/rcs/_core/common.pyi b/python/rcs/_core/common.pyi index b9d0385cf..e05237bbc 100644 --- a/python/rcs/_core/common.pyi +++ b/python/rcs/_core/common.pyi @@ -20,6 +20,7 @@ __all__: list[str] = [ "HARDWARE", "Hand", "HandConfig", + "HandType", "HandState", "IdentityRotMatrix", "IdentityRotQuatVec", @@ -130,8 +131,20 @@ class Hand: def set_normalized_joint_poses(self, q: numpy.ndarray[tuple[M], numpy.dtype[numpy.float64]]) -> None: ... def shut(self) -> None: ... +class HandType: + TilburgHand: typing.ClassVar[HandType] # value = + @staticmethod + def get_all() -> list[HandType]: ... + def __eq__(self, arg0: typing.Any) -> bool: ... + def __hash__(self) -> int: ... + def __init__(self, arg0: str) -> None: ... + def __repr__(self) -> str: ... + @property + def id(self) -> str: ... + class HandConfig: - def __init__(self) -> None: ... + hand_type: HandType + def __init__(self, hand_type: HandType = ...) -> None: ... class HandState: def __init__(self) -> None: ... diff --git a/src/pybind/rcs.cpp b/src/pybind/rcs.cpp index 0ebd39b9c..705219e84 100644 --- a/src/pybind/rcs.cpp +++ b/src/pybind/rcs.cpp @@ -481,7 +481,18 @@ PYBIND11_MODULE(_core, m) { .value("LATERAL_GRASP", rcs::common::GraspType::LATERAL_GRASP) .value("TRIPOD_GRASP", rcs::common::GraspType::TRIPOD_GRASP) .export_values(); - py::class_(common, "HandConfig").def(py::init<>()); + bind_type_class(common, "HandType") + .def_readonly_static("TilburgHand", &rcs::common::HandType::TilburgHand); + + rcs::common::HandConfig default_hand_config; + py::class_(common, "HandConfig") + .def(py::init([](rcs::common::HandType hand_type) { + rcs::common::HandConfig config; + config.hand_type = hand_type; + return config; + }), + py::arg("hand_type") = default_hand_config.hand_type) + .def_readwrite("hand_type", &rcs::common::HandConfig::hand_type); py::class_(common, "HandState").def(py::init<>()); // holder type should be smart pointer as we deal with smart pointer From a5017d22159bf00089cc39614a4d57f0b72015aa Mon Sep 17 00:00:00 2001 From: Tobias Juelg Date: Mon, 5 Oct 2026 21:29:26 -0700 Subject: [PATCH 04/16] refactor: supported robot types in bindings --- extensions/rcs_fr3/src/rcs_fr3/configs.py | 6 ++-- extensions/rcs_fr3/src/rcs_fr3/creators.py | 2 +- extensions/rcs_panda/src/rcs_panda/configs.py | 2 +- .../rcs_robotiq2f85/src/rcs_robotiq2f85/hw.py | 2 +- extensions/rcs_so101/src/rcs_so101/configs.py | 12 ++++---- .../rcs_taxim/src/rcs_taxim/creators.py | 6 ++-- extensions/rcs_ur5e/src/rcs_ur5e/configs.py | 4 +-- extensions/rcs_ur5e/src/rcs_ur5e/hw.py | 4 +-- extensions/rcs_xarm7/src/rcs_xarm7/configs.py | 2 +- extensions/rcs_xarm7/src/rcs_xarm7/hw.py | 2 +- extensions/rcs_yam/src/rcs_yam/configs.py | 4 +-- extensions/rcs_yam/src/rcs_yam/hw.py | 2 +- .../rcs_yam/src/rcs_yam/scripts/test_robot.py | 4 +-- include/rcs/Robot.h | 16 ++++++++++ python/rcs/__init__.py | 16 +++++----- python/rcs/_core/common.pyi | 8 +++++ python/rcs/envs/configs.py | 30 +++++++++---------- python/tests/test_kinematics.py | 8 ++--- src/pybind/rcs.cpp | 12 ++++++-- 19 files changed, 87 insertions(+), 55 deletions(-) diff --git a/extensions/rcs_fr3/src/rcs_fr3/configs.py b/extensions/rcs_fr3/src/rcs_fr3/configs.py index c989bc2c6..4727c37e4 100644 --- a/extensions/rcs_fr3/src/rcs_fr3/configs.py +++ b/extensions/rcs_fr3/src/rcs_fr3/configs.py @@ -118,7 +118,7 @@ def config(self) -> FR3MultiHardwareEnvCreatorConfig: cfg = base.config() cfg.robot_cfg.async_control = True cfg.robot_cfg.ip = self.robot_ip - cfg.robot_cfg.tcp_offset = rcs.GRIPPER_TCP_OFFSETS[common.GripperType("Robotiq2F85")] + cfg.robot_cfg.tcp_offset = rcs.GRIPPER_TCP_OFFSETS[common.GripperType.Robotiq2F85] cfg.robot_cfg.q_home = rcs.HOME_POSITIONS["FR3_DROID"] return FR3MultiHardwareEnvCreatorConfig( @@ -208,8 +208,8 @@ def config(self) -> FR3MultiHardwareEnvCreatorConfig: cfg = super().config() cfg.camera_cfgs = None - cfg.robot_cfgs["left"].tcp_offset = rcs.GRIPPER_TCP_OFFSETS[common.GripperType("Robotiq2F85")] - cfg.robot_cfgs["right"].tcp_offset = rcs.GRIPPER_TCP_OFFSETS[common.GripperType("Robotiq2F85")] + cfg.robot_cfgs["left"].tcp_offset = rcs.GRIPPER_TCP_OFFSETS[common.GripperType.Robotiq2F85] + cfg.robot_cfgs["right"].tcp_offset = rcs.GRIPPER_TCP_OFFSETS[common.GripperType.Robotiq2F85] cfg.robot_cfgs["left"].q_home = rcs.HOME_POSITIONS["FR3_DUO_LEFT"] cfg.robot_cfgs["right"].q_home = rcs.HOME_POSITIONS["FR3_DUO_RIGHT"] cfg.gripper_cfgs = { diff --git a/extensions/rcs_fr3/src/rcs_fr3/creators.py b/extensions/rcs_fr3/src/rcs_fr3/creators.py index d3540b581..21254482d 100644 --- a/extensions/rcs_fr3/src/rcs_fr3/creators.py +++ b/extensions/rcs_fr3/src/rcs_fr3/creators.py @@ -158,7 +158,7 @@ def _create_robotiq_gripper(cfg: GripperConfig) -> Gripper: HARDWARE_GRIPPER_CREATORS: dict[str, typing.Callable[[GripperConfig], Gripper]] = { rcs.common.GripperType.FrankaHand.id: _create_franka_gripper, - rcs.common.GripperType("Robotiq2F85").id: _create_robotiq_gripper, + rcs.common.GripperType.Robotiq2F85.id: _create_robotiq_gripper, } diff --git a/extensions/rcs_panda/src/rcs_panda/configs.py b/extensions/rcs_panda/src/rcs_panda/configs.py index 0c6ff8835..a21f42f95 100644 --- a/extensions/rcs_panda/src/rcs_panda/configs.py +++ b/extensions/rcs_panda/src/rcs_panda/configs.py @@ -61,7 +61,7 @@ def config(self) -> PandaMultiHardwareEnvCreatorConfig: cfg = base.config() cfg.robot_cfg.async_control = True cfg.robot_cfg.ip = self.robot_ip - cfg.robot_cfg.tcp_offset = rcs.GRIPPER_TCP_OFFSETS[common.GripperType("Robotiq2F85")] + cfg.robot_cfg.tcp_offset = rcs.GRIPPER_TCP_OFFSETS[common.GripperType.Robotiq2F85] cfg.robot_cfg.q_home = rcs.ROBOTS[RobotType.Panda].q_home return PandaMultiHardwareEnvCreatorConfig( diff --git a/extensions/rcs_robotiq2f85/src/rcs_robotiq2f85/hw.py b/extensions/rcs_robotiq2f85/src/rcs_robotiq2f85/hw.py index 8046648bd..4a4465c85 100644 --- a/extensions/rcs_robotiq2f85/src/rcs_robotiq2f85/hw.py +++ b/extensions/rcs_robotiq2f85/src/rcs_robotiq2f85/hw.py @@ -31,7 +31,7 @@ def __init__( self.speed = speed self.force = force self.async_control = async_control - self.gripper_type = rcs.common.GripperType("Robotiq2F85") + self.gripper_type = rcs.common.GripperType.Robotiq2F85 class RobotiQ2F85GripperState(GripperState): diff --git a/extensions/rcs_so101/src/rcs_so101/configs.py b/extensions/rcs_so101/src/rcs_so101/configs.py index e64c77e95..747335b64 100644 --- a/extensions/rcs_so101/src/rcs_so101/configs.py +++ b/extensions/rcs_so101/src/rcs_so101/configs.py @@ -16,12 +16,12 @@ def config(self) -> SO101HardwareEnvCreatorConfig: id=self.id, port=self.port, calibration_dir=self.calibration_dir, - robot_type=RobotType("SO101"), - kinematic_model_path=rcs.ROBOTS[RobotType("SO101")].mjcf_model_path, - attachment_site=rcs.ROBOTS[RobotType("SO101")].attachment_site, - dof=rcs.ROBOTS[RobotType("SO101")].dof, - joint_limits=rcs.ROBOTS[RobotType("SO101")].joint_limits, - q_home=rcs.ROBOTS[RobotType("SO101")].q_home, + robot_type=RobotType.SO101, + kinematic_model_path=rcs.ROBOTS[RobotType.SO101].mjcf_model_path, + attachment_site=rcs.ROBOTS[RobotType.SO101].attachment_site, + dof=rcs.ROBOTS[RobotType.SO101].dof, + joint_limits=rcs.ROBOTS[RobotType.SO101].joint_limits, + q_home=rcs.ROBOTS[RobotType.SO101].q_home, tcp_offset=rcs.common.Pose(), ) diff --git a/extensions/rcs_taxim/src/rcs_taxim/creators.py b/extensions/rcs_taxim/src/rcs_taxim/creators.py index 0c3e49841..1dc597c57 100644 --- a/extensions/rcs_taxim/src/rcs_taxim/creators.py +++ b/extensions/rcs_taxim/src/rcs_taxim/creators.py @@ -13,7 +13,7 @@ import rcs -_TAXIM_GRIPPER_TYPE = GripperType("Robotiq2F85Digit") +_TAXIM_GRIPPER_TYPE = GripperType.Robotiq2F85Digit def _prefixed(name: str) -> str: @@ -84,7 +84,7 @@ def __call__( scene = EmptyWorldFR3() cfg = scene.config() - cfg.robot_cfgs["right"].tcp_offset = rcs.GRIPPER_TCP_OFFSETS[rcs.common.GripperType("Robotiq2F85")] + cfg.robot_cfgs["right"].tcp_offset = rcs.GRIPPER_TCP_OFFSETS[rcs.common.GripperType.Robotiq2F85] cfg.control_mode = control_mode cfg.headless = render_mode != "human" cfg.sim_cfg.realtime = render_mode == "human" @@ -99,7 +99,7 @@ def __call__( if not delta_actions: cfg.max_relative_movement = None cfg.gripper_cfgs = {"right": _taxim_gripper_cfg()} - cfg.gripper_offsets = {"right": rcs.GRIPPER_MOUNT_OFFSETS[rcs.common.GripperType("Robotiq2F85")]} + cfg.gripper_offsets = {"right": rcs.GRIPPER_MOUNT_OFFSETS[rcs.common.GripperType.Robotiq2F85]} cfg.root_frame_objects = { "": ( rcs.OBJECT_PATHS["green_cuboid"], diff --git a/extensions/rcs_ur5e/src/rcs_ur5e/configs.py b/extensions/rcs_ur5e/src/rcs_ur5e/configs.py index cf5ab1fdc..010286683 100644 --- a/extensions/rcs_ur5e/src/rcs_ur5e/configs.py +++ b/extensions/rcs_ur5e/src/rcs_ur5e/configs.py @@ -10,7 +10,7 @@ class DefaultUR5eHardwareEnv(RCSUR5eConfigEnvCreator): ip = "192.168.1.15" def config(self) -> UR5eHardwareEnvCreatorConfig: - robot_type = RobotType("UR5e") + robot_type = RobotType.UR5e robot_cfg = UR5eConfig( ip=self.ip, max_velocity=1.0, @@ -31,7 +31,7 @@ def config(self) -> UR5eHardwareEnvCreatorConfig: gripper_cfg = RobotiQGripperConfig( ip=self.ip, - gripper_type=GripperType("Robotiq2F85"), + gripper_type=GripperType.Robotiq2F85, ) return UR5eHardwareEnvCreatorConfig( diff --git a/extensions/rcs_ur5e/src/rcs_ur5e/hw.py b/extensions/rcs_ur5e/src/rcs_ur5e/hw.py index 9fa9530a7..e310329ed 100644 --- a/extensions/rcs_ur5e/src/rcs_ur5e/hw.py +++ b/extensions/rcs_ur5e/src/rcs_ur5e/hw.py @@ -33,7 +33,7 @@ def __init__( ): super().__init__(**kwargs) self.robot_platform = common.RobotPlatform.HARDWARE - self.robot_type = common.RobotType("UR5e") + self.robot_type = common.RobotType.UR5e self.ip = ip # Robot movement parameters self.max_velocity = max_velocity @@ -194,7 +194,7 @@ def __init__(self, cfg: UR5eConfig, ik: common.Kinematics): super().__init__() self.ik = ik self._config = cfg - self._config.robot_type = common.RobotType("UR5e") + self._config.robot_type = common.RobotType.UR5e self._ip = cfg.ip # Delete shared memory if it exists diff --git a/extensions/rcs_xarm7/src/rcs_xarm7/configs.py b/extensions/rcs_xarm7/src/rcs_xarm7/configs.py index 792518eef..020343c3a 100644 --- a/extensions/rcs_xarm7/src/rcs_xarm7/configs.py +++ b/extensions/rcs_xarm7/src/rcs_xarm7/configs.py @@ -10,7 +10,7 @@ class DefaultXArm7HardwareEnv(RCSXArm7ConfigEnvCreator): ip = "192.168.1.245" def config(self) -> XArm7HardwareEnvCreatorConfig: - robot_type = RobotType("XArm7") + robot_type = RobotType.XArm7 robot_cfg = XArm7Config( ip=self.ip, payload_weight=0.624, diff --git a/extensions/rcs_xarm7/src/rcs_xarm7/hw.py b/extensions/rcs_xarm7/src/rcs_xarm7/hw.py index dd48f56dc..319057bc6 100644 --- a/extensions/rcs_xarm7/src/rcs_xarm7/hw.py +++ b/extensions/rcs_xarm7/src/rcs_xarm7/hw.py @@ -34,7 +34,7 @@ def __init__(self, cfg: XArm7Config, ik: common.Kinematics): self.ik = ik self._config = cfg self._config.robot_platform = common.RobotPlatform.HARDWARE - self._config.robot_type = common.RobotType("XArm7") + self._config.robot_type = common.RobotType.XArm7 self._xarm = XArmAPI(cfg.ip) self._xarm.set_mode(0) diff --git a/extensions/rcs_yam/src/rcs_yam/configs.py b/extensions/rcs_yam/src/rcs_yam/configs.py index 2d7a6f132..613ae6de5 100644 --- a/extensions/rcs_yam/src/rcs_yam/configs.py +++ b/extensions/rcs_yam/src/rcs_yam/configs.py @@ -18,8 +18,8 @@ class DefaultYamHardwareEnv(RCSYamConfigEnvCreator): gripper_force = 50.0 def config(self) -> YamHardwareEnvCreatorConfig: - robot_type = RobotType("Yam") - gripper_type = GripperType("Yam") + robot_type = RobotType.Yam + gripper_type = GripperType.Yam robot_cfg = YamConfig( channel=self.channel, gripper_type_id="linear_4310", diff --git a/extensions/rcs_yam/src/rcs_yam/hw.py b/extensions/rcs_yam/src/rcs_yam/hw.py index 3142b4715..ecf414a77 100644 --- a/extensions/rcs_yam/src/rcs_yam/hw.py +++ b/extensions/rcs_yam/src/rcs_yam/hw.py @@ -69,7 +69,7 @@ def __init__( ): super().__init__(**kwargs) self.robot_platform = common.RobotPlatform.HARDWARE - self.robot_type = common.RobotType("Yam") + self.robot_type = common.RobotType.Yam self.channel = channel self.arm_type_id = arm_type_id self.gripper_type_id = gripper_type_id diff --git a/extensions/rcs_yam/src/rcs_yam/scripts/test_robot.py b/extensions/rcs_yam/src/rcs_yam/scripts/test_robot.py index d745ecb7e..8114eb118 100644 --- a/extensions/rcs_yam/src/rcs_yam/scripts/test_robot.py +++ b/extensions/rcs_yam/src/rcs_yam/scripts/test_robot.py @@ -13,8 +13,8 @@ CHANNEL = "can0" -robot_type = common.RobotType("Yam") -gripper_type = common.GripperType("Yam") +robot_type = common.RobotType.Yam +gripper_type = common.GripperType.Yam robot_config = YamConfig( channel=CHANNEL, async_control=False, diff --git a/include/rcs/Robot.h b/include/rcs/Robot.h index 9cf5dcf17..9b9128c2a 100644 --- a/include/rcs/Robot.h +++ b/include/rcs/Robot.h @@ -46,9 +46,17 @@ struct RobotType : public TypeBase { static const RobotType FR3; static const RobotType Panda; + static const RobotType XArm7; + static const RobotType UR5e; + static const RobotType SO101; + static const RobotType Yam; }; inline const RobotType RobotType::FR3{"FR3"}; inline const RobotType RobotType::Panda{"Panda"}; +inline const RobotType RobotType::XArm7{"XArm7"}; +inline const RobotType RobotType::UR5e{"UR5e"}; +inline const RobotType RobotType::SO101{"SO101"}; +inline const RobotType RobotType::Yam{"Yam"}; struct RobotConfig { RobotType robot_type = RobotType::FR3; @@ -76,8 +84,16 @@ struct GripperType : public TypeBase { using TypeBase::TypeBase; static const GripperType FrankaHand; + static const GripperType Robotiq2F85; + static const GripperType Robotiq2F85Digit; + static const GripperType SO101; + static const GripperType Yam; }; inline const GripperType GripperType::FrankaHand{"FrankaHand"}; +inline const GripperType GripperType::Robotiq2F85{"Robotiq2F85"}; +inline const GripperType GripperType::Robotiq2F85Digit{"Robotiq2F85Digit"}; +inline const GripperType GripperType::SO101{"SO101"}; +inline const GripperType GripperType::Yam{"Yam"}; struct GripperConfig { GripperType gripper_type = GripperType::FrankaHand; diff --git a/python/rcs/__init__.py b/python/rcs/__init__.py index 6b4d8966e..6f0aa62fd 100644 --- a/python/rcs/__init__.py +++ b/python/rcs/__init__.py @@ -176,7 +176,7 @@ class RobotMetaConfig: ] ), ), - common.RobotType("XArm7"): RobotMetaConfig( + common.RobotType.XArm7: RobotMetaConfig( mjcf_model_path="assets/robots/xarm7/xarm7.xml", dof=7, q_home=np.array([0, -45.0 / 180.0 * np.pi, 0, 15.0 / 180.0 * np.pi, 0, -25.0 / 180.0 * np.pi, 0]), @@ -187,7 +187,7 @@ class RobotMetaConfig: ] ), ), - common.RobotType("UR5e"): RobotMetaConfig( + common.RobotType.UR5e: RobotMetaConfig( mjcf_model_path="assets/robots/ur5e/ur5e.xml", dof=6, q_home=np.array([0.0, -2.02711196, 1.64630026, -1.18999615, -1.57079762, 0.0]), @@ -198,7 +198,7 @@ class RobotMetaConfig: ] ), ), - common.RobotType("SO101"): RobotMetaConfig( + common.RobotType.SO101: RobotMetaConfig( mjcf_model_path="assets/robots/so101/so101.xml", dof=5, q_home=np.array([-0.01914898, -1.90521916, 1.56476701, 1.04783839, -1.40323926]), @@ -216,7 +216,7 @@ class RobotMetaConfig: ), attachment_site="gripper", ), - common.RobotType("Yam"): RobotMetaConfig( + common.RobotType.Yam: RobotMetaConfig( mjcf_model_path="assets/robots/yam/yam.xml", dof=6, q_home=np.array([0.0, 1.047, 1.047, 0.0, 0.0, 0.0]), @@ -246,16 +246,16 @@ class RobotMetaConfig: GRIPPER_PATHS: dict[common.GripperType, str] = { common.GripperType.FrankaHand: "assets/grippers/franka_hand/franka_hand.xml", - common.GripperType("Robotiq2F85"): "assets/grippers/robotiq_2f85/robotiq_2f85.xml", + common.GripperType.Robotiq2F85: "assets/grippers/robotiq_2f85/robotiq_2f85.xml", common.GripperType("FlexivGrav"): "assets/grippers/flexiv_grav/flexiv_grav.xml", } GRIPPER_TCP_OFFSETS: dict[common.GripperType, common.Pose] = { common.GripperType.FrankaHand: common.Pose(pose_matrix=common.FrankaHandTCPOffset()), - common.GripperType("Robotiq2F85"): common.Pose(translation=np.array([0, 0.0, 0.1493])), + common.GripperType.Robotiq2F85: common.Pose(translation=np.array([0, 0.0, 0.1493])), # The yam gripper is part of the robot mjcf, hence it needs no entry in GRIPPER_PATHS # and no mount offset, only the offset from the flange to the point between the fingers. - common.GripperType("Yam"): common.Pose(translation=np.array([0.0, 0.0, 0.1347])), + common.GripperType.Yam: common.Pose(translation=np.array([0.0, 0.0, 0.1347])), # The "grav_tcp" frame of Flexiv's URDF, which Flexiv's own software uses as TCP. It sits roughly at the # pad center of the fully open gripper; the closed finger tips ("closed_fingers_tcp") are at 0.2 m. common.GripperType("FlexivGrav"): common.Pose(translation=np.array([0.0, 0.0, 0.15])), @@ -265,7 +265,7 @@ class RobotMetaConfig: common.GripperType.FrankaHand: common.Pose( rotation=common.FrankaHandTCPOffset()[:3, :3], translation=np.array([0.0, 0.0, 0.0]) ), - common.GripperType("Robotiq2F85"): common.Pose( + common.GripperType.Robotiq2F85: common.Pose( translation=np.array([0.0, 0.0, 0.0]), quaternion=np.array([0.0, 0.0, 0.7071068, 0.7071068]) ), common.GripperType("FlexivGrav"): common.Pose( diff --git a/python/rcs/_core/common.pyi b/python/rcs/_core/common.pyi index e05237bbc..f7e2c612f 100644 --- a/python/rcs/_core/common.pyi +++ b/python/rcs/_core/common.pyi @@ -109,6 +109,10 @@ class GripperState: class GripperType: FrankaHand: typing.ClassVar[GripperType] # value = + Robotiq2F85: typing.ClassVar[GripperType] # value = + Robotiq2F85Digit: typing.ClassVar[GripperType] # value = + SO101: typing.ClassVar[GripperType] # value = + Yam: typing.ClassVar[GripperType] # value = @staticmethod def get_all() -> list[GripperType]: ... def __eq__(self, arg0: typing.Any) -> bool: ... @@ -308,6 +312,10 @@ class RobotState: class RobotType: FR3: typing.ClassVar[RobotType] # value = Panda: typing.ClassVar[RobotType] # value = + SO101: typing.ClassVar[RobotType] # value = + UR5e: typing.ClassVar[RobotType] # value = + XArm7: typing.ClassVar[RobotType] # value = + Yam: typing.ClassVar[RobotType] # value = @staticmethod def get_all() -> list[RobotType]: ... def __eq__(self, arg0: typing.Any) -> bool: ... diff --git a/python/rcs/envs/configs.py b/python/rcs/envs/configs.py index 7a49b78ea..96d9e9832 100644 --- a/python/rcs/envs/configs.py +++ b/python/rcs/envs/configs.py @@ -179,7 +179,7 @@ def config(self) -> SimEnvCreatorConfig: lead_robot_name = self.lead_robot_name(cfg) robot_cfg = cfg.robot_cfgs[lead_robot_name] - robot_cfg.tcp_offset = GRIPPER_TCP_OFFSETS[rcs.common.GripperType("Robotiq2F85")] + robot_cfg.tcp_offset = GRIPPER_TCP_OFFSETS[rcs.common.GripperType.Robotiq2F85] robot_cfg.q_home = rcs.ROBOTS[RobotType.FR3].q_home.copy() assert cfg.gripper_cfgs is not None @@ -192,9 +192,9 @@ def config(self) -> SimEnvCreatorConfig: gripper_cfg.min_actuator_width = 255 gripper_cfg.max_joint_width = 0.005 gripper_cfg.min_joint_width = 1.0 - gripper_cfg.gripper_type = GripperType("Robotiq2F85") + gripper_cfg.gripper_type = GripperType.Robotiq2F85 - cfg.gripper_offsets = {lead_robot_name: GRIPPER_MOUNT_OFFSETS[rcs.common.GripperType("Robotiq2F85")]} + cfg.gripper_offsets = {lead_robot_name: GRIPPER_MOUNT_OFFSETS[rcs.common.GripperType.Robotiq2F85]} cfg.robot_frame_objects = { "right": { @@ -274,7 +274,7 @@ class EmptyWorldFR3Duo(SimEnvCreator): def config(self) -> SimEnvCreatorConfig: robot_cfg: SimRobotConfig[Literal[7]] = SimRobotConfig( - tcp_offset=GRIPPER_TCP_OFFSETS[rcs.common.GripperType("Robotiq2F85")], + tcp_offset=GRIPPER_TCP_OFFSETS[rcs.common.GripperType.Robotiq2F85], robot_type=RobotType.FR3, attachment_site=rcs.ROBOTS[RobotType.FR3].attachment_site, kinematic_model_path=rcs.ROBOTS[RobotType.FR3].mjcf_model_path, @@ -336,7 +336,7 @@ def config(self) -> SimEnvCreatorConfig: actuator="fingers_actuator", max_actuator_width=0, min_actuator_width=255, - gripper_type=GripperType("Robotiq2F85"), + gripper_type=GripperType.Robotiq2F85, ) gripper_cfg_right = copy.deepcopy(gripper_cfg) @@ -411,7 +411,7 @@ def config(self) -> SimEnvCreatorConfig: robot_name="right", ), } - gripper_offset = GRIPPER_MOUNT_OFFSETS[rcs.common.GripperType("Robotiq2F85")] + gripper_offset = GRIPPER_MOUNT_OFFSETS[rcs.common.GripperType.Robotiq2F85] return SimEnvCreatorConfig( robot_cfgs=robot_cfgs, sim_cfg=sim_cfg, @@ -440,12 +440,12 @@ def config(self) -> SimEnvCreatorConfig: class EmptyWorldUR5e(EmptyWorldFR3): def config(self) -> SimEnvCreatorConfig: - rt = RobotType("UR5e") + rt = RobotType.UR5e cfg = super().config() lead_robot_name = self.lead_robot_name(cfg) robot_cfg = cfg.robot_cfgs[lead_robot_name] - robot_cfg.tcp_offset = GRIPPER_TCP_OFFSETS[rcs.common.GripperType("Robotiq2F85")] + robot_cfg.tcp_offset = GRIPPER_TCP_OFFSETS[rcs.common.GripperType.Robotiq2F85] robot_cfg.attachment_site = rcs.ROBOTS[rt].attachment_site robot_cfg.kinematic_model_path = rcs.ROBOTS[rt].mjcf_model_path robot_cfg.arm_collision_geoms = [] @@ -474,7 +474,7 @@ def config(self) -> SimEnvCreatorConfig: gripper_cfg.min_actuator_width = 255 gripper_cfg.max_joint_width = 0.005 gripper_cfg.min_joint_width = 1.0 - gripper_cfg.gripper_type = GripperType("Robotiq2F85") + gripper_cfg.gripper_type = GripperType.Robotiq2F85 cfg.camera_cfgs = None cfg.camera_adds = None @@ -486,7 +486,7 @@ def config(self) -> SimEnvCreatorConfig: class EmptyWorldXArm7(EmptyWorldFR3): def config(self) -> SimEnvCreatorConfig: - rt = RobotType("XArm7") + rt = RobotType.XArm7 cfg = super().config() lead_robot_name = self.lead_robot_name(cfg) @@ -532,7 +532,7 @@ class EmptyWorldSO101(EmptyWorldFR3): gripper_prefix_template = EmptyWorldFR3.robot_prefix_template def config(self) -> SimEnvCreatorConfig: - rt = RobotType("SO101") + rt = RobotType.SO101 cfg = super().config() lead_robot_name = self.lead_robot_name(cfg) @@ -559,7 +559,7 @@ def config(self) -> SimEnvCreatorConfig: gripper_cfg.joints = ["6"] gripper_cfg.collision_geoms = [] gripper_cfg.collision_geoms_fingers = [] - gripper_cfg.gripper_type = GripperType("SO101") + gripper_cfg.gripper_type = GripperType.SO101 cfg.camera_cfgs = None cfg.camera_adds = None @@ -573,13 +573,13 @@ class EmptyWorldYam(EmptyWorldFR3): gripper_prefix_template = EmptyWorldFR3.robot_prefix_template def config(self) -> SimEnvCreatorConfig: - rt = RobotType("Yam") + rt = RobotType.Yam cfg = super().config() lead_robot_name = self.lead_robot_name(cfg) robot_cfg = cfg.robot_cfgs[lead_robot_name] robot_cfg.robot_type = rt - robot_cfg.tcp_offset = GRIPPER_TCP_OFFSETS[GripperType("Yam")] + robot_cfg.tcp_offset = GRIPPER_TCP_OFFSETS[GripperType.Yam] robot_cfg.attachment_site = rcs.ROBOTS[rt].attachment_site robot_cfg.kinematic_model_path = rcs.ROBOTS[rt].mjcf_model_path robot_cfg.arm_collision_geoms = [] @@ -592,7 +592,7 @@ def config(self) -> SimEnvCreatorConfig: assert cfg.gripper_cfgs is not None gripper_cfg = cfg.gripper_cfgs[lead_robot_name] - gripper_cfg.gripper_type = GripperType("Yam") + gripper_cfg.gripper_type = GripperType.Yam gripper_cfg.actuator = "gripper" # right_finger is driven by an equality constraint, so only the actuated finger is listed gripper_cfg.joints = ["left_finger"] diff --git a/python/tests/test_kinematics.py b/python/tests/test_kinematics.py index 0367bcf46..2c77a4390 100644 --- a/python/tests/test_kinematics.py +++ b/python/tests/test_kinematics.py @@ -9,10 +9,10 @@ # Pinocchio drops the Panda attachment site as it sits on a body without a joint. PIN_SUPPORTED_ROBOTS = [ common.RobotType.FR3, - common.RobotType("XArm7"), - common.RobotType("UR5e"), - common.RobotType("SO101"), - common.RobotType("Yam"), + common.RobotType.XArm7, + common.RobotType.UR5e, + common.RobotType.SO101, + common.RobotType.Yam, common.RobotType("Rizon4S"), ] diff --git a/src/pybind/rcs.cpp b/src/pybind/rcs.cpp index 705219e84..484ed1a51 100644 --- a/src/pybind/rcs.cpp +++ b/src/pybind/rcs.cpp @@ -411,7 +411,11 @@ PYBIND11_MODULE(_core, m) { bind_type_class(common, "RobotType") .def_readonly_static("FR3", &rcs::common::RobotType::FR3) - .def_readonly_static("Panda", &rcs::common::RobotType::Panda); + .def_readonly_static("Panda", &rcs::common::RobotType::Panda) + .def_readonly_static("XArm7", &rcs::common::RobotType::XArm7) + .def_readonly_static("UR5e", &rcs::common::RobotType::UR5e) + .def_readonly_static("SO101", &rcs::common::RobotType::SO101) + .def_readonly_static("Yam", &rcs::common::RobotType::Yam); py::enum_(common, "RobotPlatform") .value("HARDWARE", rcs::common::RobotPlatform::HARDWARE) @@ -462,7 +466,11 @@ PYBIND11_MODULE(_core, m) { py::class_(common, "RobotState").def(py::init<>()); bind_type_class(common, "GripperType") - .def_readonly_static("FrankaHand", &rcs::common::GripperType::FrankaHand); + .def_readonly_static("FrankaHand", &rcs::common::GripperType::FrankaHand) + .def_readonly_static("Robotiq2F85", &rcs::common::GripperType::Robotiq2F85) + .def_readonly_static("Robotiq2F85Digit", &rcs::common::GripperType::Robotiq2F85Digit) + .def_readonly_static("SO101", &rcs::common::GripperType::SO101) + .def_readonly_static("Yam", &rcs::common::GripperType::Yam); rcs::common::GripperConfig default_gripper_config; py::class_(common, "GripperConfig") From bd2f5ed3b3fc988f73712125d7edbef9d1c2e4c8 Mon Sep 17 00:00:00 2001 From: Tobias Juelg Date: Mon, 5 Oct 2026 22:35:38 -0700 Subject: [PATCH 05/16] refactor(hw): creation of hardware devices with registry pattern by entry point --- docs/development/python_extension.md | 17 ++- extensions/rcs_digit/pyproject.toml | 3 + .../rcs_digit/src/rcs_digit/creators.py | 13 ++ extensions/rcs_fr3/pyproject.toml | 5 +- extensions/rcs_fr3/src/rcs_fr3/creators.py | 140 +----------------- extensions/rcs_panda/pyproject.toml | 5 +- extensions/rcs_panda/src/rcs_panda/configs.py | 1 + .../rcs_panda/src/rcs_panda/creators.py | 126 ++-------------- extensions/rcs_realsense/pyproject.toml | 3 + .../src/rcs_realsense/creators.py | 31 ++++ extensions/rcs_robotiq2f85/pyproject.toml | 3 + .../src/rcs_robotiq2f85/creators.py | 11 ++ .../rcs_so101/src/rcs_so101/creators.py | 60 +------- extensions/rcs_tilburg_hand/pyproject.toml | 3 + .../src/rcs_tilburg_hand/creators.py | 11 ++ .../src/rcs_tilburg_hand/hand.py | 2 + extensions/rcs_ur5e/src/rcs_ur5e/creators.py | 81 +--------- extensions/rcs_usb_cam/pyproject.toml | 3 + .../rcs_usb_cam/src/rcs_usb_cam/creators.py | 20 +++ extensions/rcs_xarm7/pyproject.toml | 2 +- .../rcs_xarm7/src/rcs_xarm7/creators.py | 80 +--------- extensions/rcs_yam/src/rcs_yam/creators.py | 54 +------ extensions/rcs_zed/pyproject.toml | 3 + extensions/rcs_zed/src/rcs_zed/creators.py | 24 +++ include/rcs/Robot.h | 2 + pyproject.toml | 3 - python/rcs/__init__.py | 8 +- python/rcs/_core/common.pyi | 1 + python/rcs/camera/hw.py | 25 ++++ python/rcs/registry.py | 70 +++++++++ src/pybind/rcs.cpp | 1 + 31 files changed, 294 insertions(+), 517 deletions(-) create mode 100644 extensions/rcs_digit/src/rcs_digit/creators.py create mode 100644 extensions/rcs_realsense/src/rcs_realsense/creators.py create mode 100644 extensions/rcs_robotiq2f85/src/rcs_robotiq2f85/creators.py create mode 100644 extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/creators.py create mode 100644 extensions/rcs_usb_cam/src/rcs_usb_cam/creators.py create mode 100644 extensions/rcs_zed/src/rcs_zed/creators.py create mode 100644 python/rcs/registry.py diff --git a/docs/development/python_extension.md b/docs/development/python_extension.md index 13b5b8590..0955689b3 100644 --- a/docs/development/python_extension.md +++ b/docs/development/python_extension.md @@ -36,7 +36,22 @@ rcs_myext/ 2. **Implement the Interface**: Create your device class in `src/rcs_myext/my_device.py`. You should inherit from the appropriate RCS base class (e.g., `Camera`, `Gripper`) if applicable, or implement the required methods. -3. **Register the Extension**: If your extension needs to be discoverable by RCS (e.g., for CLI tools or automatic loading), ensure it's installed in the same environment. +3. **Register the Backend**: If your extension provides a camera, gripper or hand, declare a factory + as an entry point so the robot extensions can create it from a config. The entry point name is + the type id the config carries (`camera_type_id`, `GripperType.id` or `HandType.id`), and the + group is one of `rcs.cameras`, `rcs.grippers` or `rcs.hands`: + + ```toml + [project.entry-points."rcs.cameras"] + mycam = "rcs_myext.creators:create_camera_set" + ``` + + The factory takes the config and returns the device, for a camera + `(HardwareCameraCreatorConfig) -> HardwareCamera`. Nothing else has to know about your + extension: `rcs.registry` lists installed backends from package metadata without importing + them, and imports yours only when its id is requested. Reinstall the extension after changing + entry points, they are read from the installed metadata. For code that is not installed as a + package, `rcs.registry.CAMERAS.register("mycam", create_camera_set)` does the same at runtime. ## Example: USB Camera diff --git a/extensions/rcs_digit/pyproject.toml b/extensions/rcs_digit/pyproject.toml index 4653afbfa..153788644 100644 --- a/extensions/rcs_digit/pyproject.toml +++ b/extensions/rcs_digit/pyproject.toml @@ -15,6 +15,9 @@ maintainers = [ authors = [{ name = "Tobias Juelg", email = "tobias.juelg@utn.de" }] requires-python = ">=3.11" +[project.entry-points."rcs.cameras"] +digit = "rcs_digit.creators:create_camera_set" + [tool.black] line-length = 120 target-version = ["py310"] diff --git a/extensions/rcs_digit/src/rcs_digit/creators.py b/extensions/rcs_digit/src/rcs_digit/creators.py new file mode 100644 index 000000000..c7b421dba --- /dev/null +++ b/extensions/rcs_digit/src/rcs_digit/creators.py @@ -0,0 +1,13 @@ +"""Factory for the `digit` camera backend, registered as an `rcs.cameras` entry point.""" + +import typing + +from rcs.camera.hw import HardwareCamera, HardwareCameraCreatorConfig +from rcs_digit.camera import DigitCam + + +def create_camera_set(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: + if cfg.calibration != "dummy": + msg = f"DIGIT sensors are not calibrated, got calibration {cfg.calibration!r}" + raise ValueError(msg) + return typing.cast(HardwareCamera, DigitCam(cameras=cfg.camera_cfgs)) diff --git a/extensions/rcs_fr3/pyproject.toml b/extensions/rcs_fr3/pyproject.toml index ce5b53f4b..ea6865ca6 100644 --- a/extensions/rcs_fr3/pyproject.toml +++ b/extensions/rcs_fr3/pyproject.toml @@ -16,7 +16,7 @@ build-backend = "scikit_build_core.build" name = "rcs_fr3" version = "0.7.4" description = "RCS libfranka integration" -dependencies = ["rcs-core>=0.7.4", "rcs-tilburg-hand>=0.7.2", "frankik"] +dependencies = ["rcs-core>=0.7.4", "frankik"] readme = "README.md" license = "AGPL-3.0-or-later" maintainers = [{ name = "Tobias Juelg", email = "tobias.juelg@utn.de" }] @@ -24,6 +24,9 @@ authors = [{ name = "Tobias Juelg", email = "tobias.juelg@utn.de" }] requires-python = ">=3.11" +[project.entry-points."rcs.grippers"] +FrankaHand = "rcs_fr3.creators:create_franka_gripper" + [dependency-groups] build_deps = [ "pin==3.7.0", diff --git a/extensions/rcs_fr3/src/rcs_fr3/creators.py b/extensions/rcs_fr3/src/rcs_fr3/creators.py index 21254482d..31f9fe927 100644 --- a/extensions/rcs_fr3/src/rcs_fr3/creators.py +++ b/extensions/rcs_fr3/src/rcs_fr3/creators.py @@ -4,21 +4,8 @@ import gymnasium as gym import numpy as np -from rcs._core.common import ( - BaseCameraConfig, - Gripper, - GripperConfig, - Hand, - HandConfig, - Kinematics, - Pose, -) -from rcs.camera.hw import ( - CalibrationStrategy, - DummyCalibrationStrategy, - HardwareCamera, - HardwareCameraSet, -) +from rcs._core.common import Gripper, GripperConfig, HandConfig, Kinematics, Pose +from rcs.camera.hw import HardwareCameraCreatorConfig, create_hardware_camera_set from rcs.envs.base import ( CameraSetWrapper, ControlMode, @@ -35,7 +22,6 @@ from rcs.envs.scenes import RCSEnvCreator, WrapperConfig from rcs_fr3._core import hw from rcs_fr3.envs import FR3HW -from rcs_tilburg_hand.hand import THConfig, TilburgHand import rcs from frankik import FrankaKinematics @@ -65,115 +51,13 @@ def inverse( # type: ignore FastIK = FrankIK() -@dataclass(kw_only=True) -class HardwareCameraCreatorConfig: - camera_type_id: str - camera_cfgs: dict[str, BaseCameraConfig] - kwargs: dict[str, typing.Any] = field(default_factory=dict) - - -def _create_realsense_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: - try: - # from rcs_realsense.calibration import FR3BaseArucoCalibration - from rcs_realsense.camera import RealSenseCameraSet - except ImportError as e: - msg = "RealSense camera support requires the `rcs_realsense` extension to be installed." - raise ImportError(msg) from e - - calibration_strategy = { - name: typing.cast(CalibrationStrategy, DummyCalibrationStrategy()) for name in cfg.camera_cfgs - } - return typing.cast( - HardwareCamera, - RealSenseCameraSet(cameras=cfg.camera_cfgs, calibration_strategy=calibration_strategy, **cfg.kwargs), - ) - - -def _create_zed_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: - try: - from rcs_zed.camera import ZEDCameraSet - except ImportError as e: - msg = "ZED camera support requires the `rcs_zed` extension to be installed." - raise ImportError(msg) from e - - calibration_strategy = { - name: typing.cast(CalibrationStrategy, DummyCalibrationStrategy()) for name in cfg.camera_cfgs - } - return typing.cast( - HardwareCamera, - ZEDCameraSet(cameras=cfg.camera_cfgs, calibration_strategy=calibration_strategy, **cfg.kwargs), - ) - - -def _create_digit_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: - try: - from rcs_digit.camera import DigitCam - except ImportError as e: - msg = "DIGIT camera support requires the `rcs_digit` extension to be installed." - raise ImportError(msg) from e - - return typing.cast(HardwareCamera, DigitCam(cameras=cfg.camera_cfgs)) - - -HARDWARE_CAMERA_CREATORS: dict[str, typing.Callable[[HardwareCameraCreatorConfig], HardwareCamera]] = { - "realsense": _create_realsense_camera, - "zed": _create_zed_camera, - "digit": _create_digit_camera, -} - - -def _create_hardware_camera_set( - camera_cfgs: dict[str, HardwareCameraCreatorConfig] | None, -) -> HardwareCameraSet | None: - if camera_cfgs is None: - return None - cameras: list[HardwareCamera] = [] - for cfg in camera_cfgs.values(): - if cfg.camera_type_id not in HARDWARE_CAMERA_CREATORS: - msg = f"Unknown hardware camera type id: {cfg.camera_type_id}" - raise ValueError(msg) - cameras.append(HARDWARE_CAMERA_CREATORS[cfg.camera_type_id](cfg)) - return HardwareCameraSet(cameras) if cameras else None - - -def _create_franka_gripper(cfg: GripperConfig) -> Gripper: +def create_franka_gripper(cfg: GripperConfig) -> Gripper: if not isinstance(cfg, hw.FHConfig): - msg = f"Expected FHConfig for franka gripper, got {type(cfg).__name__}" + msg = f"Expected rcs_fr3 FHConfig for the franka hand, got {type(cfg).__module__}.{type(cfg).__qualname__}" raise TypeError(msg) return hw.FrankaHand(cfg) -def _create_robotiq_gripper(cfg: GripperConfig) -> Gripper: - try: - from rcs_robotiq2f85.hw import RobotiQ2F85Gripper, RobotiQ2F85GripperConfig - except ImportError as e: - msg = "Robotiq gripper support requires the `rcs_robotiq2f85` extension to be installed." - raise ImportError(msg) from e - - if not isinstance(cfg, RobotiQ2F85GripperConfig): - msg = f"Expected RobotiQ2F85GripperConfig for robotiq gripper, got {type(cfg).__name__}" - raise TypeError(msg) - return RobotiQ2F85Gripper(cfg) - - -HARDWARE_GRIPPER_CREATORS: dict[str, typing.Callable[[GripperConfig], Gripper]] = { - rcs.common.GripperType.FrankaHand.id: _create_franka_gripper, - rcs.common.GripperType.Robotiq2F85.id: _create_robotiq_gripper, -} - - -def _create_tilburg_hand(cfg: HandConfig) -> Hand: - if not isinstance(cfg, THConfig): - msg = f"Expected THConfig for tilburg hand, got {type(cfg).__name__}" - raise TypeError(msg) - return TilburgHand(cfg) - - -HARDWARE_HAND_CREATORS: dict[str, typing.Callable[[HandConfig], Hand]] = { - rcs.common.HandType.TilburgHand.id: _create_tilburg_hand, -} - - @dataclass(kw_only=True) class FR3HardwareEnvCreatorConfig: robot_cfg: hw.FR3Config @@ -217,21 +101,13 @@ def create_env(self, cfg: FR3HardwareEnvCreatorConfig) -> gym.Env: env = RobotWrapper(env, robot, cfg.control_mode, home_on_reset=cfg.wrapper_cfg.home_on_reset) env = FR3HW(env) if cfg.hand_cfg is not None: - hand_type_id = cfg.hand_cfg.hand_type.id - if hand_type_id not in HARDWARE_HAND_CREATORS: - msg = f"Unknown hardware hand type id: {hand_type_id}" - raise ValueError(msg) - hand = HARDWARE_HAND_CREATORS[hand_type_id](cfg.hand_cfg) + hand = rcs.registry.HANDS.get(cfg.hand_cfg.hand_type.id)(cfg.hand_cfg) env = HandWrapper(env, hand, binary=cfg.wrapper_cfg.binary_gripper) elif cfg.gripper_cfg is not None: - gripper_type_id = cfg.gripper_cfg.gripper_type.id - if gripper_type_id not in HARDWARE_GRIPPER_CREATORS: - msg = f"Unknown hardware gripper type id: {gripper_type_id}" - raise ValueError(msg) - gripper = HARDWARE_GRIPPER_CREATORS[gripper_type_id](cfg.gripper_cfg) + gripper = rcs.registry.GRIPPERS.get(cfg.gripper_cfg.gripper_type.id)(cfg.gripper_cfg) env = GripperWrapper(env, gripper, binary=cfg.wrapper_cfg.binary_gripper) - camera_set = _create_hardware_camera_set(cfg.camera_cfgs) + camera_set = create_hardware_camera_set(cfg.camera_cfgs) if camera_set is not None: camera_set.start() camera_set.wait_for_frames() @@ -268,7 +144,7 @@ def create_env(self, cfg: FR3MultiHardwareEnvCreatorConfig) -> gym.Env: ) env: gym.Env = MultiRobotWrapper(envs, cfg.robot_to_shared_base_frame) - camera_set = _create_hardware_camera_set(cfg.camera_cfgs) + camera_set = create_hardware_camera_set(cfg.camera_cfgs) if camera_set is not None: camera_set.start() camera_set.wait_for_frames() diff --git a/extensions/rcs_panda/pyproject.toml b/extensions/rcs_panda/pyproject.toml index f176e8d56..cc96cc4ec 100644 --- a/extensions/rcs_panda/pyproject.toml +++ b/extensions/rcs_panda/pyproject.toml @@ -15,7 +15,7 @@ build-backend = "scikit_build_core.build" name = "rcs_panda" version = "0.7.4" description = "RCS libfranka integration" -dependencies = ["rcs-core>=0.7.4", "rcs-tilburg-hand>=0.7.2"] +dependencies = ["rcs-core>=0.7.4"] readme = "README.md" license = "AGPL-3.0-or-later" maintainers = [{ name = "Tobias Juelg", email = "tobias.juelg@utn.de" }] @@ -23,6 +23,9 @@ authors = [{ name = "Tobias Juelg", email = "tobias.juelg@utn.de" }] requires-python = ">=3.11" +[project.entry-points."rcs.grippers"] +PandaHand = "rcs_panda.creators:create_panda_gripper" + [dependency-groups] build_deps = [ "pin==3.7.0", diff --git a/extensions/rcs_panda/src/rcs_panda/configs.py b/extensions/rcs_panda/src/rcs_panda/configs.py index a21f42f95..ba93631ef 100644 --- a/extensions/rcs_panda/src/rcs_panda/configs.py +++ b/extensions/rcs_panda/src/rcs_panda/configs.py @@ -30,6 +30,7 @@ def config(self) -> PandaHardwareEnvCreatorConfig: robot_cfg.async_control = False gripper_cfg = hw.FHConfig(ip=self.ip) + gripper_cfg.gripper_type = common.GripperType.PandaHand gripper_cfg.epsilon_inner = gripper_cfg.epsilon_outer = 0.1 gripper_cfg.speed = 0.1 gripper_cfg.force = 30 diff --git a/extensions/rcs_panda/src/rcs_panda/creators.py b/extensions/rcs_panda/src/rcs_panda/creators.py index 19eccaa03..f13ac8466 100644 --- a/extensions/rcs_panda/src/rcs_panda/creators.py +++ b/extensions/rcs_panda/src/rcs_panda/creators.py @@ -1,22 +1,9 @@ import logging -import typing from dataclasses import dataclass, field import gymnasium as gym -from rcs._core.common import ( - BaseCameraConfig, - Gripper, - GripperConfig, - GripperType, - Hand, - HandConfig, -) -from rcs.camera.hw import ( - CalibrationStrategy, - DummyCalibrationStrategy, - HardwareCamera, - HardwareCameraSet, -) +from rcs._core.common import Gripper, GripperConfig, HandConfig +from rcs.camera.hw import HardwareCameraCreatorConfig, create_hardware_camera_set from rcs.envs.base import ( CameraSetWrapper, ControlMode, @@ -32,7 +19,6 @@ from rcs.envs.scenes import RCSEnvCreator, WrapperConfig from rcs_panda._core import hw from rcs_panda.envs import PandaHW -from rcs_tilburg_hand.hand import THConfig, TilburgHand import rcs @@ -40,99 +26,15 @@ logger.setLevel(logging.INFO) -@dataclass(kw_only=True) -class HardwareCameraCreatorConfig: - camera_type_id: str - camera_cfgs: dict[str, BaseCameraConfig] - kwargs: dict[str, typing.Any] = field(default_factory=dict) - - -def _create_realsense_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: - try: - - # from rcs_realsense.calibration import FR3BaseArucoCalibration - from rcs_realsense.camera import RealSenseCameraSet - except ImportError as e: - msg = "RealSense camera support requires the `rcs_realsense` extension to be installed." - raise ImportError(msg) from e - - calibration_strategy = { - name: typing.cast(CalibrationStrategy, DummyCalibrationStrategy()) for name in cfg.camera_cfgs - } - return typing.cast( - HardwareCamera, - RealSenseCameraSet(cameras=cfg.camera_cfgs, calibration_strategy=calibration_strategy, **cfg.kwargs), - ) - - -def _create_digit_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: - try: - from rcs_digit.camera import DigitCam - except ImportError as e: - msg = "DIGIT camera support requires the `rcs_digit` extension to be installed." - raise ImportError(msg) from e - - return typing.cast(HardwareCamera, DigitCam(cameras=cfg.camera_cfgs)) - - -HARDWARE_CAMERA_CREATORS: dict[str, typing.Callable[[HardwareCameraCreatorConfig], HardwareCamera]] = { - "realsense": _create_realsense_camera, - "digit": _create_digit_camera, -} - - -def _create_hardware_camera_set( - camera_cfgs: dict[str, HardwareCameraCreatorConfig] | None, -) -> HardwareCameraSet | None: - if camera_cfgs is None: - return None - cameras: list[HardwareCamera] = [] - for cfg in camera_cfgs.values(): - if cfg.camera_type_id not in HARDWARE_CAMERA_CREATORS: - msg = f"Unknown hardware camera type id: {cfg.camera_type_id}" - raise ValueError(msg) - cameras.append(HARDWARE_CAMERA_CREATORS[cfg.camera_type_id](cfg)) - return HardwareCameraSet(cameras) if cameras else None - - -def _create_franka_gripper(cfg: GripperConfig) -> Gripper: +def create_panda_gripper(cfg: GripperConfig) -> Gripper: + # The Panda hand is the Franka hand driven by this extension's libfranka build, so it has its + # own type id to keep it apart from `rcs_fr3`'s `FrankaHand` when both are installed. if not isinstance(cfg, hw.FHConfig): - msg = f"Expected FHConfig for franka gripper, got {type(cfg).__name__}" + msg = f"Expected rcs_panda FHConfig for the panda hand, got {type(cfg).__module__}.{type(cfg).__qualname__}" raise TypeError(msg) return hw.FrankaHand(cfg) -def _create_robotiq_gripper(cfg: GripperConfig) -> Gripper: - try: - from rcs_robotiq2f85.hw import RobotiQ2F85Gripper, RobotiQ2F85GripperConfig - except ImportError as e: - msg = "Robotiq gripper support requires the `rcs_robotiq2f85` extension to be installed." - raise ImportError(msg) from e - - if not isinstance(cfg, RobotiQ2F85GripperConfig): - msg = f"Expected RobotiQ2F85GripperConfig, got {type(cfg).__name__}" - raise TypeError(msg) - return typing.cast(Gripper, RobotiQ2F85Gripper(cfg)) - - -HARDWARE_GRIPPER_CREATORS: dict[str, typing.Callable[[GripperConfig], Gripper]] = { - GripperType.FrankaHand.id: _create_franka_gripper, - "robotiq2f85": _create_robotiq_gripper, -} - - -def _create_tilburg_hand(cfg: HandConfig) -> Hand: - if not isinstance(cfg, THConfig): - msg = f"Expected THConfig for tilburg hand, got {type(cfg).__name__}" - raise TypeError(msg) - return TilburgHand(cfg) - - -HARDWARE_HAND_CREATORS: dict[str, typing.Callable[[HandConfig], Hand]] = { - rcs.common.HandType.TilburgHand.id: _create_tilburg_hand, -} - - @dataclass(kw_only=True) class PandaHardwareEnvCreatorConfig: robot_cfg: hw.PandaConfig @@ -176,21 +78,13 @@ def create_env(self, cfg: PandaHardwareEnvCreatorConfig) -> gym.Env: env = RobotWrapper(env, robot, cfg.control_mode, home_on_reset=cfg.wrapper_cfg.home_on_reset) env = PandaHW(env) if cfg.hand_cfg is not None: - hand_type_id = cfg.hand_cfg.hand_type.id - if hand_type_id not in HARDWARE_HAND_CREATORS: - msg = f"Unknown hardware hand type id: {hand_type_id}" - raise ValueError(msg) - hand = HARDWARE_HAND_CREATORS[hand_type_id](cfg.hand_cfg) + hand = rcs.registry.HANDS.get(cfg.hand_cfg.hand_type.id)(cfg.hand_cfg) env = HandWrapper(env, hand, binary=cfg.wrapper_cfg.binary_gripper) elif cfg.gripper_cfg is not None: - gripper_type_id = cfg.gripper_cfg.gripper_type.id - if gripper_type_id not in HARDWARE_GRIPPER_CREATORS: - msg = f"Unknown hardware gripper type id: {gripper_type_id}" - raise ValueError(msg) - gripper = HARDWARE_GRIPPER_CREATORS[gripper_type_id](cfg.gripper_cfg) + gripper = rcs.registry.GRIPPERS.get(cfg.gripper_cfg.gripper_type.id)(cfg.gripper_cfg) env = GripperWrapper(env, gripper, binary=cfg.wrapper_cfg.binary_gripper) - camera_set = _create_hardware_camera_set(cfg.camera_cfgs) + camera_set = create_hardware_camera_set(cfg.camera_cfgs) if camera_set is not None: camera_set.start() camera_set.wait_for_frames() @@ -225,7 +119,7 @@ def create_env(self, cfg: PandaMultiHardwareEnvCreatorConfig) -> gym.Env: ) env: gym.Env = MultiRobotWrapper(envs, cfg.robot_to_shared_base_frame) - camera_set = _create_hardware_camera_set(cfg.camera_cfgs) + camera_set = create_hardware_camera_set(cfg.camera_cfgs) if camera_set is not None: camera_set.start() camera_set.wait_for_frames() diff --git a/extensions/rcs_realsense/pyproject.toml b/extensions/rcs_realsense/pyproject.toml index edbabacf5..998517fb2 100644 --- a/extensions/rcs_realsense/pyproject.toml +++ b/extensions/rcs_realsense/pyproject.toml @@ -18,6 +18,9 @@ maintainers = [{ name = "Tobias Juelg", email = "tobias.juelg@utn.de" }] authors = [{ name = "Tobias Juelg", email = "tobias.juelg@utn.de" }] requires-python = ">=3.11" +[project.entry-points."rcs.cameras"] +realsense = "rcs_realsense.creators:create_camera_set" + [tool.black] line-length = 120 target-version = ["py310"] diff --git a/extensions/rcs_realsense/src/rcs_realsense/creators.py b/extensions/rcs_realsense/src/rcs_realsense/creators.py new file mode 100644 index 000000000..38c6ce59d --- /dev/null +++ b/extensions/rcs_realsense/src/rcs_realsense/creators.py @@ -0,0 +1,31 @@ +"""Factory for the `realsense` camera backend, registered as an `rcs.cameras` entry point.""" + +import typing +from collections.abc import Callable + +from rcs.camera.hw import ( + CalibrationStrategy, + DummyCalibrationStrategy, + HardwareCamera, + HardwareCameraCreatorConfig, +) +from rcs_realsense.calibration import FR3BaseArucoCalibration +from rcs_realsense.camera import RealSenseCameraSet + +# Calibration ids a config may ask for, each a factory from camera name to strategy. +CALIBRATION_STRATEGIES: dict[str, Callable[[str], CalibrationStrategy]] = { + "dummy": lambda _name: DummyCalibrationStrategy(), + "fr3_base_aruco": FR3BaseArucoCalibration, +} + + +def create_camera_set(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: + if cfg.calibration not in CALIBRATION_STRATEGIES: + msg = f"Unknown realsense calibration {cfg.calibration!r}, available: {sorted(CALIBRATION_STRATEGIES)}" + raise ValueError(msg) + make_strategy = CALIBRATION_STRATEGIES[cfg.calibration] + calibration_strategy = {name: make_strategy(name) for name in cfg.camera_cfgs} + return typing.cast( + HardwareCamera, + RealSenseCameraSet(cameras=cfg.camera_cfgs, calibration_strategy=calibration_strategy, **cfg.kwargs), + ) diff --git a/extensions/rcs_robotiq2f85/pyproject.toml b/extensions/rcs_robotiq2f85/pyproject.toml index fdefe0fa9..1bb4cde41 100644 --- a/extensions/rcs_robotiq2f85/pyproject.toml +++ b/extensions/rcs_robotiq2f85/pyproject.toml @@ -20,3 +20,6 @@ authors = [ ] requires-python = ">=3.11" license = "AGPL-3.0-or-later" + +[project.entry-points."rcs.grippers"] +Robotiq2F85 = "rcs_robotiq2f85.creators:create_gripper" diff --git a/extensions/rcs_robotiq2f85/src/rcs_robotiq2f85/creators.py b/extensions/rcs_robotiq2f85/src/rcs_robotiq2f85/creators.py new file mode 100644 index 000000000..95490e123 --- /dev/null +++ b/extensions/rcs_robotiq2f85/src/rcs_robotiq2f85/creators.py @@ -0,0 +1,11 @@ +"""Factory for the Robotiq 2F-85 gripper, registered as an `rcs.grippers` entry point.""" + +from rcs._core.common import Gripper, GripperConfig +from rcs_robotiq2f85.hw import RobotiQ2F85Gripper, RobotiQ2F85GripperConfig + + +def create_gripper(cfg: GripperConfig) -> Gripper: + if not isinstance(cfg, RobotiQ2F85GripperConfig): + msg = f"Expected RobotiQ2F85GripperConfig for robotiq gripper, got {type(cfg).__name__}" + raise TypeError(msg) + return RobotiQ2F85Gripper(cfg) diff --git a/extensions/rcs_so101/src/rcs_so101/creators.py b/extensions/rcs_so101/src/rcs_so101/creators.py index 1b04d4e2d..21d13f9a9 100644 --- a/extensions/rcs_so101/src/rcs_so101/creators.py +++ b/extensions/rcs_so101/src/rcs_so101/creators.py @@ -1,10 +1,8 @@ import logging -import typing from dataclasses import dataclass, field import gymnasium as gym -from rcs._core.common import BaseCameraConfig -from rcs.camera.hw import CalibrationStrategy, HardwareCamera, HardwareCameraSet +from rcs.camera.hw import HardwareCameraCreatorConfig, create_hardware_camera_set from rcs.envs.base import ( CameraSetWrapper, ControlMode, @@ -23,60 +21,6 @@ logger.setLevel(logging.INFO) -@dataclass(kw_only=True) -class HardwareCameraCreatorConfig: - camera_type_id: str - camera_cfgs: dict[str, BaseCameraConfig] - kwargs: dict[str, typing.Any] = field(default_factory=dict) - - -def _create_realsense_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: - try: - from rcs_realsense.calibration import FR3BaseArucoCalibration - from rcs_realsense.camera import RealSenseCameraSet - except ImportError as e: - msg = "RealSense camera support requires the `rcs_realsense` extension to be installed." - raise ImportError(msg) from e - - calibration_strategy = { - name: typing.cast(CalibrationStrategy, FR3BaseArucoCalibration(name)) for name in cfg.camera_cfgs - } - return typing.cast( - HardwareCamera, - RealSenseCameraSet(cameras=cfg.camera_cfgs, calibration_strategy=calibration_strategy, **cfg.kwargs), - ) - - -def _create_digit_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: - try: - from rcs_digit.camera import DigitCam - except ImportError as e: - msg = "DIGIT camera support requires the `rcs_digit` extension to be installed." - raise ImportError(msg) from e - - return typing.cast(HardwareCamera, DigitCam(cameras=cfg.camera_cfgs)) - - -HARDWARE_CAMERA_CREATORS: dict[str, typing.Callable[[HardwareCameraCreatorConfig], HardwareCamera]] = { - "realsense": _create_realsense_camera, - "digit": _create_digit_camera, -} - - -def _create_hardware_camera_set( - camera_cfgs: dict[str, HardwareCameraCreatorConfig] | None, -) -> HardwareCameraSet | None: - if camera_cfgs is None: - return None - cameras: list[HardwareCamera] = [] - for cfg in camera_cfgs.values(): - if cfg.camera_type_id not in HARDWARE_CAMERA_CREATORS: - msg = f"Unknown hardware camera type id: {cfg.camera_type_id}" - raise ValueError(msg) - cameras.append(HARDWARE_CAMERA_CREATORS[cfg.camera_type_id](cfg)) - return HardwareCameraSet(cameras) if cameras else None - - @dataclass(kw_only=True) class SO101HardwareEnvCreatorConfig: robot_cfg: SO101Config @@ -103,7 +47,7 @@ def create_env(self, cfg: SO101HardwareEnvCreatorConfig) -> gym.Env: gripper = SO101Gripper(robot._hf_robot, robot) env = GripperWrapper(env, gripper, binary=cfg.wrapper_cfg.binary_gripper) - camera_set = _create_hardware_camera_set(cfg.camera_cfgs) + camera_set = create_hardware_camera_set(cfg.camera_cfgs) if camera_set is not None: camera_set.start() camera_set.wait_for_frames() diff --git a/extensions/rcs_tilburg_hand/pyproject.toml b/extensions/rcs_tilburg_hand/pyproject.toml index d31df0618..235607827 100644 --- a/extensions/rcs_tilburg_hand/pyproject.toml +++ b/extensions/rcs_tilburg_hand/pyproject.toml @@ -15,6 +15,9 @@ maintainers = [ authors = [{ name = "Tobias Juelg", email = "tobias.juelg@utn.de" }] requires-python = ">=3.11" +[project.entry-points."rcs.hands"] +TilburgHand = "rcs_tilburg_hand.creators:create_hand" + [tool.black] line-length = 120 target-version = ["py310"] diff --git a/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/creators.py b/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/creators.py new file mode 100644 index 000000000..6c16739ac --- /dev/null +++ b/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/creators.py @@ -0,0 +1,11 @@ +"""Factory for the Tilburg Hand, registered as an `rcs.hands` entry point.""" + +from rcs._core.common import Hand, HandConfig +from rcs_tilburg_hand.hand import THConfig, TilburgHand + + +def create_hand(cfg: HandConfig) -> Hand: + if not isinstance(cfg, THConfig): + msg = f"Expected THConfig for tilburg hand, got {type(cfg).__name__}" + raise TypeError(msg) + return TilburgHand(cfg, verbose=cfg.verbose) diff --git a/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/hand.py b/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/hand.py index 3a297b5e3..7f72672d0 100644 --- a/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/hand.py +++ b/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/hand.py @@ -24,6 +24,7 @@ def __init__( control_unit: Unit = Unit.NORMALIZED, hand_orientation: str = "right", grasp_type: common.GraspType = common.GraspType.POWER_GRASP, + verbose: bool = False, ) -> None: super().__init__(hand_type=common.HandType.TilburgHand) self.calibration_file = calibration_file @@ -31,6 +32,7 @@ def __init__( self.control_unit = control_unit self.hand_orientation = hand_orientation self.grasp_type = grasp_type + self.verbose = verbose class TilburgHandState(common.HandState): diff --git a/extensions/rcs_ur5e/src/rcs_ur5e/creators.py b/extensions/rcs_ur5e/src/rcs_ur5e/creators.py index 2c8627bb8..ab502d5ca 100644 --- a/extensions/rcs_ur5e/src/rcs_ur5e/creators.py +++ b/extensions/rcs_ur5e/src/rcs_ur5e/creators.py @@ -1,10 +1,9 @@ import logging -import typing from dataclasses import dataclass, field import gymnasium as gym -from rcs._core.common import BaseCameraConfig, Gripper, GripperConfig -from rcs.camera.hw import CalibrationStrategy, HardwareCamera, HardwareCameraSet +from rcs._core.common import GripperConfig +from rcs.camera.hw import HardwareCameraCreatorConfig, create_hardware_camera_set from rcs.envs.base import ( CameraSetWrapper, ControlMode, @@ -16,7 +15,7 @@ RobotWrapper, ) from rcs.envs.scenes import RCSEnvCreator, WrapperConfig -from rcs_ur5e.hw import RobotiQGripper, RobotiQGripperConfig, UR5e, UR5eConfig +from rcs_ur5e.hw import UR5e, UR5eConfig import rcs @@ -24,72 +23,6 @@ logger.setLevel(logging.INFO) -@dataclass(kw_only=True) -class HardwareCameraCreatorConfig: - camera_type_id: str - camera_cfgs: dict[str, BaseCameraConfig] - kwargs: dict[str, typing.Any] = field(default_factory=dict) - - -def _create_realsense_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: - try: - from rcs_realsense.calibration import FR3BaseArucoCalibration - from rcs_realsense.camera import RealSenseCameraSet - except ImportError as e: - msg = "RealSense camera support requires the `rcs_realsense` extension to be installed." - raise ImportError(msg) from e - - calibration_strategy = { - name: typing.cast(CalibrationStrategy, FR3BaseArucoCalibration(name)) for name in cfg.camera_cfgs - } - return typing.cast( - HardwareCamera, - RealSenseCameraSet(cameras=cfg.camera_cfgs, calibration_strategy=calibration_strategy, **cfg.kwargs), - ) - - -def _create_digit_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: - try: - from rcs_digit.camera import DigitCam - except ImportError as e: - msg = "DIGIT camera support requires the `rcs_digit` extension to be installed." - raise ImportError(msg) from e - - return typing.cast(HardwareCamera, DigitCam(cameras=cfg.camera_cfgs)) - - -HARDWARE_CAMERA_CREATORS: dict[str, typing.Callable[[HardwareCameraCreatorConfig], HardwareCamera]] = { - "realsense": _create_realsense_camera, - "digit": _create_digit_camera, -} - - -def _create_hardware_camera_set( - camera_cfgs: dict[str, HardwareCameraCreatorConfig] | None, -) -> HardwareCameraSet | None: - if camera_cfgs is None: - return None - cameras: list[HardwareCamera] = [] - for cfg in camera_cfgs.values(): - if cfg.camera_type_id not in HARDWARE_CAMERA_CREATORS: - msg = f"Unknown hardware camera type id: {cfg.camera_type_id}" - raise ValueError(msg) - cameras.append(HARDWARE_CAMERA_CREATORS[cfg.camera_type_id](cfg)) - return HardwareCameraSet(cameras) if cameras else None - - -def _create_robotiq_gripper(cfg: GripperConfig) -> Gripper: - if not isinstance(cfg, RobotiQGripperConfig): - msg = f"Expected RobotiQGripperConfig, got {type(cfg).__name__}" - raise TypeError(msg) - return RobotiQGripper(cfg=cfg) - - -HARDWARE_GRIPPER_CREATORS: dict[str, typing.Callable[[GripperConfig], Gripper]] = { - "Robotiq2F85siemens": _create_robotiq_gripper, -} - - @dataclass(kw_only=True) class UR5eHardwareEnvCreatorConfig: robot_cfg: UR5eConfig @@ -116,14 +49,10 @@ def create_env(self, cfg: UR5eHardwareEnvCreatorConfig) -> gym.Env: env = RobotWrapper(env, robot, cfg.control_mode, home_on_reset=cfg.wrapper_cfg.home_on_reset) if cfg.gripper_cfg is not None: - gripper_type_id = cfg.gripper_cfg.gripper_type.id - if gripper_type_id not in HARDWARE_GRIPPER_CREATORS: - msg = f"Unknown hardware gripper type id: {gripper_type_id}" - raise ValueError(msg) - gripper = HARDWARE_GRIPPER_CREATORS[gripper_type_id](cfg.gripper_cfg) + gripper = rcs.registry.GRIPPERS.get(cfg.gripper_cfg.gripper_type.id)(cfg.gripper_cfg) env = GripperWrapper(env, gripper, binary=cfg.wrapper_cfg.binary_gripper) - camera_set = _create_hardware_camera_set(cfg.camera_cfgs) + camera_set = create_hardware_camera_set(cfg.camera_cfgs) if camera_set is not None: camera_set.start() camera_set.wait_for_frames() diff --git a/extensions/rcs_usb_cam/pyproject.toml b/extensions/rcs_usb_cam/pyproject.toml index a0933dc1c..34b58a6eb 100644 --- a/extensions/rcs_usb_cam/pyproject.toml +++ b/extensions/rcs_usb_cam/pyproject.toml @@ -16,6 +16,9 @@ maintainers = [ authors = [{ name = "Seongjin Bien", email = "seongjin.bien@utn.de" }] requires-python = ">=3.11" +[project.entry-points."rcs.cameras"] +usb = "rcs_usb_cam.creators:create_camera_set" + [tool.black] line-length = 120 target-version = ["py310"] diff --git a/extensions/rcs_usb_cam/src/rcs_usb_cam/creators.py b/extensions/rcs_usb_cam/src/rcs_usb_cam/creators.py new file mode 100644 index 000000000..03f4b5e69 --- /dev/null +++ b/extensions/rcs_usb_cam/src/rcs_usb_cam/creators.py @@ -0,0 +1,20 @@ +"""Factory for the `usb` camera backend, registered as an `rcs.cameras` entry point.""" + +import typing + +from rcs.camera.hw import HardwareCamera, HardwareCameraCreatorConfig +from rcs_usb_cam.camera import USBCameraConfig, USBCameraSet + + +def create_camera_set(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: + if cfg.calibration != "dummy": + msg = f"The usb backend supports only the 'dummy' calibration, got {cfg.calibration!r}" + raise ValueError(msg) + # The set reads USB specific fields (intrinsics, distortion) off every camera config. + for name, camera_cfg in cfg.camera_cfgs.items(): + if not isinstance(camera_cfg, USBCameraConfig): + msg = f"Expected USBCameraConfig for usb camera {name!r}, got {type(camera_cfg).__name__}" + raise TypeError(msg) + cameras = typing.cast(dict[str, USBCameraConfig], cfg.camera_cfgs) + # calibration_strategy=None makes the set build dummy strategies itself. + return typing.cast(HardwareCamera, USBCameraSet(cameras=cameras, calibration_strategy=None, **cfg.kwargs)) diff --git a/extensions/rcs_xarm7/pyproject.toml b/extensions/rcs_xarm7/pyproject.toml index 057745b8d..70ffe2fc9 100644 --- a/extensions/rcs_xarm7/pyproject.toml +++ b/extensions/rcs_xarm7/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" name = "rcs_xarm7" version = "0.7.4" description = "RCS xArm7 module" -dependencies = ["rcs-core>=0.7.4", "rcs-tilburg-hand>=0.7.2", "xarm-python-sdk==1.17.0"] +dependencies = ["rcs-core>=0.7.4", "xarm-python-sdk==1.17.0"] readme = "README.md" license = "AGPL-3.0-or-later" maintainers = [ diff --git a/extensions/rcs_xarm7/src/rcs_xarm7/creators.py b/extensions/rcs_xarm7/src/rcs_xarm7/creators.py index 8eded4f47..35fb231a3 100644 --- a/extensions/rcs_xarm7/src/rcs_xarm7/creators.py +++ b/extensions/rcs_xarm7/src/rcs_xarm7/creators.py @@ -1,12 +1,11 @@ import logging -import typing from dataclasses import dataclass, field from os import PathLike from pathlib import Path import gymnasium as gym -from rcs._core.common import BaseCameraConfig, Hand, HandConfig -from rcs.camera.hw import CalibrationStrategy, HardwareCamera, HardwareCameraSet +from rcs._core.common import HandConfig +from rcs.camera.hw import HardwareCameraCreatorConfig, create_hardware_camera_set from rcs.envs.base import ( CameraSetWrapper, ControlMode, @@ -18,7 +17,6 @@ RobotWrapper, ) from rcs.envs.scenes import RCSEnvCreator, WrapperConfig -from rcs_tilburg_hand.hand import THConfig, TilburgHand from rcs_xarm7.hw import XArm7, XArm7Config import rcs @@ -27,72 +25,6 @@ logger.setLevel(logging.INFO) -def _create_tilburg_hand(cfg: HandConfig) -> Hand: - if not isinstance(cfg, THConfig): - msg = f"Expected THConfig for tilburg hand, got {type(cfg).__name__}" - raise TypeError(msg) - return TilburgHand(cfg=cfg, verbose=True) - - -HARDWARE_HAND_CREATORS: dict[str, typing.Callable[[HandConfig], Hand]] = { - rcs.common.HandType.TilburgHand.id: _create_tilburg_hand, -} - - -@dataclass(kw_only=True) -class HardwareCameraCreatorConfig: - camera_type_id: str - camera_cfgs: dict[str, BaseCameraConfig] - kwargs: dict[str, typing.Any] = field(default_factory=dict) - - -def _create_realsense_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: - try: - from rcs_realsense.calibration import FR3BaseArucoCalibration - from rcs_realsense.camera import RealSenseCameraSet - except ImportError as e: - msg = "RealSense camera support requires the `rcs_realsense` extension to be installed." - raise ImportError(msg) from e - - calibration_strategy = { - name: typing.cast(CalibrationStrategy, FR3BaseArucoCalibration(name)) for name in cfg.camera_cfgs - } - return typing.cast( - HardwareCamera, - RealSenseCameraSet(cameras=cfg.camera_cfgs, calibration_strategy=calibration_strategy, **cfg.kwargs), - ) - - -def _create_digit_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: - try: - from rcs_digit.camera import DigitCam - except ImportError as e: - msg = "DIGIT camera support requires the `rcs_digit` extension to be installed." - raise ImportError(msg) from e - - return typing.cast(HardwareCamera, DigitCam(cameras=cfg.camera_cfgs)) - - -HARDWARE_CAMERA_CREATORS: dict[str, typing.Callable[[HardwareCameraCreatorConfig], HardwareCamera]] = { - "realsense": _create_realsense_camera, - "digit": _create_digit_camera, -} - - -def _create_hardware_camera_set( - camera_cfgs: dict[str, HardwareCameraCreatorConfig] | None, -) -> HardwareCameraSet | None: - if camera_cfgs is None: - return None - cameras: list[HardwareCamera] = [] - for cfg in camera_cfgs.values(): - if cfg.camera_type_id not in HARDWARE_CAMERA_CREATORS: - msg = f"Unknown hardware camera type id: {cfg.camera_type_id}" - raise ValueError(msg) - cameras.append(HARDWARE_CAMERA_CREATORS[cfg.camera_type_id](cfg)) - return HardwareCameraSet(cameras) if cameras else None - - @dataclass(kw_only=True) class XArm7HardwareEnvCreatorConfig: robot_cfg: XArm7Config @@ -122,18 +54,14 @@ def create_env(self, cfg: XArm7HardwareEnvCreatorConfig) -> gym.Env: env: gym.Env = HardwareEnv(frequency=cfg.frequency) env = RobotWrapper(env, robot, cfg.control_mode, home_on_reset=cfg.wrapper_cfg.home_on_reset) - camera_set = _create_hardware_camera_set(cfg.camera_cfgs) + camera_set = create_hardware_camera_set(cfg.camera_cfgs) if camera_set is not None: camera_set.start() camera_set.wait_for_frames() logger.info("CameraSet started") env = CameraSetWrapper(env, camera_set, include_depth=True) if cfg.hand_cfg is not None: - hand_type_id = cfg.hand_cfg.hand_type.id - if hand_type_id not in HARDWARE_HAND_CREATORS: - msg = f"Unknown hardware hand type id: {hand_type_id}" - raise ValueError(msg) - hand = HARDWARE_HAND_CREATORS[hand_type_id](cfg.hand_cfg) + hand = rcs.registry.HANDS.get(cfg.hand_cfg.hand_type.id)(cfg.hand_cfg) env = HandWrapper(env, hand, cfg.wrapper_cfg.binary_gripper) if cfg.relative_to != RelativeTo.NONE: diff --git a/extensions/rcs_yam/src/rcs_yam/creators.py b/extensions/rcs_yam/src/rcs_yam/creators.py index 3d90ede3b..8dcbd1cb6 100644 --- a/extensions/rcs_yam/src/rcs_yam/creators.py +++ b/extensions/rcs_yam/src/rcs_yam/creators.py @@ -1,15 +1,9 @@ import logging -import typing from dataclasses import dataclass, field import gymnasium as gym -from rcs._core.common import BaseCameraConfig, GripperConfig -from rcs.camera.hw import ( - CalibrationStrategy, - DummyCalibrationStrategy, - HardwareCamera, - HardwareCameraSet, -) +from rcs._core.common import GripperConfig +from rcs.camera.hw import HardwareCameraCreatorConfig, create_hardware_camera_set from rcs.envs.base import ( CameraSetWrapper, ControlMode, @@ -30,52 +24,10 @@ logger.setLevel(logging.INFO) -@dataclass(kw_only=True) -class HardwareCameraCreatorConfig: - camera_type_id: str - camera_cfgs: dict[str, BaseCameraConfig] - kwargs: dict[str, typing.Any] = field(default_factory=dict) - - -def _create_realsense_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: - try: - from rcs_realsense.camera import RealSenseCameraSet - except ImportError as e: - msg = "RealSense camera support requires the `rcs_realsense` extension to be installed." - raise ImportError(msg) from e - - calibration_strategy = { - name: typing.cast(CalibrationStrategy, DummyCalibrationStrategy()) for name in cfg.camera_cfgs - } - return typing.cast( - HardwareCamera, - RealSenseCameraSet(cameras=cfg.camera_cfgs, calibration_strategy=calibration_strategy, **cfg.kwargs), - ) - - -HARDWARE_CAMERA_CREATORS: dict[str, typing.Callable[[HardwareCameraCreatorConfig], HardwareCamera]] = { - "realsense": _create_realsense_camera, -} - - -def _create_hardware_camera_set( - camera_cfgs: dict[str, HardwareCameraCreatorConfig] | None, -) -> HardwareCameraSet | None: - if camera_cfgs is None: - return None - cameras: list[HardwareCamera] = [] - for cfg in camera_cfgs.values(): - if cfg.camera_type_id not in HARDWARE_CAMERA_CREATORS: - msg = f"Unknown hardware camera type id: {cfg.camera_type_id}" - raise ValueError(msg) - cameras.append(HARDWARE_CAMERA_CREATORS[cfg.camera_type_id](cfg)) - return HardwareCameraSet(cameras) if cameras else None - - def _attach_camera_set( env: gym.Env, camera_cfgs: dict[str, HardwareCameraCreatorConfig] | None, include_depth: bool ) -> gym.Env: - camera_set = _create_hardware_camera_set(camera_cfgs) + camera_set = create_hardware_camera_set(camera_cfgs) if camera_set is None: return env camera_set.start() diff --git a/extensions/rcs_zed/pyproject.toml b/extensions/rcs_zed/pyproject.toml index dab02a700..2461620f6 100644 --- a/extensions/rcs_zed/pyproject.toml +++ b/extensions/rcs_zed/pyproject.toml @@ -17,6 +17,9 @@ maintainers = [{ name = "Tobias Juelg", email = "tobias.juelg@utn.de" }] authors = [{ name = "Tobias Juelg", email = "tobias.juelg@utn.de" }] requires-python = ">=3.11" +[project.entry-points."rcs.cameras"] +zed = "rcs_zed.creators:create_camera_set" + [tool.black] line-length = 120 target-version = ["py310"] diff --git a/extensions/rcs_zed/src/rcs_zed/creators.py b/extensions/rcs_zed/src/rcs_zed/creators.py new file mode 100644 index 000000000..464ff2a4f --- /dev/null +++ b/extensions/rcs_zed/src/rcs_zed/creators.py @@ -0,0 +1,24 @@ +"""Factory for the `zed` camera backend, registered as an `rcs.cameras` entry point.""" + +import typing + +from rcs.camera.hw import ( + CalibrationStrategy, + DummyCalibrationStrategy, + HardwareCamera, + HardwareCameraCreatorConfig, +) +from rcs_zed.camera import ZEDCameraSet + + +def create_camera_set(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: + if cfg.calibration != "dummy": + msg = f"The zed backend supports only the 'dummy' calibration, got {cfg.calibration!r}" + raise ValueError(msg) + calibration_strategy = { + name: typing.cast(CalibrationStrategy, DummyCalibrationStrategy()) for name in cfg.camera_cfgs + } + return typing.cast( + HardwareCamera, + ZEDCameraSet(cameras=cfg.camera_cfgs, calibration_strategy=calibration_strategy, **cfg.kwargs), + ) diff --git a/include/rcs/Robot.h b/include/rcs/Robot.h index 9b9128c2a..94b6dea0c 100644 --- a/include/rcs/Robot.h +++ b/include/rcs/Robot.h @@ -84,12 +84,14 @@ struct GripperType : public TypeBase { using TypeBase::TypeBase; static const GripperType FrankaHand; + static const GripperType PandaHand; static const GripperType Robotiq2F85; static const GripperType Robotiq2F85Digit; static const GripperType SO101; static const GripperType Yam; }; inline const GripperType GripperType::FrankaHand{"FrankaHand"}; +inline const GripperType GripperType::PandaHand{"PandaHand"}; inline const GripperType GripperType::Robotiq2F85{"Robotiq2F85"}; inline const GripperType GripperType::Robotiq2F85Digit{"Robotiq2F85Digit"}; inline const GripperType GripperType::SO101{"SO101"}; diff --git a/pyproject.toml b/pyproject.toml index 50b4b1dce..11d9ab527 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -197,14 +197,12 @@ version_files = [ "extensions/rcs_fr3/src/rcs_fr3/_core/__init__.pyi:__version__", "extensions/rcs_fr3/pyproject.toml:version", "extensions/rcs_fr3/pyproject.toml:\"rcs-core>=(.*)\"", - "extensions/rcs_fr3/pyproject.toml:\"rcs-tilburg-hand>=(.*)\"", # --- Panda Extension --- "extensions/rcs_panda/CMakeLists.txt:VERSION", "extensions/rcs_panda/src/rcs_panda/_core/__init__.pyi:__version__", "extensions/rcs_panda/pyproject.toml:version", "extensions/rcs_panda/pyproject.toml:\"rcs-core>=(.*)\"", - "extensions/rcs_panda/pyproject.toml:\"rcs-tilburg-hand>=(.*)\"", # --- SO101 --- "extensions/rcs_so101/CMakeLists.txt:VERSION", @@ -224,7 +222,6 @@ version_files = [ "extensions/rcs_xarm7/pyproject.toml:version", "extensions/rcs_xarm7/src/rcs_xarm7/__init__.py:__version__", "extensions/rcs_xarm7/pyproject.toml:\"rcs-core>=(.*)\"", - "extensions/rcs_xarm7/pyproject.toml:\"rcs-tilburg-hand>=(.*)\"", "extensions/rcs_tilburg_hand/pyproject.toml:version", "extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/__init__.py:__version__", diff --git a/python/rcs/__init__.py b/python/rcs/__init__.py index 6f0aa62fd..3b97383b0 100644 --- a/python/rcs/__init__.py +++ b/python/rcs/__init__.py @@ -15,7 +15,7 @@ import requests from rcs._core import __version__, common -from rcs import camera, envs, sim +from rcs import camera, envs, registry, sim GITHUB_ASSET_ARCHIVE_URL = "https://github.com/RobotControlStack/robot-control-stack/archive/refs/tags/{tag}.zip" # written into the assets directory after a complete download, holds the version the assets belong to @@ -246,12 +246,14 @@ class RobotMetaConfig: GRIPPER_PATHS: dict[common.GripperType, str] = { common.GripperType.FrankaHand: "assets/grippers/franka_hand/franka_hand.xml", + common.GripperType.PandaHand: "assets/grippers/franka_hand/franka_hand.xml", common.GripperType.Robotiq2F85: "assets/grippers/robotiq_2f85/robotiq_2f85.xml", common.GripperType("FlexivGrav"): "assets/grippers/flexiv_grav/flexiv_grav.xml", } GRIPPER_TCP_OFFSETS: dict[common.GripperType, common.Pose] = { common.GripperType.FrankaHand: common.Pose(pose_matrix=common.FrankaHandTCPOffset()), + common.GripperType.PandaHand: common.Pose(pose_matrix=common.FrankaHandTCPOffset()), common.GripperType.Robotiq2F85: common.Pose(translation=np.array([0, 0.0, 0.1493])), # The yam gripper is part of the robot mjcf, hence it needs no entry in GRIPPER_PATHS # and no mount offset, only the offset from the flange to the point between the fingers. @@ -265,6 +267,9 @@ class RobotMetaConfig: common.GripperType.FrankaHand: common.Pose( rotation=common.FrankaHandTCPOffset()[:3, :3], translation=np.array([0.0, 0.0, 0.0]) ), + common.GripperType.PandaHand: common.Pose( + rotation=common.FrankaHandTCPOffset()[:3, :3], translation=np.array([0.0, 0.0, 0.0]) + ), common.GripperType.Robotiq2F85: common.Pose( translation=np.array([0.0, 0.0, 0.0]), quaternion=np.array([0.0, 0.0, 0.7071068, 0.7071068]) ), @@ -408,6 +413,7 @@ class RobotMetaConfig: "sim", "camera", "envs", + "registry", "ROBOTS", "GRIPPER_PATHS", "SCENE_PATHS", diff --git a/python/rcs/_core/common.pyi b/python/rcs/_core/common.pyi index f7e2c612f..41791467c 100644 --- a/python/rcs/_core/common.pyi +++ b/python/rcs/_core/common.pyi @@ -109,6 +109,7 @@ class GripperState: class GripperType: FrankaHand: typing.ClassVar[GripperType] # value = + PandaHand: typing.ClassVar[GripperType] # value = Robotiq2F85: typing.ClassVar[GripperType] # value = Robotiq2F85Digit: typing.ClassVar[GripperType] # value = SO101: typing.ClassVar[GripperType] # value = diff --git a/python/rcs/camera/hw.py b/python/rcs/camera/hw.py index 390e3e498..edab1419b 100644 --- a/python/rcs/camera/hw.py +++ b/python/rcs/camera/hw.py @@ -2,6 +2,7 @@ import threading import typing from collections.abc import Sequence +from dataclasses import dataclass, field from datetime import datetime from pathlib import Path from time import sleep @@ -12,6 +13,8 @@ from rcs.camera.interface import BaseCameraSet, Frame, FrameSet from rcs.utils import SimpleFrameRate +from rcs import registry + class HardwareCamera(typing.Protocol): """Implementation of a hardware camera potentially a set of cameras of the same kind.""" @@ -288,3 +291,25 @@ def __enter__(self): def __exit__(self, *args, **kwargs): self.close() + + +@dataclass(kw_only=True) +class HardwareCameraCreatorConfig: + """One camera backend and the cameras it should open, resolved through `rcs.registry.CAMERAS`.""" + + camera_type_id: str + camera_cfgs: dict[str, BaseCameraConfig] + # How each camera is calibrated, by name; "dummy" is the identity. Backends resolve the ids + # they support and reject the rest, so an unsupported choice fails at creation, not silently. + calibration: str = "dummy" + kwargs: dict[str, typing.Any] = field(default_factory=dict) + + +def create_hardware_camera_set( + camera_cfgs: dict[str, HardwareCameraCreatorConfig] | None, +) -> HardwareCameraSet | None: + """Build one `HardwareCameraSet` from per-backend configs, or None when there is nothing to open.""" + if camera_cfgs is None: + return None + cameras = [registry.CAMERAS.get(cfg.camera_type_id)(cfg) for cfg in camera_cfgs.values()] + return HardwareCameraSet(cameras) if cameras else None diff --git a/python/rcs/registry.py b/python/rcs/registry.py new file mode 100644 index 000000000..045ad8e21 --- /dev/null +++ b/python/rcs/registry.py @@ -0,0 +1,70 @@ +"""Factory registries for pluggable hardware: cameras, grippers and hands. + +An extension that provides a backend declares a factory as an entry point in its own +``pyproject.toml`` and nothing else has to know about it:: + + [project.entry-points."rcs.cameras"] + realsense = "rcs_realsense.creators:create_camera_set" + +The entry point name is the type id that configs already carry (``camera_type_id``, +``GripperType.id``, ``HandType.id``). Entry points are plain package metadata, so listing the +available backends imports nothing, and a backend is imported only when its id is requested. A +backend that is not installed is simply absent from the metadata, which is how a missing +extension surfaces: as an unknown id, with the installed ids listed next to it. + +Two installed distributions may provide the same id, for example `rcs_fr3` and `rcs_panda` both +implement `FrankaHand` against different libfranka versions. Resolving that silently would pick an +arbitrary one, so it is an error instead; `register` settles it explicitly for the process. +""" + +from collections.abc import Callable +from importlib.metadata import entry_points +from typing import TYPE_CHECKING, Generic, TypeVar + +if TYPE_CHECKING: + from rcs._core.common import Gripper, Hand + from rcs.camera.hw import HardwareCamera + +T = TypeVar("T") + + +class Registry(Generic[T]): + """Maps type ids to factories, filled from an entry point group and by `register`.""" + + def __init__(self, group: str) -> None: + self._group = group + self._factories: dict[str, Callable[..., T]] = {} + + def register(self, type_id: str, factory: Callable[..., T]) -> None: + """Add a factory at runtime, for tests and for backends not installed as a distribution.""" + self._factories[type_id] = factory + + def available(self) -> set[str]: + """Ids that can be resolved, from registered factories and installed entry points. Imports nothing.""" + return set(self._factories) | {ep.name for ep in entry_points(group=self._group)} + + def get(self, type_id: str) -> Callable[..., T]: + """Return the factory for `type_id`, importing its backend on first use.""" + if type_id not in self._factories: + matches = list(entry_points(group=self._group, name=type_id)) + if len(matches) > 1: + dists = sorted({ep.dist.name for ep in matches if ep.dist is not None}) + msg = ( + f"{self._group} type {type_id!r} is provided by more than one installed package {dists}, " + f"call `register({type_id!r}, factory)` to choose one" + ) + raise ValueError(msg) + if matches: + self._factories[type_id] = matches[0].load() + try: + return self._factories[type_id] + except KeyError: + msg = f"Unknown {self._group} type {type_id!r}, available: {sorted(self.available())}" + raise ValueError(msg) from None + + +CAMERAS: "Registry[HardwareCamera]" = Registry("rcs.cameras") +GRIPPERS: "Registry[Gripper]" = Registry("rcs.grippers") +HANDS: "Registry[Hand]" = Registry("rcs.hands") + +__all__ = ["CAMERAS", "GRIPPERS", "HANDS", "Registry"] diff --git a/src/pybind/rcs.cpp b/src/pybind/rcs.cpp index 484ed1a51..1ed913539 100644 --- a/src/pybind/rcs.cpp +++ b/src/pybind/rcs.cpp @@ -467,6 +467,7 @@ PYBIND11_MODULE(_core, m) { bind_type_class(common, "GripperType") .def_readonly_static("FrankaHand", &rcs::common::GripperType::FrankaHand) + .def_readonly_static("PandaHand", &rcs::common::GripperType::PandaHand) .def_readonly_static("Robotiq2F85", &rcs::common::GripperType::Robotiq2F85) .def_readonly_static("Robotiq2F85Digit", &rcs::common::GripperType::Robotiq2F85Digit) .def_readonly_static("SO101", &rcs::common::GripperType::SO101) From 96af77ad04fb3b88ba5840d567f1abea72f1e664 Mon Sep 17 00:00:00 2001 From: Tobias Juelg Date: Mon, 5 Oct 2026 22:42:01 -0700 Subject: [PATCH 06/16] refactor: non string type for calibration strategy, rename dummy to identity calibration strategy --- docs/extensions/rcs_zed.md | 2 +- .../rcs_digit/src/rcs_digit/creators.py | 4 ++-- .../rcs_realsense/src/rcs_realsense/camera.py | 8 +++++-- .../src/rcs_realsense/creators.py | 23 +++---------------- .../rcs_realsense/src/rcs_realsense/utils.py | 2 +- .../rcs_usb_cam/src/rcs_usb_cam/camera.py | 8 +++++-- .../rcs_usb_cam/src/rcs_usb_cam/creators.py | 9 ++++---- extensions/rcs_zed/README.md | 2 +- extensions/rcs_zed/src/rcs_zed/camera.py | 8 +++++-- extensions/rcs_zed/src/rcs_zed/creators.py | 16 +++---------- extensions/rcs_zed/src/rcs_zed/utils.py | 6 ++--- .../rcs_zed/tests/test_zed_extension.py | 14 +++++------ python/rcs/camera/hw.py | 8 +++---- 13 files changed, 47 insertions(+), 63 deletions(-) diff --git a/docs/extensions/rcs_zed.md b/docs/extensions/rcs_zed.md index 6f82cfc1a..3b9759a4f 100644 --- a/docs/extensions/rcs_zed.md +++ b/docs/extensions/rcs_zed.md @@ -22,7 +22,7 @@ pip install -ve extensions/rcs_zed ## Calibration The `default_zed(...)` helper uses the identity -`DummyCalibrationStrategy` unless a `calibration_strategy` mapping is supplied. +`IdentityCalibrationStrategy` unless a `calibration_strategy` mapping is supplied. Mapping keys must match the logical camera names, and values must implement `rcs.camera.hw.CalibrationStrategy`. Calibration is injected explicitly so the ZED extension remains independent of other hardware-camera extensions. diff --git a/extensions/rcs_digit/src/rcs_digit/creators.py b/extensions/rcs_digit/src/rcs_digit/creators.py index c7b421dba..3e47f35f0 100644 --- a/extensions/rcs_digit/src/rcs_digit/creators.py +++ b/extensions/rcs_digit/src/rcs_digit/creators.py @@ -7,7 +7,7 @@ def create_camera_set(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: - if cfg.calibration != "dummy": - msg = f"DIGIT sensors are not calibrated, got calibration {cfg.calibration!r}" + if cfg.calibration is not None: + msg = "DIGIT sensors are not calibrated, `calibration` must be None" raise ValueError(msg) return typing.cast(HardwareCamera, DigitCam(cameras=cfg.camera_cfgs)) diff --git a/extensions/rcs_realsense/src/rcs_realsense/camera.py b/extensions/rcs_realsense/src/rcs_realsense/camera.py index 5125dddbb..762d94f5c 100644 --- a/extensions/rcs_realsense/src/rcs_realsense/camera.py +++ b/extensions/rcs_realsense/src/rcs_realsense/camera.py @@ -6,7 +6,11 @@ import numpy as np import pyrealsense2 as rs -from rcs.camera.hw import CalibrationStrategy, DummyCalibrationStrategy, HardwareCamera +from rcs.camera.hw import ( + CalibrationStrategy, + HardwareCamera, + IdentityCalibrationStrategy, +) from rcs.camera.interface import BaseCameraSet, CameraFrame, DataFrame, Frame, IMUFrame from rcs import common @@ -50,7 +54,7 @@ def __init__( self.cameras = cameras self.align_depth_to_color = align_depth_to_color if calibration_strategy is None: - calibration_strategy = {camera_name: DummyCalibrationStrategy() for camera_name in cameras} + calibration_strategy = {camera_name: IdentityCalibrationStrategy() for camera_name in cameras} self.calibration_strategy = calibration_strategy self._logger = logging.getLogger(__name__) assert ( diff --git a/extensions/rcs_realsense/src/rcs_realsense/creators.py b/extensions/rcs_realsense/src/rcs_realsense/creators.py index 38c6ce59d..c1e0df19d 100644 --- a/extensions/rcs_realsense/src/rcs_realsense/creators.py +++ b/extensions/rcs_realsense/src/rcs_realsense/creators.py @@ -1,31 +1,14 @@ """Factory for the `realsense` camera backend, registered as an `rcs.cameras` entry point.""" import typing -from collections.abc import Callable -from rcs.camera.hw import ( - CalibrationStrategy, - DummyCalibrationStrategy, - HardwareCamera, - HardwareCameraCreatorConfig, -) -from rcs_realsense.calibration import FR3BaseArucoCalibration +from rcs.camera.hw import HardwareCamera, HardwareCameraCreatorConfig from rcs_realsense.camera import RealSenseCameraSet -# Calibration ids a config may ask for, each a factory from camera name to strategy. -CALIBRATION_STRATEGIES: dict[str, Callable[[str], CalibrationStrategy]] = { - "dummy": lambda _name: DummyCalibrationStrategy(), - "fr3_base_aruco": FR3BaseArucoCalibration, -} - def create_camera_set(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: - if cfg.calibration not in CALIBRATION_STRATEGIES: - msg = f"Unknown realsense calibration {cfg.calibration!r}, available: {sorted(CALIBRATION_STRATEGIES)}" - raise ValueError(msg) - make_strategy = CALIBRATION_STRATEGIES[cfg.calibration] - calibration_strategy = {name: make_strategy(name) for name in cfg.camera_cfgs} + # calibration=None leaves the set to build identity strategies for every camera. return typing.cast( HardwareCamera, - RealSenseCameraSet(cameras=cfg.camera_cfgs, calibration_strategy=calibration_strategy, **cfg.kwargs), + RealSenseCameraSet(cameras=cfg.camera_cfgs, calibration_strategy=cfg.calibration, **cfg.kwargs), ) diff --git a/extensions/rcs_realsense/src/rcs_realsense/utils.py b/extensions/rcs_realsense/src/rcs_realsense/utils.py index 2797fd29e..f537be9e6 100644 --- a/extensions/rcs_realsense/src/rcs_realsense/utils.py +++ b/extensions/rcs_realsense/src/rcs_realsense/utils.py @@ -18,7 +18,7 @@ def default_realsense(name2id: dict[str, str] | None) -> RealSenseCameraSet | No return RealSenseCameraSet(cameras=cameras, calibration_strategy=calibration_strategy) -def default_realsense_dummy_calibration(name2id: dict[str, str] | None) -> RealSenseCameraSet | None: +def default_realsense_identity_calibration(name2id: dict[str, str] | None) -> RealSenseCameraSet | None: if name2id is None: return None cameras = { diff --git a/extensions/rcs_usb_cam/src/rcs_usb_cam/camera.py b/extensions/rcs_usb_cam/src/rcs_usb_cam/camera.py index a434d01f4..18519fcf4 100644 --- a/extensions/rcs_usb_cam/src/rcs_usb_cam/camera.py +++ b/extensions/rcs_usb_cam/src/rcs_usb_cam/camera.py @@ -6,7 +6,11 @@ import cv2 import numpy as np -from rcs.camera.hw import CalibrationStrategy, DummyCalibrationStrategy, HardwareCamera +from rcs.camera.hw import ( + CalibrationStrategy, + HardwareCamera, + IdentityCalibrationStrategy, +) from rcs.camera.interface import CameraFrame, DataFrame, Frame from rcs import common @@ -33,7 +37,7 @@ def __init__( self.cameras = cameras self.CALIBRATION_FRAME_SIZE = 30 if calibration_strategy is None: - calibration_strategy = {camera_name: DummyCalibrationStrategy() for camera_name in cameras} + calibration_strategy = {camera_name: IdentityCalibrationStrategy() for camera_name in cameras} for cam in self.cameras.values(): if cam.color_intrinsics is None: cam.color_intrinsics = np.zeros((3, 4), dtype=np.float64) # type: ignore diff --git a/extensions/rcs_usb_cam/src/rcs_usb_cam/creators.py b/extensions/rcs_usb_cam/src/rcs_usb_cam/creators.py index 03f4b5e69..66b232d78 100644 --- a/extensions/rcs_usb_cam/src/rcs_usb_cam/creators.py +++ b/extensions/rcs_usb_cam/src/rcs_usb_cam/creators.py @@ -7,14 +7,13 @@ def create_camera_set(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: - if cfg.calibration != "dummy": - msg = f"The usb backend supports only the 'dummy' calibration, got {cfg.calibration!r}" - raise ValueError(msg) # The set reads USB specific fields (intrinsics, distortion) off every camera config. for name, camera_cfg in cfg.camera_cfgs.items(): if not isinstance(camera_cfg, USBCameraConfig): msg = f"Expected USBCameraConfig for usb camera {name!r}, got {type(camera_cfg).__name__}" raise TypeError(msg) cameras = typing.cast(dict[str, USBCameraConfig], cfg.camera_cfgs) - # calibration_strategy=None makes the set build dummy strategies itself. - return typing.cast(HardwareCamera, USBCameraSet(cameras=cameras, calibration_strategy=None, **cfg.kwargs)) + # calibration=None leaves the set to build identity strategies for every camera. + return typing.cast( + HardwareCamera, USBCameraSet(cameras=cameras, calibration_strategy=cfg.calibration, **cfg.kwargs) + ) diff --git a/extensions/rcs_zed/README.md b/extensions/rcs_zed/README.md index a612e8f45..aad0354fc 100644 --- a/extensions/rcs_zed/README.md +++ b/extensions/rcs_zed/README.md @@ -35,7 +35,7 @@ pip install -ve extensions/rcs_zed ## Calibration `default_zed(...)` is standalone and uses RCS's identity -`DummyCalibrationStrategy` by default. To use measured extrinsics, pass one +`IdentityCalibrationStrategy` by default. To use measured extrinsics, pass one calibration strategy per logical camera: ```python diff --git a/extensions/rcs_zed/src/rcs_zed/camera.py b/extensions/rcs_zed/src/rcs_zed/camera.py index 8e86481d7..67f81f6d6 100644 --- a/extensions/rcs_zed/src/rcs_zed/camera.py +++ b/extensions/rcs_zed/src/rcs_zed/camera.py @@ -6,7 +6,11 @@ from time import time import numpy as np -from rcs.camera.hw import CalibrationStrategy, DummyCalibrationStrategy, HardwareCamera +from rcs.camera.hw import ( + CalibrationStrategy, + HardwareCamera, + IdentityCalibrationStrategy, +) from rcs.camera.interface import BaseCameraSet, CameraFrame, DataFrame, Frame, IMUFrame from rcs import common @@ -255,7 +259,7 @@ def __init__( ) -> None: self.cameras = cameras if calibration_strategy is None: - calibration_strategy = {camera_name: DummyCalibrationStrategy() for camera_name in cameras} + calibration_strategy = {camera_name: IdentityCalibrationStrategy() for camera_name in cameras} self.calibration_strategy = calibration_strategy self.enable_depth = enable_depth self.enable_imu = enable_imu diff --git a/extensions/rcs_zed/src/rcs_zed/creators.py b/extensions/rcs_zed/src/rcs_zed/creators.py index 464ff2a4f..3586e4084 100644 --- a/extensions/rcs_zed/src/rcs_zed/creators.py +++ b/extensions/rcs_zed/src/rcs_zed/creators.py @@ -2,23 +2,13 @@ import typing -from rcs.camera.hw import ( - CalibrationStrategy, - DummyCalibrationStrategy, - HardwareCamera, - HardwareCameraCreatorConfig, -) +from rcs.camera.hw import HardwareCamera, HardwareCameraCreatorConfig from rcs_zed.camera import ZEDCameraSet def create_camera_set(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: - if cfg.calibration != "dummy": - msg = f"The zed backend supports only the 'dummy' calibration, got {cfg.calibration!r}" - raise ValueError(msg) - calibration_strategy = { - name: typing.cast(CalibrationStrategy, DummyCalibrationStrategy()) for name in cfg.camera_cfgs - } + # calibration=None leaves the set to build identity strategies for every camera. return typing.cast( HardwareCamera, - ZEDCameraSet(cameras=cfg.camera_cfgs, calibration_strategy=calibration_strategy, **cfg.kwargs), + ZEDCameraSet(cameras=cfg.camera_cfgs, calibration_strategy=cfg.calibration, **cfg.kwargs), ) diff --git a/extensions/rcs_zed/src/rcs_zed/utils.py b/extensions/rcs_zed/src/rcs_zed/utils.py index 087cc55a3..56840fad7 100644 --- a/extensions/rcs_zed/src/rcs_zed/utils.py +++ b/extensions/rcs_zed/src/rcs_zed/utils.py @@ -14,7 +14,7 @@ def default_zed( name2id: Mapping from logical camera names to ZED serial numbers. calibration_strategy: Optional calibration strategy for each logical camera. When omitted, ``ZEDCameraSet`` uses - ``DummyCalibrationStrategy``. + ``IdentityCalibrationStrategy``. """ if name2id is None: return None @@ -25,6 +25,6 @@ def default_zed( return ZEDCameraSet(cameras=cameras, calibration_strategy=calibration_strategy) -def default_zed_dummy_calibration(name2id: dict[str, str] | None) -> ZEDCameraSet | None: - """Create the default ZED camera set with dummy calibration.""" +def default_zed_identity_calibration(name2id: dict[str, str] | None) -> ZEDCameraSet | None: + """Create the default ZED camera set with identity calibration.""" return default_zed(name2id) diff --git a/extensions/rcs_zed/tests/test_zed_extension.py b/extensions/rcs_zed/tests/test_zed_extension.py index 6943cc79b..1aa442129 100644 --- a/extensions/rcs_zed/tests/test_zed_extension.py +++ b/extensions/rcs_zed/tests/test_zed_extension.py @@ -9,9 +9,9 @@ sys.path.insert(0, str(REPO_ROOT / "python")) sys.path.insert(0, str(REPO_ROOT / "extensions/rcs_zed/src")) -from rcs.camera.hw import DummyCalibrationStrategy # noqa: E402 +from rcs.camera.hw import IdentityCalibrationStrategy # noqa: E402 from rcs_zed.camera import ZEDCameraSet, ZEDDeviceInfo, ZEDFrameBundle # noqa: E402 -from rcs_zed.utils import default_zed, default_zed_dummy_calibration # noqa: E402 +from rcs_zed.utils import default_zed, default_zed_identity_calibration # noqa: E402 from rcs import common # noqa: E402 @@ -175,11 +175,11 @@ def test_zed_include_right_adds_logical_right_camera_without_double_grab(patch_z assert right_frame.camera.depth is None -def test_default_zed_uses_builtin_dummy_calibration(): +def test_default_zed_uses_builtin_identity_calibration(): camera_set = default_zed({"wrist": "123"}) assert camera_set is not None - assert isinstance(camera_set.calibration_strategy["wrist"], DummyCalibrationStrategy) + assert isinstance(camera_set.calibration_strategy["wrist"], IdentityCalibrationStrategy) def test_default_zed_accepts_explicit_calibration_strategy(): @@ -193,8 +193,8 @@ def test_default_zed_accepts_explicit_calibration_strategy(): assert camera_set.calibration_strategy == {"wrist": calibration} -def test_default_zed_dummy_calibration_remains_compatible(): - camera_set = default_zed_dummy_calibration({"wrist": "123"}) +def test_default_zed_identity_calibration_remains_compatible(): + camera_set = default_zed_identity_calibration({"wrist": "123"}) assert camera_set is not None - assert isinstance(camera_set.calibration_strategy["wrist"], DummyCalibrationStrategy) + assert isinstance(camera_set.calibration_strategy["wrist"], IdentityCalibrationStrategy) diff --git a/python/rcs/camera/hw.py b/python/rcs/camera/hw.py index edab1419b..d658810bc 100644 --- a/python/rcs/camera/hw.py +++ b/python/rcs/camera/hw.py @@ -74,7 +74,7 @@ def get_extrinsics(self) -> np.ndarray[tuple[typing.Literal[4], typing.Literal[4 """ -class DummyCalibrationStrategy(CalibrationStrategy): +class IdentityCalibrationStrategy(CalibrationStrategy): """Always returns identity extrinsics.""" def calibrate( @@ -299,9 +299,9 @@ class HardwareCameraCreatorConfig: camera_type_id: str camera_cfgs: dict[str, BaseCameraConfig] - # How each camera is calibrated, by name; "dummy" is the identity. Backends resolve the ids - # they support and reject the rest, so an unsupported choice fails at creation, not silently. - calibration: str = "dummy" + # Calibration strategy per camera name, passed to the camera set as is. None leaves every + # camera at identity extrinsics, which is what the sets default to themselves. + calibration: dict[str, CalibrationStrategy] | None = None kwargs: dict[str, typing.Any] = field(default_factory=dict) From 674fba249d754223adefc02751dee18eb365d759 Mon Sep 17 00:00:00 2001 From: Tobias Juelg Date: Tue, 6 Oct 2026 13:43:18 -0700 Subject: [PATCH 07/16] build: bump rcs versions of new prebase added extensions --- extensions/rcs_digit/pyproject.toml | 4 ++-- extensions/rcs_digit/src/rcs_digit/__init__.py | 2 +- extensions/rcs_tilburg_hand/pyproject.toml | 4 ++-- extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/__init__.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/extensions/rcs_digit/pyproject.toml b/extensions/rcs_digit/pyproject.toml index 153788644..858db4bbe 100644 --- a/extensions/rcs_digit/pyproject.toml +++ b/extensions/rcs_digit/pyproject.toml @@ -4,11 +4,11 @@ build-backend = "setuptools.build_meta" [project] name = "rcs_digit" -version = "0.7.2" +version = "0.7.3" description = "RCS DIGIT tactile sensor module" readme = "README.md" license = "AGPL-3.0-or-later" -dependencies = ["rcs-core>=0.7.2", "digit-interface"] +dependencies = ["rcs-core>=0.7.3", "digit-interface"] maintainers = [ { name = "Tobias Juelg", email = "tobias.juelg@utn.de" }, ] diff --git a/extensions/rcs_digit/src/rcs_digit/__init__.py b/extensions/rcs_digit/src/rcs_digit/__init__.py index bc8c296f6..4910b9ec3 100644 --- a/extensions/rcs_digit/src/rcs_digit/__init__.py +++ b/extensions/rcs_digit/src/rcs_digit/__init__.py @@ -1 +1 @@ -__version__ = "0.7.2" +__version__ = "0.7.3" diff --git a/extensions/rcs_tilburg_hand/pyproject.toml b/extensions/rcs_tilburg_hand/pyproject.toml index 235607827..24059aa64 100644 --- a/extensions/rcs_tilburg_hand/pyproject.toml +++ b/extensions/rcs_tilburg_hand/pyproject.toml @@ -4,11 +4,11 @@ build-backend = "setuptools.build_meta" [project] name = "rcs_tilburg_hand" -version = "0.7.2" +version = "0.7.3" description = "RCS Tilburg Hand module" readme = "README.md" license = "AGPL-3.0-or-later" -dependencies = ["rcs-core>=0.7.2", "tilburg-hand"] +dependencies = ["rcs-core>=0.7.3", "tilburg-hand"] maintainers = [ { name = "Tobias Juelg", email = "tobias.juelg@utn.de" }, ] diff --git a/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/__init__.py b/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/__init__.py index bc8c296f6..4910b9ec3 100644 --- a/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/__init__.py +++ b/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/__init__.py @@ -1 +1 @@ -__version__ = "0.7.2" +__version__ = "0.7.3" From 6b170324c8e453d7cf51477f3d181b50ea1d2e5e Mon Sep 17 00:00:00 2001 From: Tobias Juelg Date: Tue, 6 Oct 2026 14:04:44 -0700 Subject: [PATCH 08/16] style: cpp format --- src/pybind/rcs.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pybind/rcs.cpp b/src/pybind/rcs.cpp index 1ed913539..ab1ec2ea5 100644 --- a/src/pybind/rcs.cpp +++ b/src/pybind/rcs.cpp @@ -468,8 +468,10 @@ PYBIND11_MODULE(_core, m) { bind_type_class(common, "GripperType") .def_readonly_static("FrankaHand", &rcs::common::GripperType::FrankaHand) .def_readonly_static("PandaHand", &rcs::common::GripperType::PandaHand) - .def_readonly_static("Robotiq2F85", &rcs::common::GripperType::Robotiq2F85) - .def_readonly_static("Robotiq2F85Digit", &rcs::common::GripperType::Robotiq2F85Digit) + .def_readonly_static("Robotiq2F85", + &rcs::common::GripperType::Robotiq2F85) + .def_readonly_static("Robotiq2F85Digit", + &rcs::common::GripperType::Robotiq2F85Digit) .def_readonly_static("SO101", &rcs::common::GripperType::SO101) .def_readonly_static("Yam", &rcs::common::GripperType::Yam); From 99ba9f75bfe9d8b3925c0d057e48ca3d4a312034 Mon Sep 17 00:00:00 2001 From: Tobias Juelg Date: Fri, 20 Nov 2026 15:22:42 -0800 Subject: [PATCH 09/16] refactor(flexiv): create cameras through the camera registry rcs_flexiv still carried its own copy of the hardware camera creation and used DummyCalibrationStrategy, which is now IdentityCalibrationStrategy, so importing its creators failed. Cameras are now created with rcs.camera.hw.create_hardware_camera_set like in the other extensions. RealSense cameras keep identity calibration, as that is the default without an explicit calibration. --- .../rcs_flexiv/src/rcs_flexiv/creators.py | 51 ++----------------- 1 file changed, 3 insertions(+), 48 deletions(-) diff --git a/extensions/rcs_flexiv/src/rcs_flexiv/creators.py b/extensions/rcs_flexiv/src/rcs_flexiv/creators.py index ddaa86dd4..70e2d1f19 100644 --- a/extensions/rcs_flexiv/src/rcs_flexiv/creators.py +++ b/extensions/rcs_flexiv/src/rcs_flexiv/creators.py @@ -1,10 +1,8 @@ import logging -import typing from dataclasses import dataclass, field import gymnasium as gym -from rcs._core.common import BaseCameraConfig -from rcs.camera.hw import DummyCalibrationStrategy, HardwareCamera, HardwareCameraSet +from rcs.camera.hw import HardwareCameraCreatorConfig, create_hardware_camera_set from rcs.envs.base import ( CameraSetWrapper, ControlMode, @@ -25,49 +23,6 @@ logger.setLevel(logging.INFO) -@dataclass(kw_only=True) -class HardwareCameraCreatorConfig: - camera_type_id: str - camera_cfgs: dict[str, BaseCameraConfig] - kwargs: dict[str, typing.Any] = field(default_factory=dict) - - -def _create_realsense_camera(cfg: HardwareCameraCreatorConfig) -> HardwareCamera: - try: - from rcs.camera.hw import CalibrationStrategy - from rcs_realsense.camera import RealSenseCameraSet - except ImportError as e: - msg = "RealSense camera support requires the `rcs_realsense` extension to be installed." - raise ImportError(msg) from e - - calibration_strategy = { - name: typing.cast(CalibrationStrategy, DummyCalibrationStrategy()) for name in cfg.camera_cfgs - } - return typing.cast( - HardwareCamera, - RealSenseCameraSet(cameras=cfg.camera_cfgs, calibration_strategy=calibration_strategy, **cfg.kwargs), - ) - - -HARDWARE_CAMERA_CREATORS: dict[str, typing.Callable[[HardwareCameraCreatorConfig], HardwareCamera]] = { - "realsense": _create_realsense_camera, -} - - -def _create_hardware_camera_set( - camera_cfgs: dict[str, HardwareCameraCreatorConfig] | None, -) -> HardwareCameraSet | None: - if camera_cfgs is None: - return None - cameras: list[HardwareCamera] = [] - for cfg in camera_cfgs.values(): - if cfg.camera_type_id not in HARDWARE_CAMERA_CREATORS: - msg = f"Unknown hardware camera type id: {cfg.camera_type_id}" - raise ValueError(msg) - cameras.append(HARDWARE_CAMERA_CREATORS[cfg.camera_type_id](cfg)) - return HardwareCameraSet(cameras) if cameras else None - - @dataclass(kw_only=True) class FlexivHardwareEnvCreatorConfig: robot_cfg: FlexivConfig @@ -97,7 +52,7 @@ def create_env(self, cfg: FlexivHardwareEnvCreatorConfig) -> gym.Env: gripper = FlexivGripper(cfg.gripper_cfg, robot) env = GripperWrapper(env, gripper, binary=cfg.wrapper_cfg.binary_gripper) - camera_set = _create_hardware_camera_set(cfg.camera_cfgs) + camera_set = create_hardware_camera_set(cfg.camera_cfgs) if camera_set is not None: camera_set.start() camera_set.wait_for_frames() @@ -148,7 +103,7 @@ def create_env(self, cfg: FlexivMultiHardwareEnvCreatorConfig) -> gym.Env: ) env: gym.Env = MultiRobotWrapper(envs, cfg.robot_to_shared_base_frame) - camera_set = _create_hardware_camera_set(cfg.camera_cfgs) + camera_set = create_hardware_camera_set(cfg.camera_cfgs) if camera_set is not None: camera_set.start() camera_set.wait_for_frames() From c83a09777b07e9262b4346bb14ffc493419e4543 Mon Sep 17 00:00:00 2001 From: Tobias Juelg Date: Fri, 20 Nov 2026 15:43:00 -0800 Subject: [PATCH 10/16] refactor: add Rizon4S and FlexivGrav type constants The Flexiv robot and gripper types were the only built-in types without a constant in the bindings and were created from strings. They now have constants like all other types, and all callers use the constants. --- .../rcs_flexiv/src/rcs_flexiv/configs.py | 4 ++-- extensions/rcs_flexiv/src/rcs_flexiv/hw.py | 2 +- .../src/rcs_flexiv/scripts/test_robot.py | 4 ++-- extensions/rcs_yam/README.md | 2 +- include/rcs/Robot.h | 4 ++++ python/rcs/__init__.py | 8 ++++---- python/rcs/_core/common.pyi | 18 ++++++++++-------- python/rcs/envs/configs.py | 10 +++++----- python/tests/test_kinematics.py | 6 +++--- src/pybind/rcs.cpp | 6 ++++-- 10 files changed, 36 insertions(+), 28 deletions(-) diff --git a/extensions/rcs_flexiv/src/rcs_flexiv/configs.py b/extensions/rcs_flexiv/src/rcs_flexiv/configs.py index fef3d68e7..46aa98971 100644 --- a/extensions/rcs_flexiv/src/rcs_flexiv/configs.py +++ b/extensions/rcs_flexiv/src/rcs_flexiv/configs.py @@ -25,8 +25,8 @@ class DefaultRizon4SHardwareEnv(RCSFlexivConfigEnvCreator): active tool. The active tool matters for gravity compensation, so it should match the mounted gripper.""" def config(self) -> FlexivHardwareEnvCreatorConfig: - robot_type = RobotType("Rizon4S") - gripper_type = rcs.common.GripperType("FlexivGrav") + robot_type = RobotType.Rizon4S + gripper_type = rcs.common.GripperType.FlexivGrav robot_cfg = FlexivConfig( robot_sn=self.robot_sn, control_mode=FlexivControlMode.JOINT_IMPEDANCE, diff --git a/extensions/rcs_flexiv/src/rcs_flexiv/hw.py b/extensions/rcs_flexiv/src/rcs_flexiv/hw.py index 34dfb5152..a247aac31 100644 --- a/extensions/rcs_flexiv/src/rcs_flexiv/hw.py +++ b/extensions/rcs_flexiv/src/rcs_flexiv/hw.py @@ -537,7 +537,7 @@ def __init__( command_timeout: Seconds after which a synchronous command returns even if the width was not reached. """ super().__init__(**kwargs) - self.gripper_type = common.GripperType("FlexivGrav") + self.gripper_type = common.GripperType.FlexivGrav self.device_name = device_name self.async_control = async_control self.manual_init = manual_init diff --git a/extensions/rcs_flexiv/src/rcs_flexiv/scripts/test_robot.py b/extensions/rcs_flexiv/src/rcs_flexiv/scripts/test_robot.py index 0d64f38fb..91aef19f7 100644 --- a/extensions/rcs_flexiv/src/rcs_flexiv/scripts/test_robot.py +++ b/extensions/rcs_flexiv/src/rcs_flexiv/scripts/test_robot.py @@ -29,8 +29,8 @@ def main() -> None: robot_sn = sys.argv[1] gripper_device = sys.argv[2] if len(sys.argv) > 2 else None - robot_type = common.RobotType("Rizon4S") - gripper_type = common.GripperType("FlexivGrav") + robot_type = common.RobotType.Rizon4S + gripper_type = common.GripperType.FlexivGrav robot_config = FlexivConfig( robot_sn=robot_sn, control_mode=FlexivControlMode.JOINT_IMPEDANCE, diff --git a/extensions/rcs_yam/README.md b/extensions/rcs_yam/README.md index 12539ec7b..92440bb90 100644 --- a/extensions/rcs_yam/README.md +++ b/extensions/rcs_yam/README.md @@ -93,7 +93,7 @@ from rcs_yam.hw import Yam, YamConfig, YamGripper cfg = YamConfig(channel="can0", async_control=False, dof=6, ...) ik = common.Pin(cfg.kinematic_model_path, cfg.attachment_site, joint_limits=cfg.joint_limits) robot = Yam(cfg, ik) -gripper = YamGripper(common.GripperConfig(gripper_type=common.GripperType("Yam")), robot) +gripper = YamGripper(common.GripperConfig(gripper_type=common.GripperType.Yam), robot) robot.move_home() gripper.grasp() diff --git a/include/rcs/Robot.h b/include/rcs/Robot.h index 94b6dea0c..66f3008fb 100644 --- a/include/rcs/Robot.h +++ b/include/rcs/Robot.h @@ -50,6 +50,7 @@ struct RobotType : public TypeBase { static const RobotType UR5e; static const RobotType SO101; static const RobotType Yam; + static const RobotType Rizon4S; }; inline const RobotType RobotType::FR3{"FR3"}; inline const RobotType RobotType::Panda{"Panda"}; @@ -57,6 +58,7 @@ inline const RobotType RobotType::XArm7{"XArm7"}; inline const RobotType RobotType::UR5e{"UR5e"}; inline const RobotType RobotType::SO101{"SO101"}; inline const RobotType RobotType::Yam{"Yam"}; +inline const RobotType RobotType::Rizon4S{"Rizon4S"}; struct RobotConfig { RobotType robot_type = RobotType::FR3; @@ -89,6 +91,7 @@ struct GripperType : public TypeBase { static const GripperType Robotiq2F85Digit; static const GripperType SO101; static const GripperType Yam; + static const GripperType FlexivGrav; }; inline const GripperType GripperType::FrankaHand{"FrankaHand"}; inline const GripperType GripperType::PandaHand{"PandaHand"}; @@ -96,6 +99,7 @@ inline const GripperType GripperType::Robotiq2F85{"Robotiq2F85"}; inline const GripperType GripperType::Robotiq2F85Digit{"Robotiq2F85Digit"}; inline const GripperType GripperType::SO101{"SO101"}; inline const GripperType GripperType::Yam{"Yam"}; +inline const GripperType GripperType::FlexivGrav{"FlexivGrav"}; struct GripperConfig { GripperType gripper_type = GripperType::FrankaHand; diff --git a/python/rcs/__init__.py b/python/rcs/__init__.py index 3b97383b0..6db2f7ea4 100644 --- a/python/rcs/__init__.py +++ b/python/rcs/__init__.py @@ -228,7 +228,7 @@ class RobotMetaConfig: ), attachment_site="tcp_site", ), - common.RobotType("Rizon4S"): RobotMetaConfig( + common.RobotType.Rizon4S: RobotMetaConfig( mjcf_model_path="assets/robots/rizon4s/rizon4s.xml", dof=7, # flange pointing straight down (joint2 - joint4 + joint6 = -pi/2), about 0.56 m in front of @@ -248,7 +248,7 @@ class RobotMetaConfig: common.GripperType.FrankaHand: "assets/grippers/franka_hand/franka_hand.xml", common.GripperType.PandaHand: "assets/grippers/franka_hand/franka_hand.xml", common.GripperType.Robotiq2F85: "assets/grippers/robotiq_2f85/robotiq_2f85.xml", - common.GripperType("FlexivGrav"): "assets/grippers/flexiv_grav/flexiv_grav.xml", + common.GripperType.FlexivGrav: "assets/grippers/flexiv_grav/flexiv_grav.xml", } GRIPPER_TCP_OFFSETS: dict[common.GripperType, common.Pose] = { @@ -260,7 +260,7 @@ class RobotMetaConfig: common.GripperType.Yam: common.Pose(translation=np.array([0.0, 0.0, 0.1347])), # The "grav_tcp" frame of Flexiv's URDF, which Flexiv's own software uses as TCP. It sits roughly at the # pad center of the fully open gripper; the closed finger tips ("closed_fingers_tcp") are at 0.2 m. - common.GripperType("FlexivGrav"): common.Pose(translation=np.array([0.0, 0.0, 0.15])), + common.GripperType.FlexivGrav: common.Pose(translation=np.array([0.0, 0.0, 0.15])), } GRIPPER_MOUNT_OFFSETS: dict[common.GripperType, common.Pose] = { @@ -273,7 +273,7 @@ class RobotMetaConfig: common.GripperType.Robotiq2F85: common.Pose( translation=np.array([0.0, 0.0, 0.0]), quaternion=np.array([0.0, 0.0, 0.7071068, 0.7071068]) ), - common.GripperType("FlexivGrav"): common.Pose( + common.GripperType.FlexivGrav: common.Pose( translation=np.array([0.0, 0.0, 0.0]), quaternion=np.array([0.0, 0.0, 1.0, 0.0]) ), } diff --git a/python/rcs/_core/common.pyi b/python/rcs/_core/common.pyi index 41791467c..22befd6a4 100644 --- a/python/rcs/_core/common.pyi +++ b/python/rcs/_core/common.pyi @@ -20,8 +20,8 @@ __all__: list[str] = [ "HARDWARE", "Hand", "HandConfig", - "HandType", "HandState", + "HandType", "IdentityRotMatrix", "IdentityRotQuatVec", "IdentityTranslation", @@ -108,6 +108,7 @@ class GripperState: def __init__(self) -> None: ... class GripperType: + FlexivGrav: typing.ClassVar[GripperType] # value = FrankaHand: typing.ClassVar[GripperType] # value = PandaHand: typing.ClassVar[GripperType] # value = Robotiq2F85: typing.ClassVar[GripperType] # value = @@ -136,6 +137,13 @@ class Hand: def set_normalized_joint_poses(self, q: numpy.ndarray[tuple[M], numpy.dtype[numpy.float64]]) -> None: ... def shut(self) -> None: ... +class HandConfig: + hand_type: HandType + def __init__(self, hand_type: HandType = ...) -> None: ... + +class HandState: + def __init__(self) -> None: ... + class HandType: TilburgHand: typing.ClassVar[HandType] # value = @staticmethod @@ -147,13 +155,6 @@ class HandType: @property def id(self) -> str: ... -class HandConfig: - hand_type: HandType - def __init__(self, hand_type: HandType = ...) -> None: ... - -class HandState: - def __init__(self) -> None: ... - class Kinematics: def __init__(self) -> None: ... def forward(self, q0: numpy.ndarray[tuple[M], numpy.dtype[numpy.float64]], tcp_offset: Pose = ...) -> Pose: ... @@ -313,6 +314,7 @@ class RobotState: class RobotType: FR3: typing.ClassVar[RobotType] # value = Panda: typing.ClassVar[RobotType] # value = + Rizon4S: typing.ClassVar[RobotType] # value = SO101: typing.ClassVar[RobotType] # value = UR5e: typing.ClassVar[RobotType] # value = XArm7: typing.ClassVar[RobotType] # value = diff --git a/python/rcs/envs/configs.py b/python/rcs/envs/configs.py index 96d9e9832..d79ad936f 100644 --- a/python/rcs/envs/configs.py +++ b/python/rcs/envs/configs.py @@ -614,13 +614,13 @@ class EmptyWorldRizon4S(EmptyWorldFR3): """Flexiv Rizon 4s with the Flexiv Grav (GN-01) gripper mounted on the flange.""" def config(self) -> SimEnvCreatorConfig: - rt = RobotType("Rizon4S") + rt = RobotType.Rizon4S cfg = super().config() lead_robot_name = self.lead_robot_name(cfg) robot_cfg = cfg.robot_cfgs[lead_robot_name] robot_cfg.robot_type = rt - robot_cfg.tcp_offset = GRIPPER_TCP_OFFSETS[GripperType("FlexivGrav")] + robot_cfg.tcp_offset = GRIPPER_TCP_OFFSETS[GripperType.FlexivGrav] robot_cfg.attachment_site = rcs.ROBOTS[rt].attachment_site robot_cfg.kinematic_model_path = rcs.ROBOTS[rt].mjcf_model_path robot_cfg.arm_collision_geoms = [] @@ -633,7 +633,7 @@ def config(self) -> SimEnvCreatorConfig: assert cfg.gripper_cfgs is not None gripper_cfg = cfg.gripper_cfgs[lead_robot_name] - gripper_cfg.gripper_type = GripperType("FlexivGrav") + gripper_cfg.gripper_type = GripperType.FlexivGrav # The actuator is commanded in finger opening width (0 m closed, 0.1 m open). gripper_cfg.actuator = "fingers_actuator" gripper_cfg.min_actuator_width = 0.0 @@ -645,7 +645,7 @@ def config(self) -> SimEnvCreatorConfig: gripper_cfg.collision_geoms = ["left_pad1", "left_pad2", "right_pad1", "right_pad2"] gripper_cfg.collision_geoms_fingers = ["left_pad1", "left_pad2", "right_pad1", "right_pad2"] - cfg.gripper_offsets = {lead_robot_name: GRIPPER_MOUNT_OFFSETS[GripperType("FlexivGrav")]} + cfg.gripper_offsets = {lead_robot_name: GRIPPER_MOUNT_OFFSETS[GripperType.FlexivGrav]} # D405 wrist camera on a rail screwed to the accessory pocket of the wrist link, see assets/objects/rizon_d405_wrist_mount cfg.robot_frame_objects = { lead_robot_name: { @@ -778,7 +778,7 @@ def config(self) -> SimEnvCreatorConfig: robot_cfgs[name] = robot_cfg gripper_cfgs[name] = copy.deepcopy(base_gripper_cfg) - grav_offset = GRIPPER_MOUNT_OFFSETS[GripperType("FlexivGrav")] + grav_offset = GRIPPER_MOUNT_OFFSETS[GripperType.FlexivGrav] # D405 wrist camera on its mount on each arm, see EmptyWorldRizon4S robot_frame_objects = { name: { diff --git a/python/tests/test_kinematics.py b/python/tests/test_kinematics.py index 2c77a4390..b899e6f03 100644 --- a/python/tests/test_kinematics.py +++ b/python/tests/test_kinematics.py @@ -13,13 +13,13 @@ common.RobotType.UR5e, common.RobotType.SO101, common.RobotType.Yam, - common.RobotType("Rizon4S"), + common.RobotType.Rizon4S, ] # Robots with a genuine redundant DOF (7-DoF arms), where null-space biasing has room to act. REDUNDANT_ROBOTS = [ common.RobotType.FR3, - common.RobotType("XArm7"), + common.RobotType.XArm7, ] # Identity pose / no TCP offset, reused across tests. @@ -250,7 +250,7 @@ def test_kinematics_joint_limits_override_model_limits(): def test_kinematics_joint_limits_more_joints_than_model_raises(): - robot = rcs.ROBOTS[common.RobotType("UR5e")] + robot = rcs.ROBOTS[common.RobotType.UR5e] too_many = np.vstack([-np.ones(robot.dof + 1), np.ones(robot.dof + 1)]) with pytest.raises(ValueError, match="joint_limits"): common.Pin(robot.mjcf_model_path, robot.attachment_site, False, joint_limits=too_many) diff --git a/src/pybind/rcs.cpp b/src/pybind/rcs.cpp index ab1ec2ea5..a788f2b9a 100644 --- a/src/pybind/rcs.cpp +++ b/src/pybind/rcs.cpp @@ -415,7 +415,8 @@ PYBIND11_MODULE(_core, m) { .def_readonly_static("XArm7", &rcs::common::RobotType::XArm7) .def_readonly_static("UR5e", &rcs::common::RobotType::UR5e) .def_readonly_static("SO101", &rcs::common::RobotType::SO101) - .def_readonly_static("Yam", &rcs::common::RobotType::Yam); + .def_readonly_static("Yam", &rcs::common::RobotType::Yam) + .def_readonly_static("Rizon4S", &rcs::common::RobotType::Rizon4S); py::enum_(common, "RobotPlatform") .value("HARDWARE", rcs::common::RobotPlatform::HARDWARE) @@ -473,7 +474,8 @@ PYBIND11_MODULE(_core, m) { .def_readonly_static("Robotiq2F85Digit", &rcs::common::GripperType::Robotiq2F85Digit) .def_readonly_static("SO101", &rcs::common::GripperType::SO101) - .def_readonly_static("Yam", &rcs::common::GripperType::Yam); + .def_readonly_static("Yam", &rcs::common::GripperType::Yam) + .def_readonly_static("FlexivGrav", &rcs::common::GripperType::FlexivGrav); rcs::common::GripperConfig default_gripper_config; py::class_(common, "GripperConfig") From ee87c7b1fed020f9df9c2f1ee213ec548e9692ee Mon Sep 17 00:00:00 2001 From: Tobias Juelg Date: Fri, 20 Nov 2026 15:44:10 -0800 Subject: [PATCH 11/16] style: sort imports of the fr3 creators --- extensions/rcs_fr3/src/rcs_fr3/creators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/rcs_fr3/src/rcs_fr3/creators.py b/extensions/rcs_fr3/src/rcs_fr3/creators.py index 31f9fe927..69e25e215 100644 --- a/extensions/rcs_fr3/src/rcs_fr3/creators.py +++ b/extensions/rcs_fr3/src/rcs_fr3/creators.py @@ -4,6 +4,7 @@ import gymnasium as gym import numpy as np +from frankik import FrankaKinematics from rcs._core.common import Gripper, GripperConfig, HandConfig, Kinematics, Pose from rcs.camera.hw import HardwareCameraCreatorConfig, create_hardware_camera_set from rcs.envs.base import ( @@ -24,7 +25,6 @@ from rcs_fr3.envs import FR3HW import rcs -from frankik import FrankaKinematics logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) From f6b7cb61a49fbbe04a6be760692a99b1490cc880 Mon Sep 17 00:00:00 2001 From: Tobias Juelg Date: Fri, 20 Nov 2026 15:49:34 -0800 Subject: [PATCH 12/16] feat(composer): exclude attachments from gravity compensation SimEnvCreatorConfig.gravcomp_ignore lists ids of camera_adds and robot_frame_objects that are not gravity-compensated even when add_gravcomp is set, e.g. a wrist camera and its mount that the controller of the real robot does not compensate. The simulated arm then carries them as an uncompensated load, like the real robot. Unknown ids raise. The default is empty, so existing configs are unchanged. --- python/rcs/envs/scenes.py | 16 ++++++++++++++++ python/rcs/sim/composer.py | 14 ++++++++++++-- python/tests/test_gravcomp.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 python/tests/test_gravcomp.py diff --git a/python/rcs/envs/scenes.py b/python/rcs/envs/scenes.py index 28170de36..6b7832666 100644 --- a/python/rcs/envs/scenes.py +++ b/python/rcs/envs/scenes.py @@ -108,6 +108,11 @@ class SimEnvCreatorConfig(typing.Generic[TaskConfig]): """shared base frame is a common reference frame for all robots in the scene and the origin for all actions and observations, e.g. the middle of franka duo thus this transformation defines the offset of each robot's base to this shared base frame.""" add_gravcomp: bool = False + gravcomp_ignore: set[str] = field(default_factory=set) + """ids of attached cameras (``camera_adds`` keys) and robot-frame objects (``robot_frame_objects`` ids) + that are NOT gravity-compensated even when ``add_gravcomp`` is True, e.g. a wrist camera and its mount + that the real robot's controller does not compensate. The simulated arm then carries them as an + uncompensated load, like the real robot.""" wrapper_cfg: WrapperConfig = field(default_factory=WrapperConfig) headless: bool = False shared_base_frame_to_root_frame: rcs.common.Pose = field(default_factory=rcs.common.Pose) @@ -326,6 +331,17 @@ def create_model(self, cfg: SimEnvCreatorConfig) -> MjModel: ), ) + # attachments the real robot's controller does not gravity-compensate, their prefix is id + "_" + if cfg.gravcomp_ignore: + attachments = set(cfg.camera_adds or {}) | { + object_id for robot_objects in (cfg.robot_frame_objects or {}).values() for object_id in robot_objects + } + unknown = cfg.gravcomp_ignore - attachments + if unknown: + msg = f"gravcomp_ignore contains ids that are neither camera_adds nor robot_frame_objects: {sorted(unknown)}" + raise ValueError(msg) + composer.ignore_gravcomp({f"{attachment_id}_" for attachment_id in cfg.gravcomp_ignore}) + if cfg.visual_randomization is not None and cfg.visual_randomization.enabled_randomizers(): composer.visual_randomization_params = VisualRandomizer(cfg.visual_randomization).apply( composer.spec, np.random.default_rng(cfg.visual_randomization.seed) diff --git a/python/rcs/sim/composer.py b/python/rcs/sim/composer.py index 4ed1fcf66..3cc5e01e2 100644 --- a/python/rcs/sim/composer.py +++ b/python/rcs/sim/composer.py @@ -20,6 +20,7 @@ def __init__( self.spec.compiler.autolimits = True self.add_gravcomp = add_gravcomp self._gravcomp_prefixes: set[str] = set() + self._gravcomp_ignore_prefixes: set[str] = set() self._root_relative_replay_free_joints: set[str] = set() self.visual_randomization_params: dict[str, Any] = {} """sampled parameters of the visual randomization applied to this scene, if any""" @@ -74,6 +75,10 @@ def _prefixed_free_joint_names(self, spec: mujoco.MjSpec, prefix: str) -> list[s free_joint_type = int(mujoco.mjtJoint.mjJNT_FREE) return [f"{prefix}{joint.name}" for joint in spec.joints if joint.name and int(joint.type) == free_joint_type] + def ignore_gravcomp(self, prefixes: set[str]): + """Excludes bodies and joints whose names start with one of the prefixes from gravity compensation.""" + self._gravcomp_ignore_prefixes.update(prefixes) + def register_root_relative_replay_free_joints(self, joint_names: list[str]): self._root_relative_replay_free_joints.update(joint_names) @@ -331,10 +336,15 @@ def _apply_gravcomp(self): if not self.add_gravcomp or not self._gravcomp_prefixes: return + def compensated(name: str) -> bool: + return any(name.startswith(prefix) for prefix in self._gravcomp_prefixes) and not any( + name.startswith(prefix) for prefix in self._gravcomp_ignore_prefixes + ) + for body in self.spec.bodies: - if body.name and any(body.name.startswith(prefix) for prefix in self._gravcomp_prefixes): + if body.name and compensated(body.name): body.gravcomp = 1 for joint in self.spec.joints: - if joint.name and any(joint.name.startswith(prefix) for prefix in self._gravcomp_prefixes): + if joint.name and compensated(joint.name): joint.actgravcomp = True diff --git a/python/tests/test_gravcomp.py b/python/tests/test_gravcomp.py new file mode 100644 index 000000000..25bcc55d4 --- /dev/null +++ b/python/tests/test_gravcomp.py @@ -0,0 +1,31 @@ +import pytest +from rcs.envs.configs import EmptyWorldDroid +from rcs.sim.composer import ModelComposer + + +def _compensated_bodies(gravcomp_ignore: set[str]) -> set[str]: + scene = EmptyWorldDroid() + cfg = scene.config() + cfg.add_gravcomp = True + cfg.gravcomp_ignore = gravcomp_ignore + composer = scene.create_model(cfg) + assert isinstance(composer, ModelComposer) + model = composer.get_model() + return {model.body(i).name for i in range(model.nbody) if model.body_gravcomp[i] > 0} + + +def test_gravcomp_ignore_excludes_only_the_given_attachments(): + compensated = _compensated_bodies(set()) + # the wrist camera (camera_adds) and its mount (robot_frame_objects) are compensated by default + assert {"wrist_zed_mini", "zed_mount_base"} <= compensated + + ignored = _compensated_bodies({"wrist", "zed_mount"}) + assert ignored == compensated - {"wrist_zed_mini", "zed_mount_base"} + # the arm and the gripper stay compensated + assert any(name.startswith("rightfr3_link") for name in ignored) + assert any(name.startswith("gripper") for name in ignored) + + +def test_gravcomp_ignore_rejects_unknown_ids(): + with pytest.raises(ValueError, match="missing"): + _compensated_bodies({"missing"}) From 27966e52d0695df794babde6165978ca19287abd Mon Sep 17 00:00:00 2001 From: Tobias Juelg Date: Fri, 20 Nov 2026 16:09:29 -0800 Subject: [PATCH 13/16] fix(ur5e): create the robotiq gripper through the gripper registry The UR5e env creator resolved its Robotiq2F85 gripper config through the registry to the rcs_robotiq2f85 factory, which drives the gripper over a serial port and rejects the UR gripper config. The Robotiq 2F-85 on the UR is driven through the UR controller (Robotiq URCap), so it gets its own gripper type Robotiq2F85UR, which rcs_ur5e registers as an rcs.grippers entry point and which RobotiQGripperConfig uses by default. The arm can still be created without a gripper or with any other registered gripper. --- extensions/rcs_ur5e/pyproject.toml | 3 +++ extensions/rcs_ur5e/src/rcs_ur5e/configs.py | 7 ++----- extensions/rcs_ur5e/src/rcs_ur5e/creators.py | 14 ++++++++++++-- extensions/rcs_ur5e/src/rcs_ur5e/hw.py | 3 +++ include/rcs/Robot.h | 4 ++++ python/rcs/_core/common.pyi | 1 + src/pybind/rcs.cpp | 2 ++ 7 files changed, 27 insertions(+), 7 deletions(-) diff --git a/extensions/rcs_ur5e/pyproject.toml b/extensions/rcs_ur5e/pyproject.toml index d0d820ca5..875de7b85 100644 --- a/extensions/rcs_ur5e/pyproject.toml +++ b/extensions/rcs_ur5e/pyproject.toml @@ -18,6 +18,9 @@ authors = [ ] requires-python = ">=3.11" +[project.entry-points."rcs.grippers"] +Robotiq2F85UR = "rcs_ur5e.creators:create_robotiq_gripper" + [tool.black] line-length = 120 target-version = ["py310"] diff --git a/extensions/rcs_ur5e/src/rcs_ur5e/configs.py b/extensions/rcs_ur5e/src/rcs_ur5e/configs.py index 010286683..37802922b 100644 --- a/extensions/rcs_ur5e/src/rcs_ur5e/configs.py +++ b/extensions/rcs_ur5e/src/rcs_ur5e/configs.py @@ -1,4 +1,4 @@ -from rcs._core.common import GripperType, RobotType +from rcs._core.common import RobotType from rcs.envs.base import ControlMode, RelativeTo from rcs_ur5e.creators import RCSUR5eConfigEnvCreator, UR5eHardwareEnvCreatorConfig from rcs_ur5e.hw import RobotiQGripperConfig, UR5eConfig @@ -29,10 +29,7 @@ def config(self) -> UR5eHardwareEnvCreatorConfig: tcp_offset=rcs.common.Pose(), ) - gripper_cfg = RobotiQGripperConfig( - ip=self.ip, - gripper_type=GripperType.Robotiq2F85, - ) + gripper_cfg = RobotiQGripperConfig(ip=self.ip) return UR5eHardwareEnvCreatorConfig( control_mode=ControlMode.CARTESIAN_TRPY, diff --git a/extensions/rcs_ur5e/src/rcs_ur5e/creators.py b/extensions/rcs_ur5e/src/rcs_ur5e/creators.py index ab502d5ca..32c8e84f3 100644 --- a/extensions/rcs_ur5e/src/rcs_ur5e/creators.py +++ b/extensions/rcs_ur5e/src/rcs_ur5e/creators.py @@ -2,7 +2,7 @@ from dataclasses import dataclass, field import gymnasium as gym -from rcs._core.common import GripperConfig +from rcs._core.common import Gripper, GripperConfig from rcs.camera.hw import HardwareCameraCreatorConfig, create_hardware_camera_set from rcs.envs.base import ( CameraSetWrapper, @@ -15,7 +15,7 @@ RobotWrapper, ) from rcs.envs.scenes import RCSEnvCreator, WrapperConfig -from rcs_ur5e.hw import UR5e, UR5eConfig +from rcs_ur5e.hw import RobotiQGripper, RobotiQGripperConfig, UR5e, UR5eConfig import rcs @@ -23,11 +23,21 @@ logger.setLevel(logging.INFO) +def create_robotiq_gripper(cfg: GripperConfig) -> Gripper: + """Factory of the `Robotiq2F85UR` gripper type, the Robotiq 2F-85 driven through the UR controller.""" + if not isinstance(cfg, RobotiQGripperConfig): + msg = f"Expected rcs_ur5e RobotiQGripperConfig for the UR robotiq gripper, got {type(cfg).__name__}" + raise TypeError(msg) + return RobotiQGripper(cfg) + + @dataclass(kw_only=True) class UR5eHardwareEnvCreatorConfig: robot_cfg: UR5eConfig control_mode: ControlMode gripper_cfg: GripperConfig | None = None + """None for no gripper, otherwise created through `rcs.registry.GRIPPERS` by its gripper type, e.g. a + `RobotiQGripperConfig` for the Robotiq 2F-85 driven through the UR controller (`Robotiq2F85UR`).""" camera_cfgs: dict[str, HardwareCameraCreatorConfig] | None = None max_relative_movement: float | tuple[float, float] | None = None relative_to: RelativeTo = RelativeTo.LAST_STEP diff --git a/extensions/rcs_ur5e/src/rcs_ur5e/hw.py b/extensions/rcs_ur5e/src/rcs_ur5e/hw.py index e310329ed..c111716d7 100644 --- a/extensions/rcs_ur5e/src/rcs_ur5e/hw.py +++ b/extensions/rcs_ur5e/src/rcs_ur5e/hw.py @@ -64,7 +64,10 @@ def from_dict(self, data: dict[str, typing.Any]) -> None: class RobotiQGripperConfig(common.GripperConfig): + """Robotiq 2F-85 on the UR tool flange, driven through the UR controller (Robotiq URCap, port 63352).""" + def __init__(self, ip: str, **kwargs: typing.Unpack[GripperConfigKwargs]) -> None: + kwargs.setdefault("gripper_type", common.GripperType.Robotiq2F85UR) super().__init__(**kwargs) self.ip = ip diff --git a/include/rcs/Robot.h b/include/rcs/Robot.h index 66f3008fb..25ed354fc 100644 --- a/include/rcs/Robot.h +++ b/include/rcs/Robot.h @@ -89,6 +89,7 @@ struct GripperType : public TypeBase { static const GripperType PandaHand; static const GripperType Robotiq2F85; static const GripperType Robotiq2F85Digit; + static const GripperType Robotiq2F85UR; static const GripperType SO101; static const GripperType Yam; static const GripperType FlexivGrav; @@ -97,6 +98,9 @@ inline const GripperType GripperType::FrankaHand{"FrankaHand"}; inline const GripperType GripperType::PandaHand{"PandaHand"}; inline const GripperType GripperType::Robotiq2F85{"Robotiq2F85"}; inline const GripperType GripperType::Robotiq2F85Digit{"Robotiq2F85Digit"}; +// Robotiq 2F-85 on a UR arm, driven through the robot controller (Robotiq +// URCap) +inline const GripperType GripperType::Robotiq2F85UR{"Robotiq2F85UR"}; inline const GripperType GripperType::SO101{"SO101"}; inline const GripperType GripperType::Yam{"Yam"}; inline const GripperType GripperType::FlexivGrav{"FlexivGrav"}; diff --git a/python/rcs/_core/common.pyi b/python/rcs/_core/common.pyi index 22befd6a4..307ff9ef5 100644 --- a/python/rcs/_core/common.pyi +++ b/python/rcs/_core/common.pyi @@ -113,6 +113,7 @@ class GripperType: PandaHand: typing.ClassVar[GripperType] # value = Robotiq2F85: typing.ClassVar[GripperType] # value = Robotiq2F85Digit: typing.ClassVar[GripperType] # value = + Robotiq2F85UR: typing.ClassVar[GripperType] # value = SO101: typing.ClassVar[GripperType] # value = Yam: typing.ClassVar[GripperType] # value = @staticmethod diff --git a/src/pybind/rcs.cpp b/src/pybind/rcs.cpp index a788f2b9a..b36004d8a 100644 --- a/src/pybind/rcs.cpp +++ b/src/pybind/rcs.cpp @@ -473,6 +473,8 @@ PYBIND11_MODULE(_core, m) { &rcs::common::GripperType::Robotiq2F85) .def_readonly_static("Robotiq2F85Digit", &rcs::common::GripperType::Robotiq2F85Digit) + .def_readonly_static("Robotiq2F85UR", + &rcs::common::GripperType::Robotiq2F85UR) .def_readonly_static("SO101", &rcs::common::GripperType::SO101) .def_readonly_static("Yam", &rcs::common::GripperType::Yam) .def_readonly_static("FlexivGrav", &rcs::common::GripperType::FlexivGrav); From 10b07328e419f910773b090624cf8cd1fe7acb51 Mon Sep 17 00:00:00 2001 From: Tobias Juelg Date: Fri, 20 Nov 2026 16:09:42 -0800 Subject: [PATCH 14/16] fix(panda): always create the panda hand for rcs_panda hand configs rcs_panda's FHConfig is built from the fr3 sources, so its gripper type defaults to FrankaHand. A hand config without an explicitly set PandaHand type was resolved to rcs_fr3's FrankaHand factory, which rejects it or is not installed. The panda env creator now creates the panda hand for every rcs_panda FHConfig and uses the gripper registry for all other gripper configs. --- extensions/rcs_panda/src/rcs_panda/creators.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/extensions/rcs_panda/src/rcs_panda/creators.py b/extensions/rcs_panda/src/rcs_panda/creators.py index f13ac8466..fd93ec3e2 100644 --- a/extensions/rcs_panda/src/rcs_panda/creators.py +++ b/extensions/rcs_panda/src/rcs_panda/creators.py @@ -80,6 +80,11 @@ def create_env(self, cfg: PandaHardwareEnvCreatorConfig) -> gym.Env: if cfg.hand_cfg is not None: hand = rcs.registry.HANDS.get(cfg.hand_cfg.hand_type.id)(cfg.hand_cfg) env = HandWrapper(env, hand, binary=cfg.wrapper_cfg.binary_gripper) + elif isinstance(cfg.gripper_cfg, hw.FHConfig): + # This extension's FHConfig is built from the fr3 sources, so its gripper type defaults to + # rcs_fr3's FrankaHand. Its hand is always the panda hand, whatever the type says. + gripper = create_panda_gripper(cfg.gripper_cfg) + env = GripperWrapper(env, gripper, binary=cfg.wrapper_cfg.binary_gripper) elif cfg.gripper_cfg is not None: gripper = rcs.registry.GRIPPERS.get(cfg.gripper_cfg.gripper_type.id)(cfg.gripper_cfg) env = GripperWrapper(env, gripper, binary=cfg.wrapper_cfg.binary_gripper) From d670d2ac553a9b6115dbf5c5ffd78a338e98967f Mon Sep 17 00:00:00 2001 From: Tobias Juelg Date: Fri, 20 Nov 2026 16:09:58 -0800 Subject: [PATCH 15/16] build: align extension versions with the current release rcs_digit and rcs_tilburg_hand were at 0.7.3 and the __version__ of rcs_usb_cam and rcs_zed at 0.5.2 and 0.6.3, while everything else is at 0.7.4. Commitizen bumps by replacing the current version in the version files, so these were not bumped. All version files now carry 0.7.4. --- extensions/rcs_digit/pyproject.toml | 4 ++-- extensions/rcs_digit/src/rcs_digit/__init__.py | 2 +- extensions/rcs_tilburg_hand/pyproject.toml | 4 ++-- extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/__init__.py | 2 +- extensions/rcs_usb_cam/src/rcs_usb_cam/__init__.py | 2 +- extensions/rcs_zed/src/rcs_zed/__init__.py | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/extensions/rcs_digit/pyproject.toml b/extensions/rcs_digit/pyproject.toml index 858db4bbe..7ed589953 100644 --- a/extensions/rcs_digit/pyproject.toml +++ b/extensions/rcs_digit/pyproject.toml @@ -4,11 +4,11 @@ build-backend = "setuptools.build_meta" [project] name = "rcs_digit" -version = "0.7.3" +version = "0.7.4" description = "RCS DIGIT tactile sensor module" readme = "README.md" license = "AGPL-3.0-or-later" -dependencies = ["rcs-core>=0.7.3", "digit-interface"] +dependencies = ["rcs-core>=0.7.4", "digit-interface"] maintainers = [ { name = "Tobias Juelg", email = "tobias.juelg@utn.de" }, ] diff --git a/extensions/rcs_digit/src/rcs_digit/__init__.py b/extensions/rcs_digit/src/rcs_digit/__init__.py index 4910b9ec3..ed9d4d87b 100644 --- a/extensions/rcs_digit/src/rcs_digit/__init__.py +++ b/extensions/rcs_digit/src/rcs_digit/__init__.py @@ -1 +1 @@ -__version__ = "0.7.3" +__version__ = "0.7.4" diff --git a/extensions/rcs_tilburg_hand/pyproject.toml b/extensions/rcs_tilburg_hand/pyproject.toml index 24059aa64..54c5ba315 100644 --- a/extensions/rcs_tilburg_hand/pyproject.toml +++ b/extensions/rcs_tilburg_hand/pyproject.toml @@ -4,11 +4,11 @@ build-backend = "setuptools.build_meta" [project] name = "rcs_tilburg_hand" -version = "0.7.3" +version = "0.7.4" description = "RCS Tilburg Hand module" readme = "README.md" license = "AGPL-3.0-or-later" -dependencies = ["rcs-core>=0.7.3", "tilburg-hand"] +dependencies = ["rcs-core>=0.7.4", "tilburg-hand"] maintainers = [ { name = "Tobias Juelg", email = "tobias.juelg@utn.de" }, ] diff --git a/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/__init__.py b/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/__init__.py index 4910b9ec3..ed9d4d87b 100644 --- a/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/__init__.py +++ b/extensions/rcs_tilburg_hand/src/rcs_tilburg_hand/__init__.py @@ -1 +1 @@ -__version__ = "0.7.3" +__version__ = "0.7.4" diff --git a/extensions/rcs_usb_cam/src/rcs_usb_cam/__init__.py b/extensions/rcs_usb_cam/src/rcs_usb_cam/__init__.py index 722515271..ed9d4d87b 100644 --- a/extensions/rcs_usb_cam/src/rcs_usb_cam/__init__.py +++ b/extensions/rcs_usb_cam/src/rcs_usb_cam/__init__.py @@ -1 +1 @@ -__version__ = "0.5.2" +__version__ = "0.7.4" diff --git a/extensions/rcs_zed/src/rcs_zed/__init__.py b/extensions/rcs_zed/src/rcs_zed/__init__.py index 63af88769..ed9d4d87b 100644 --- a/extensions/rcs_zed/src/rcs_zed/__init__.py +++ b/extensions/rcs_zed/src/rcs_zed/__init__.py @@ -1 +1 @@ -__version__ = "0.6.3" +__version__ = "0.7.4" From 2026ff93df1de8d5b44faa4b36efd1af6f04a2c5 Mon Sep 17 00:00:00 2001 From: Tobias Juelg Date: Fri, 20 Nov 2026 16:10:21 -0800 Subject: [PATCH 16/16] docs: pass the tilburg hand as hand config, update registry id example The tilburg hand docs still passed THConfig as gripper_cfg, which now goes to the gripper registry. The arm creators take it as hand_cfg. The registry docstring used FrankaHand of rcs_fr3 and rcs_panda as an example of a duplicate id, but rcs_panda now registers PandaHand. --- docs/extensions/rcs_tilburg_hand.md | 5 +++-- extensions/rcs_tilburg_hand/README.md | 7 ++++--- python/rcs/registry.py | 9 ++++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/docs/extensions/rcs_tilburg_hand.md b/docs/extensions/rcs_tilburg_hand.md index 5c82b6ccd..6498c2179 100644 --- a/docs/extensions/rcs_tilburg_hand.md +++ b/docs/extensions/rcs_tilburg_hand.md @@ -5,8 +5,9 @@ This extension provides support for the Tilburg Hand in RCS. It covers the **hardware** hand only. The simulated hand, `rcs.sim.SimTilburgHand`, is implemented in C++ inside `rcs-core` and needs nothing from this extension. -The arm extensions accept a `THConfig` wherever they take a gripper config, and attach the hand -through a `HandWrapper` once this extension is installed. +The arm extensions with hand support (`rcs_fr3`, `rcs_panda` and `rcs_xarm7`) take a `THConfig` as +their `hand_cfg` (`hand_cfgs` per robot for the multi-robot creators) and attach the hand through a +`HandWrapper` once this extension is installed. ## Installation diff --git a/extensions/rcs_tilburg_hand/README.md b/extensions/rcs_tilburg_hand/README.md index 042269690..548e43478 100644 --- a/extensions/rcs_tilburg_hand/README.md +++ b/extensions/rcs_tilburg_hand/README.md @@ -34,13 +34,14 @@ pip install -ve extensions/rcs_tilburg_hand ## Usage -The arm extensions accept a `THConfig` wherever they take a gripper config, and attach the hand -through a `HandWrapper` once this extension is installed: +The arm extensions with hand support (`rcs_fr3`, `rcs_panda` and `rcs_xarm7`) take a `THConfig` as +their `hand_cfg` (`hand_cfgs` per robot for the multi-robot creators) and attach the hand through a +`HandWrapper` once this extension is installed: ```python from rcs_tilburg_hand.hand import THConfig -cfg.gripper_cfg = THConfig( +cfg.hand_cfg = THConfig( calibration_file="/path/to/calibration.json", grasp_percentage=1, hand_orientation="right", diff --git a/python/rcs/registry.py b/python/rcs/registry.py index 045ad8e21..2f6723269 100644 --- a/python/rcs/registry.py +++ b/python/rcs/registry.py @@ -12,9 +12,12 @@ backend that is not installed is simply absent from the metadata, which is how a missing extension surfaces: as an unknown id, with the installed ids listed next to it. -Two installed distributions may provide the same id, for example `rcs_fr3` and `rcs_panda` both -implement `FrankaHand` against different libfranka versions. Resolving that silently would pick an -arbitrary one, so it is an error instead; `register` settles it explicitly for the process. +Two installed distributions may provide the same id, for example two packages that both drive the +same gripper model. Resolving that silently would pick an arbitrary one, so it is an error instead; +`register` settles it explicitly for the process. Backends of the same device that are driven +differently get their own ids instead, e.g. `FrankaHand` (`rcs_fr3`) and `PandaHand` (`rcs_panda`) +for the libfranka versions, or `Robotiq2F85` (serial, `rcs_robotiq2f85`) and `Robotiq2F85UR` (through +the UR controller, `rcs_ur5e`). """ from collections.abc import Callable