Skip to content

Commit 3512142

Browse files
committed
refactor!: wrapper parameters into config objects
- robot wrapper: home_on_reset -> into robot config - robot wrapper: home position for home_on_reset configurable in robot config - gripper wrapper: binary -> into gripper config
1 parent 7e7446c commit 3512142

17 files changed

Lines changed: 236 additions & 58 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ stubgen:
3030
find ./python -not -path "./python/rcs/_core/*" -name '*.pyi' -delete
3131
find ./python/rcs/_core -name '*.pyi' -print | xargs sed -i 's/tuple\[typing\.Literal\[\([0-9]\+\)\], typing\.Literal\[1\]\]/tuple\[typing\.Literal[\1]\]/g'
3232
find ./python/rcs/_core -name '*.pyi' -print | xargs sed -i 's/tuple\[\([M|N]\), typing\.Literal\[1\]\]/tuple\[\1\]/g'
33+
sed -i 's/ q_home: numpy\.ndarray\[tuple\[M\], numpy\.dtype\[numpy\.float64\]\] | None/ q_home: numpy.ndarray | None/' python/rcs/_core/common.pyi
3334
python scripts/generate_common_typing.py
3435
ruff check --fix python/rcs/_core python/rcs/common_typing.py
3536
isort python/rcs/_core python/rcs/common_typing.py

examples/fr3/fr3_readme.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
# gripper
5050
gripper = sim.SimGripper(simulation, gripper_cfg)
51-
env = GripperWrapper(env, gripper, binary=True)
51+
env = GripperWrapper(env, gripper)
5252

5353
env = RobotSimWrapper(env)
5454
env = GripperWrapperSim(env)

