Skip to content

Commit 05b49da

Browse files
committed
feat(maniskill): port PegInsertionSide dense reward — 10/10 native dense rewards bitwise
reward staged (reach peg -> grasp -> pre-insert align -> insert) computed from peg/goal/ box-hole poses; matches native compute_dense_reward to float32 eps (5.96e-8). Wired into the shipped peg_insertion_side_native task. All 10 tasks with a native dense reward are now bitwise; all 12 tabletop tasks have bitwise success.
1 parent a6ccd1b commit 05b49da

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

roboverse_pack/tasks/maniskill/_native/rewards.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,21 @@ def pull_cube_tool(
248248
if success:
249249
reward += 5.0
250250
return float(reward)
251+
252+
253+
def peg_insertion_side(*, gripper_to_peg, is_grasped, yz1, yz2, hole_dist, success, normalized=False) -> float:
254+
"""ManiSkill PegInsertionSide-v1 ``compute_dense_reward`` (max 10).
255+
256+
Scalars are computed by the caller from poses (gripper→peg distance; yz1/yz2 = |yz| of peg-head /
257+
peg-center in goal frame; hole_dist = |peg head in box-hole frame|; is_grasped at max_angle=20).
258+
"""
259+
reward = 1.0 - _tanh(4.0 * gripper_to_peg)
260+
reward += 1.0 if is_grasped else 0.0
261+
pre = 3.0 * (1.0 - _tanh(0.5 * (yz1 + yz2) + 4.5 * max(yz1, yz2)))
262+
reward += pre * (1.0 if is_grasped else 0.0)
263+
pre_inserted = yz1 < 0.01 and yz2 < 0.01
264+
insertion = 5.0 * (1.0 - _tanh(5.0 * hole_dist))
265+
reward += insertion * (1.0 if (is_grasped and pre_inserted) else 0.0)
266+
if success:
267+
reward = 10.0
268+
return float(reward / 10.0) if normalized else float(reward)

roboverse_pack/tasks/maniskill/_native/specs.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,30 @@ def _pull_cube_tool_success(task):
323323
return SU.pull_cube_tool(cube_pos=task.obj_pos("cube"), robot_base_pos=task.robot_base_pos())
324324

325325

326+
def _peg_insertion_reward(task):
327+
import numpy as _np
328+
import sapien
329+
330+
box = task.handler.object_ids["box_with_hole_0"].get_pose()
331+
peg = task.handler.object_ids["peg_0"].get_pose()
332+
goal = box * sapien.Pose([-0.10695, 0.0087, 0.0038], [1, 0, 0, 0])
333+
ph = peg * sapien.Pose([0.10695, 0.0, 0.0], [1, 0, 0, 0])
334+
bh = box * sapien.Pose([0.0, 0.0087, 0.0038], [1, 0, 0, 0])
335+
tgt = peg * sapien.Pose([-0.06, 0.0, 0.0], [1, 0, 0, 0])
336+
gtp = float(_np.linalg.norm(task.tcp_pos() - _np.asarray(tgt.p)))
337+
yz1 = float(_np.linalg.norm(_np.asarray((goal.inv() * ph).p)[1:]))
338+
yz2 = float(_np.linalg.norm(_np.asarray((goal.inv() * peg).p)[1:]))
339+
hd = float(_np.linalg.norm(_np.asarray((bh.inv() * ph).p)))
340+
return RW.peg_insertion_side(
341+
gripper_to_peg=gtp,
342+
is_grasped=task.is_grasped("peg_0", max_angle=20),
343+
yz1=yz1,
344+
yz2=yz2,
345+
hole_dist=hd,
346+
success=_peg_insertion_success(task),
347+
)
348+
349+
326350
def _peg_insertion_success(task):
327351
"""ManiSkill PegInsertionSide ``has_peg_inserted``: peg head inside the box hole.
328352
@@ -545,6 +569,7 @@ def _stack_pyramid_success(task):
545569
"success": _moved("peg_0", (-0.0007, -0.0695)),
546570
"orientations": {"box_with_hole_0": [0.6694, 0.0, 0.0, 0.7429], "peg_0": [0.8344, 0.0, 0.0, 0.5511]},
547571
"success_full": _peg_insertion_success,
572+
"reward": _peg_insertion_reward,
548573
},
549574
"plug_charger": {
550575
"gym_id": "PlugCharger-v1",

0 commit comments

Comments
 (0)