Skip to content

Commit 74e5b00

Browse files
committed
Fix: more precise grasp in grasp_demo.py
1 parent d88051b commit 74e5b00

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

examples/fr3/grasp_demo.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ def approach(self, geom_name: str):
6161

6262
def grasp(self, geom_name: str):
6363

64-
waypoints = self.plan_linear_motion(geom_name=geom_name, delta_up=0.01, num_waypoints=60)
64+
waypoints = self.plan_linear_motion(geom_name=geom_name, delta_up=-0.005, num_waypoints=60)
6565
self.execute_motion(waypoints=waypoints, gripper=GripperWrapper.BINARY_GRIPPER_OPEN)
6666

67-
self.step(self._action(Pose(), GripperWrapper.BINARY_GRIPPER_CLOSED))
67+
for _ in range(4):
68+
self.step(self._action(self.unwrapped.robot.get_cartesian_position(), GripperWrapper.BINARY_GRIPPER_CLOSED))
6869

6970
waypoints = self.plan_linear_motion(geom_name=geom_name, delta_up=0.2, num_waypoints=60)
7071
self.execute_motion(waypoints=waypoints, gripper=GripperWrapper.BINARY_GRIPPER_CLOSED)

python/rcs/envs/base.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,9 @@ def get_obs(self) -> ArmObsType:
255255
def step(self, action: CartOrJointContType) -> tuple[ArmObsType, float, bool, bool, dict]:
256256
action_dict = cast(dict, action)
257257
if (
258-
self.get_base_control_mode() == ControlMode.CARTESIAN_TQuat
259-
and self.tquat_key not in action_dict
260-
or self.get_base_control_mode() == ControlMode.CARTESIAN_TRPY
261-
and self.trpy_key not in action_dict
262-
or self.get_base_control_mode() == ControlMode.JOINTS
263-
and self.joints_key not in action_dict
258+
(self.get_base_control_mode() == ControlMode.CARTESIAN_TQuat and self.tquat_key not in action_dict)
259+
or (self.get_base_control_mode() == ControlMode.CARTESIAN_TRPY and self.trpy_key not in action_dict)
260+
or (self.get_base_control_mode() == ControlMode.JOINTS and self.joints_key not in action_dict)
264261
):
265262
msg = "Given type is not matching control mode!"
266263
raise RuntimeError(msg)
@@ -336,8 +333,8 @@ def reset(
336333
obs = {}
337334
info = {}
338335

339-
seed_ = seed if seed is not None else {key: None for key in self.envs} # type: ignore
340-
options_ = options if options is not None else {key: None for key in self.envs} # type: ignore
336+
seed_ = seed if seed is not None else dict.fromkeys(self.envs) # type: ignore
337+
options_ = options if options is not None else dict.fromkeys(self.envs) # type: ignore
341338
for key, env in self.envs.items():
342339
obs[key], info[key] = env.reset(seed=seed_[key], options=options_[key])
343340
return obs, info
@@ -459,8 +456,10 @@ def set_origin_to_current(self):
459456
else:
460457
self._origin = self.unwrapped.robot.get_cartesian_position()
461458

462-
def reset(self, **kwargs) -> tuple[dict, dict[str, Any]]:
463-
obs, info = super().reset(**kwargs)
459+
def reset(
460+
self, *, seed: int | None = None, options: dict[str, Any] | None = None
461+
) -> tuple[dict[str, Any], dict[str, Any]]:
462+
obs, info = super().reset(seed=seed, options=options)
464463
self.initial_obs = obs
465464
self.set_origin_to_current()
466465
self._last_action = None
@@ -629,7 +628,9 @@ def __init__(self, env, camera_set: BaseCameraSet, include_depth: bool = False):
629628
)
630629
self.camera_key = get_space_keys(CameraDictType)[0]
631630

632-
def reset(self, seed: int | None = None, options: dict[str, Any] | None = None) -> tuple[dict, dict[str, Any]]:
631+
def reset(
632+
self, *, seed: int | None = None, options: dict[str, Any] | None = None
633+
) -> tuple[dict[str, Any], dict[str, Any]]:
633634
self.camera_set.clear_buffer()
634635
return super().reset(seed=seed, options=options)
635636

python/rcs/envs/sim.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,12 @@ def step(self, action: dict[str, Any]) -> tuple[dict[str, Any], float, bool, boo
104104
return obs, 0.0, False, bool(truncated), info
105105

106106
def reset(
107-
self, seed: dict[str, int | None] | None = None, options: dict[str, Any] | None = None # type: ignore
107+
self,
108+
seed: dict[str, int | None] | None = None,
109+
options: dict[str, Any] | None = None, # type: ignore
108110
) -> tuple[dict[str, Any], dict[str, Any]]:
109111
if seed is None:
110-
seed = {key: None for key in self.env.envs}
112+
seed = dict.fromkeys(self.env.envs)
111113
if options is None:
112114
options = {key: {} for key in self.env.envs}
113115
obs = {}
@@ -196,7 +198,6 @@ def __init__(
196198
self.sim.open_gui()
197199

198200
def step(self, action: dict[str, Any]) -> tuple[dict[str, Any], SupportsFloat, bool, bool, dict[str, Any]]:
199-
200201
self.collision_env.get_wrapper_attr("robot").set_joints_hard(self.unwrapped.robot.get_joint_position())
201202
_, _, _, _, info = self.collision_env.step(action)
202203

@@ -219,7 +220,7 @@ def step(self, action: dict[str, Any]) -> tuple[dict[str, Any], SupportsFloat, b
219220
return obs, reward, done, truncated, info
220221

221222
def reset(
222-
self, seed: int | None = None, options: dict[str, Any] | None = None
223+
self, *, seed: int | None = None, options: dict[str, Any] | None = None
223224
) -> tuple[dict[str, Any], dict[str, Any]]:
224225
# check if move to home is collision free
225226
if self.check_home_collision:
@@ -333,7 +334,7 @@ def __init__(
333334
self.y_offset = y_offset
334335

335336
def reset(
336-
self, seed: int | None = None, options: dict[str, Any] | None = None
337+
self, *, seed: int | None = None, options: dict[str, Any] | None = None
337338
) -> tuple[dict[str, Any], dict[str, Any]]:
338339
if options is not None and "RandomObjectPos.init_object_pose" in options:
339340
assert isinstance(
@@ -381,7 +382,7 @@ def __init__(self, env: gym.Env, simulation: sim.Sim, include_rotation: bool = F
381382
self.cube_joint_name = cube_joint_name
382383

383384
def reset(
384-
self, seed: int | None = None, options: dict[str, Any] | None = None
385+
self, *, seed: int | None = None, options: dict[str, Any] | None = None
385386
) -> tuple[dict[str, Any], dict[str, Any]]:
386387
obs, info = super().reset(seed=seed, options=options)
387388
self.sim.step(1)
@@ -456,11 +457,7 @@ def step(self, action: dict[str, Any]):
456457
reward /= 3 # type: ignore
457458
return obs, reward, success, truncated, info
458459

459-
def reset(
460-
self,
461-
seed: dict[str, int | None] | None = None,
462-
options: dict[str, Any] | None = None, # type: ignore
463-
):
460+
def reset(self, *, seed: int | None = None, options: dict[str, Any] | None = None):
464461
obs, info = super().reset()
465462
self.home_pose = self.unwrapped.robot.get_cartesian_position()
466463
return obs, info

0 commit comments

Comments
 (0)