Skip to content

Commit cd73f95

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

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

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/sim.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ def step(self, action: dict[str, Any]) -> tuple[dict[str, Any], float, bool, boo
103103
truncated = np.all([info[key]["collision"] or info[key]["ik_success"] for key in info])
104104
return obs, 0.0, False, bool(truncated), info
105105

106-
def reset(
107-
self, seed: dict[str, int | None] | None = None, options: dict[str, Any] | None = None # type: ignore
106+
def reset( # type: ignore
107+
self, *, seed: dict[str, int | None] | None = None, options: dict[str, Any] | None = None
108108
) -> tuple[dict[str, Any], dict[str, Any]]:
109109
if seed is None:
110-
seed = {key: None for key in self.env.envs}
110+
seed = dict.fromkeys(self.env.envs)
111111
if options is None:
112112
options = {key: {} for key in self.env.envs}
113113
obs = {}
@@ -196,7 +196,6 @@ def __init__(
196196
self.sim.open_gui()
197197

198198
def step(self, action: dict[str, Any]) -> tuple[dict[str, Any], SupportsFloat, bool, bool, dict[str, Any]]:
199-
200199
self.collision_env.get_wrapper_attr("robot").set_joints_hard(self.unwrapped.robot.get_joint_position())
201200
_, _, _, _, info = self.collision_env.step(action)
202201

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

221220
def reset(
222-
self, seed: int | None = None, options: dict[str, Any] | None = None
221+
self, *, seed: int | None = None, options: dict[str, Any] | None = None
223222
) -> tuple[dict[str, Any], dict[str, Any]]:
224223
# check if move to home is collision free
225224
if self.check_home_collision:
@@ -333,7 +332,7 @@ def __init__(
333332
self.y_offset = y_offset
334333

335334
def reset(
336-
self, seed: int | None = None, options: dict[str, Any] | None = None
335+
self, *, seed: int | None = None, options: dict[str, Any] | None = None
337336
) -> tuple[dict[str, Any], dict[str, Any]]:
338337
if options is not None and "RandomObjectPos.init_object_pose" in options:
339338
assert isinstance(
@@ -381,7 +380,7 @@ def __init__(self, env: gym.Env, simulation: sim.Sim, include_rotation: bool = F
381380
self.cube_joint_name = cube_joint_name
382381

383382
def reset(
384-
self, seed: int | None = None, options: dict[str, Any] | None = None
383+
self, *, seed: int | None = None, options: dict[str, Any] | None = None
385384
) -> tuple[dict[str, Any], dict[str, Any]]:
386385
obs, info = super().reset(seed=seed, options=options)
387386
self.sim.step(1)
@@ -456,11 +455,7 @@ def step(self, action: dict[str, Any]):
456455
reward /= 3 # type: ignore
457456
return obs, reward, success, truncated, info
458457

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

0 commit comments

Comments
 (0)