extensions/rcs_fr3/src/rcs_fr3/creators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def __call__( # type: ignore
100100
if isinstance(gripper_cfg, hw.FHConfig):
101101
gripper_cfg.ip = ip
102102
gripper = hw.FrankaHand(gripper_cfg)
103-
env = GripperWrapper(env, gripper, binary=True)
103+
env = GripperWrapper(env, gripper)
104104
elif isinstance(gripper_cfg, rcs.hand.tilburg_hand.THConfig):
105105
hand = TilburgHand(gripper_cfg)
106106
env = HandWrapper(env, hand, binary=True)
@@ -164,7 +164,7 @@ def __call__( # type: ignore
164164
if gripper_cfg is not None:
165165
gripper_cfg.ip = ip
166166
gripper = hw.FrankaHand(gripper_cfg)
167-
env = GripperWrapper(env, gripper, binary=True)
167+
env = GripperWrapper(env, gripper)
168168

169169
if max_relative_movement is not None:
170170
env = RelativeActionSpace(env, max_mov=max_relative_movement, relative_to=relative_to)

extensions/rcs_panda/src/rcs_panda/creators.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,13 @@ def __call__( # type: ignore
7575
env,
7676
robot,
7777
ControlMode.JOINTS if collision_guard is not None else control_mode,
78-
home_on_reset=True,
7978
)
8079

8180
env = PandaHW(env)
8281
if isinstance(gripper_cfg, hw.FHConfig):
8382
gripper_cfg.ip = ip
8483
gripper = hw.FrankaHand(gripper_cfg)
85-
env = GripperWrapper(env, gripper, binary=True)
84+
env = GripperWrapper(env, gripper)
8685
elif isinstance(gripper_cfg, rcs.hand.tilburg_hand.THConfig):
8786
hand = TilburgHand(gripper_cfg)
8887
env = HandWrapper(env, hand, binary=True)
@@ -144,7 +143,7 @@ def __call__( # type: ignore
144143
if gripper_cfg is not None:
145144
gripper_cfg.ip = ip
146145
gripper = hw.FrankaHand(gripper_cfg)
147-
env = GripperWrapper(env, gripper, binary=True)
146+
env = GripperWrapper(env, gripper)
148147

149148
if max_relative_movement is not None:
150149
env = RelativeActionSpace(env, max_mov=max_relative_movement, relative_to=relative_to)

extensions/rcs_robotiq2f85/src/rcs_robotiq2f85/hw.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1+
import typing
2+
13
from rcs._core.common import Gripper, GripperConfig, GripperState
4+
from rcs.common_typing import GripperConfigKwargs
25
from Robotiq2F85Driver.Robotiq2F85Driver import GripperStatus, Robotiq2F85Driver
36

47

58
class RobotiQ2F85GripperConfig(GripperConfig):
69

7-
def __init__(self, serial_number: str, speed: float = 100, force: float = 50, async_control: bool = True) -> None:
10+
def __init__(
11+
self,
12+
serial_number: str,
13+
speed: float = 100,
14+
force: float = 50,
15+
async_control: bool = True,
16+
**kwargs: typing.Unpack[GripperConfigKwargs],
17+
) -> None:
818
"""
919
Args:
1020
serial_number: Get the serial number with `udevadm info -a -n /dev/ttyUSB0 | grep serial`, make sure you have read/write permissions to the port.
1121
speed: Speed in mm/s. Must be between 20 and 150 mm/s.
1222
force: Force in N. Must be between 20 and 235 N.
1323
async_control: If True, gripper commands return immediately without waiting for the movement to complete. A new command interrupts any ongoing movement.
1424
"""
15-
super().__init__()
25+
super().__init__(**kwargs)
1626
self.serial_number = serial_number
1727
self.speed = speed
1828
self.force = force

extensions/rcs_so101/src/rcs_so101/creators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ def __call__( # type: ignore
3636
)
3737
robot = SO101(cfg=robot_cfg, ik=ik)
3838
env: gym.Env = HardwareEnv()
39-
env = RobotWrapper(env, robot, control_mode, home_on_reset=True)
39+
env = RobotWrapper(env, robot, control_mode)
4040

4141
gripper = SO101Gripper(robot._hf_robot, robot)
42-
env = GripperWrapper(env, gripper, binary=False)
42+
env = GripperWrapper(env, gripper)
4343

4444
if camera_set is not None:
4545
camera_set.start()

extensions/rcs_so101/src/rcs_so101/hw.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,17 @@ def __init__(self, hf_robot: SO101Follower, robot: SO101):
188188
super().__init__()
189189
self._hf_robot = hf_robot
190190
self._robot = robot
191+
self._cfg = common.GripperConfig(binary=False)
191192

192193
def get_normalized_width(self) -> float:
193194
obs = self._robot.obs
194195
if obs is None:
195196
return 0.0
196197
return obs["gripper.pos"] / 100.0
197198

198-
# def get_config(self) -> GripperConfig: ...
199+
def get_config(self) -> common.GripperConfig:
200+
return self._cfg
201+
199202
# def get_state(self) -> GripperState: ...
200203

201204
def grasp(self) -> None:

extensions/rcs_ur5e/src/rcs_ur5e/creators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ def __call__( # type: ignore
3838
)
3939
robot = UR5e(robot_cfg, ik)
4040
env: gym.Env = HardwareEnv()
41-
env = RobotWrapper(env, robot, control_mode, home_on_reset=True)
41+
env = RobotWrapper(env, robot, control_mode)
4242

4343
if gripper_cfg is not None:
4444
gripper = RobotiQGripper(cfg=gripper_cfg)
4545
# TODO: binary and other things of the wrappers should also be in the config
46-
env = GripperWrapper(env, gripper, binary=True)
46+
env = GripperWrapper(env, gripper)
4747

4848
if camera_set is not None:
4949
camera_set.start()

extensions/rcs_ur5e/src/rcs_ur5e/hw.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import numpy as np
1212
import rtde_control
1313
import rtde_receive
14-
from rcs.common_typing import RobotConfigKwargs
14+
from rcs.common_typing import GripperConfigKwargs, RobotConfigKwargs
1515
from rcs_ur5e import robotiq_gripper
1616

1717
from rcs import common
@@ -64,8 +64,8 @@ def from_dict(self, data: dict[str, typing.Any]) -> None:
6464

6565

6666
class RobotiQGripperConfig(common.GripperConfig):
67-
def __init__(self, ip: str):
68-
super().__init__()
67+
def __init__(self, ip: str, **kwargs: typing.Unpack[GripperConfigKwargs]) -> None:
68+
super().__init__(**kwargs)
6969
self.ip = ip
7070

7171

@@ -326,6 +326,7 @@ def reset(self) -> None:
326326
class RobotiQGripper(common.Gripper):
327327
def __init__(self, cfg: RobotiQGripperConfig):
328328
super().__init__()
329+
self._cfg = cfg
329330
self.gripper = robotiq_gripper.RobotiqGripper()
330331
try:
331332
self.gripper.connect(cfg.ip, 63352, socket_timeout=3.0) # default port for Robotiq gripper
@@ -336,6 +337,9 @@ def __init__(self, cfg: RobotiQGripperConfig):
336337
self.gripper.activate()
337338
print("Gripper Connection established.")
338339

340+
def get_config(self) -> RobotiQGripperConfig:
341+
return self._cfg
342+
339343
def get_normalized_width(self) -> float:
340344
# value between 0 and 1 (0 is closed)
341345
return (self.gripper.get_max_position() - self.gripper.get_current_position()) / self.gripper.get_max_position()

extensions/rcs_xarm7/src/rcs_xarm7/creators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __call__( # type: ignore
4444
)
4545
robot = XArm7(cfg=robot_cfg, ik=ik)
4646
env: gym.Env = HardwareEnv()
47-
env = RobotWrapper(env, robot, control_mode, home_on_reset=True)
47+
env = RobotWrapper(env, robot, control_mode)
4848

4949
if camera_set is not None:
5050
camera_set.start()

0 commit comments

Comments
 (0)