Skip to content

Commit 3659a33

Browse files
committed
Share the manager section declarations through term factories
The reorient manager cfgs repeated the same command, reward, and termination declarations per robot with one or two differing scalars. Move the defaults into two term factories and the invariant termination section in reorient_task_base; each variant now declares a small plain section class stating only its deltas (Allegro tolerance 0.2, OpenAI tolerance 0.4 with fall penalty and noisy-EMA action source). The camera manager cfg inherits the sections instead of re-declaring them.
1 parent 1732493 commit 3659a33

4 files changed

Lines changed: 101 additions & 147 deletions

File tree

source/isaaclab_tasks/isaaclab_tasks/core/reorient/config/allegro_hand/allegro_hand_manager_env_cfg.py

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
from isaaclab.managers import EventTermCfg as EventTerm
1212
from isaaclab.managers import ObservationGroupCfg as ObsGroup
1313
from isaaclab.managers import ObservationTermCfg as ObsTerm
14-
from isaaclab.managers import RewardTermCfg as RewTerm
1514
from isaaclab.managers import SceneEntityCfg
16-
from isaaclab.managers import TerminationTermCfg as DoneTerm
1715
from isaaclab.scene import InteractiveSceneCfg
1816
from isaaclab.utils.configclass import configclass
1917

@@ -28,8 +26,9 @@
2826
from isaaclab_tasks.core.reorient.reorient_task_base import (
2927
ALLEGRO_ACTUATED_JOINT_NAMES,
3028
ALLEGRO_FINGERTIP_BODY_NAMES,
31-
GOAL_MARKER_POSITION,
32-
IN_HAND_POS_OFFSET,
29+
ReorientTerminationsCfg,
30+
reorient_goal_command,
31+
reorient_reward_term,
3332
)
3433
from isaaclab_tasks.utils import PresetCfg
3534

@@ -69,18 +68,9 @@ def set_num_envs(self, num_envs: int) -> None:
6968

7069
@configclass
7170
class CommandsCfg:
72-
"""Object pose goal matching the Direct in-hand target."""
73-
74-
object_pose = mdp.ReorientEpisodeCommandCfg(
75-
asset_name="object",
76-
init_pos_offset=IN_HAND_POS_OFFSET,
77-
update_goal_on_success=True,
78-
orientation_success_threshold=0.2,
79-
make_quat_unique=False,
80-
fixed_marker_pos=GOAL_MARKER_POSITION,
81-
goal_pose_visualizer_cfg=GOAL_OBJECT_CFG,
82-
debug_vis=True,
83-
)
71+
"""The reorient goal command with the Allegro marker and tolerance."""
72+
73+
object_pose = reorient_goal_command(orientation_success_threshold=0.2, goal_pose_visualizer_cfg=GOAL_OBJECT_CFG)
8474

8575

8676
@configclass
@@ -231,41 +221,9 @@ class EventCfg:
231221

232222
@configclass
233223
class RewardsCfg:
234-
"""Direct-compatible reward and success accounting."""
235-
236-
reorient = RewTerm(
237-
func=mdp.ReorientReward,
238-
weight=1.0,
239-
params={
240-
"command_name": "object_pose",
241-
"distance_scale": -10.0,
242-
"rotation_scale": 1.0,
243-
"rotation_epsilon": 0.1,
244-
"action_penalty_scale": -0.0002,
245-
"success_tolerance": 0.2,
246-
"success_bonus": 250.0,
247-
"fall_distance": 0.24,
248-
"fall_penalty": 0.0,
249-
"averaging_factor": 0.1,
250-
"success_count_threshold": 1,
251-
"object_cfg": SceneEntityCfg("object"),
252-
},
253-
)
224+
"""The reorient reward with the Allegro success tolerance."""
254225

255-
256-
@configclass
257-
class TerminationsCfg:
258-
"""Termination conditions matching the Direct task."""
259-
260-
object_out_of_reach = DoneTerm(
261-
func=mdp.object_reorientation_out_of_reach,
262-
params={
263-
"threshold": 0.24,
264-
"command_name": "object_pose",
265-
"object_cfg": SceneEntityCfg("object"),
266-
},
267-
)
268-
time_out = DoneTerm(func=mdp.time_out, time_out=True)
226+
reorient = reorient_reward_term(success_tolerance=0.2)
269227

270228

271229
@configclass
@@ -277,7 +235,8 @@ class AllegroCubeEnvCfg(AllegroHandTaskCfgBase, ManagerBasedRLEnvCfg):
277235
actions: ActionsCfg = ActionsCfg()
278236
commands: CommandsCfg = CommandsCfg()
279237
rewards: RewardsCfg = RewardsCfg()
280-
terminations: TerminationsCfg = TerminationsCfg()
238+
# the shared termination section from isaaclab_tasks.core.reorient.reorient_task_base
239+
terminations: ReorientTerminationsCfg = ReorientTerminationsCfg()
281240
events: EventCfg = EventCfg()
282241

283242
enable_domain_randomization: bool = False

source/isaaclab_tasks/isaaclab_tasks/core/reorient/config/shadow_hand/shadow_hand_camera_manager_env_cfg.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@
1818
)
1919
from isaaclab_tasks.core.reorient.config.shadow_hand.shadow_hand_manager_env_cfg import (
2020
ActionsCfg,
21-
CommandsCfg,
2221
EventCfg,
2322
FullStateWithoutActionCfg,
24-
RewardsCfg,
2523
ShadowHandManagerEnvCfg,
26-
TerminationsCfg,
2724
_ShadowHandManagerSceneCfg,
2825
)
2926
from isaaclab_tasks.core.reorient.reorient_task_base import (
@@ -122,9 +119,8 @@ class ShadowHandCameraManagerEnvCfg(ShadowHandManagerEnvCfg):
122119
scene: ShadowHandCameraManagerSceneCfg = ShadowHandCameraManagerSceneCfg()
123120
observations: CameraObservationsCfg = CameraObservationsCfg()
124121
actions: ActionsCfg = ActionsCfg()
125-
commands: CommandsCfg = CommandsCfg()
126-
rewards: RewardsCfg = RewardsCfg()
127-
terminations: TerminationsCfg = TerminationsCfg()
122+
# commands/rewards/terminations are inherited from ShadowHandManagerEnvCfg (the
123+
# shared sections from isaaclab_tasks.core.reorient.reorient_task_base)
128124
events: EventCfg = EventCfg()
129125
feature_extractor: FeatureExtractorCfg = FeatureExtractorCfg()
130126

source/isaaclab_tasks/isaaclab_tasks/core/reorient/config/shadow_hand/shadow_hand_manager_env_cfg.py

Lines changed: 20 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from isaaclab.managers import EventTermCfg as EventTerm
1212
from isaaclab.managers import ObservationGroupCfg as ObsGroup
1313
from isaaclab.managers import ObservationTermCfg as ObsTerm
14-
from isaaclab.managers import RewardTermCfg as RewTerm
1514
from isaaclab.managers import SceneEntityCfg
1615
from isaaclab.managers import TerminationTermCfg as DoneTerm
1716
from isaaclab.scene import InteractiveSceneCfg
@@ -32,10 +31,11 @@
3231
ShadowHandTaskCfgBase,
3332
)
3433
from isaaclab_tasks.core.reorient.reorient_task_base import (
35-
GOAL_MARKER_POSITION,
36-
IN_HAND_POS_OFFSET,
3734
SHADOW_ACTUATED_JOINT_NAMES,
3835
SHADOW_FINGERTIP_BODY_NAMES,
36+
ReorientTerminationsCfg,
37+
reorient_goal_command,
38+
reorient_reward_term,
3939
)
4040
from isaaclab_tasks.utils import PresetCfg
4141

@@ -68,22 +68,6 @@ class ShadowHandManagerSceneCfg(PresetCfg):
6868
default = physx
6969

7070

71-
@configclass
72-
class CommandsCfg:
73-
"""Object pose goal matching the Direct in-hand target."""
74-
75-
object_pose = mdp.ReorientEpisodeCommandCfg(
76-
asset_name="object",
77-
init_pos_offset=IN_HAND_POS_OFFSET,
78-
update_goal_on_success=True,
79-
orientation_success_threshold=0.1,
80-
make_quat_unique=False,
81-
fixed_marker_pos=GOAL_MARKER_POSITION,
82-
goal_pose_visualizer_cfg=GOAL_OBJECT_CFG,
83-
debug_vis=True,
84-
)
85-
86-
8771
@configclass
8872
class ActionsCfg:
8973
"""Twenty actuated Shadow Hand joints."""
@@ -171,42 +155,17 @@ class EventCfg:
171155

172156

173157
@configclass
174-
class RewardsCfg:
175-
"""Direct-compatible reward and success accounting."""
158+
class CommandsCfg:
159+
"""The reorient goal command with the Shadow Hand goal marker."""
176160

177-
reorient = RewTerm(
178-
func=mdp.ReorientReward,
179-
weight=1.0,
180-
params={
181-
"command_name": "object_pose",
182-
"distance_scale": -10.0,
183-
"rotation_scale": 1.0,
184-
"rotation_epsilon": 0.1,
185-
"action_penalty_scale": -0.0002,
186-
"success_tolerance": 0.1,
187-
"success_bonus": 250.0,
188-
"fall_distance": 0.24,
189-
"fall_penalty": 0.0,
190-
"averaging_factor": 0.1,
191-
"success_count_threshold": 1,
192-
"object_cfg": SceneEntityCfg("object"),
193-
},
194-
)
161+
object_pose = reorient_goal_command(goal_pose_visualizer_cfg=GOAL_OBJECT_CFG)
195162

196163

197164
@configclass
198-
class TerminationsCfg:
199-
"""Termination conditions matching the Direct task."""
165+
class RewardsCfg:
166+
"""Direct-compatible reward and success accounting (the factory defaults)."""
200167

201-
object_out_of_reach = DoneTerm(
202-
func=mdp.object_reorientation_out_of_reach,
203-
params={
204-
"threshold": 0.24,
205-
"command_name": "object_pose",
206-
"object_cfg": SceneEntityCfg("object"),
207-
},
208-
)
209-
time_out = DoneTerm(func=mdp.time_out, time_out=True)
168+
reorient = reorient_reward_term()
210169

211170

212171
@configclass
@@ -218,7 +177,8 @@ class ShadowHandManagerEnvCfg(ShadowHandTaskCfgBase, ManagerBasedRLEnvCfg):
218177
actions: ActionsCfg = ActionsCfg()
219178
commands: CommandsCfg = CommandsCfg()
220179
rewards: RewardsCfg = RewardsCfg()
221-
terminations: TerminationsCfg = TerminationsCfg()
180+
# the shared termination section from isaaclab_tasks.core.reorient.reorient_task_base
181+
terminations: ReorientTerminationsCfg = ReorientTerminationsCfg()
222182
events: EventCfg = EventCfg()
223183

224184
def __post_init__(self):
@@ -228,22 +188,6 @@ def __post_init__(self):
228188
self.viewer.eye = (2.0, 2.0, 2.0)
229189

230190

231-
@configclass
232-
class OpenAICommandsCfg:
233-
"""OpenAI goal command with its wider success tolerance."""
234-
235-
object_pose = mdp.ReorientEpisodeCommandCfg(
236-
asset_name="object",
237-
init_pos_offset=IN_HAND_POS_OFFSET,
238-
update_goal_on_success=True,
239-
orientation_success_threshold=0.4,
240-
make_quat_unique=False,
241-
fixed_marker_pos=GOAL_MARKER_POSITION,
242-
goal_pose_visualizer_cfg=GOAL_OBJECT_CFG,
243-
debug_vis=True,
244-
)
245-
246-
247191
@configclass
248192
class OpenAIActionsCfg:
249193
"""OpenAI actions with Direct-compatible EMA and stateful noise."""
@@ -345,29 +289,18 @@ class OpenAIEventCfg(PresetCfg):
345289
default = physx
346290

347291

292+
@configclass
293+
class OpenAICommandsCfg:
294+
"""OpenAI goal command with its wider success tolerance."""
295+
296+
object_pose = reorient_goal_command(orientation_success_threshold=0.4, goal_pose_visualizer_cfg=GOAL_OBJECT_CFG)
297+
298+
348299
@configclass
349300
class OpenAIRewardsCfg:
350-
"""Direct-compatible OpenAI reward and success accounting."""
301+
"""OpenAI reward: wider tolerance, fall penalty, and noisy-EMA action source."""
351302

352-
reorient = RewTerm(
353-
func=mdp.ReorientReward,
354-
weight=1.0,
355-
params={
356-
"command_name": "object_pose",
357-
"distance_scale": -10.0,
358-
"rotation_scale": 1.0,
359-
"rotation_epsilon": 0.1,
360-
"action_penalty_scale": -0.0002,
361-
"success_tolerance": 0.4,
362-
"success_bonus": 250.0,
363-
"fall_distance": 0.24,
364-
"fall_penalty": -50.0,
365-
"averaging_factor": 0.1,
366-
"success_count_threshold": 1,
367-
"action_name": "joint_pos",
368-
"object_cfg": SceneEntityCfg("object"),
369-
},
370-
)
303+
reorient = reorient_reward_term(success_tolerance=0.4, fall_penalty=-50.0, action_name="joint_pos")
371304

372305

373306
@configclass

source/isaaclab_tasks/isaaclab_tasks/core/reorient/reorient_task_base.py

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@
66
"""Structural definitions shared by the reorientation task family.
77
88
Joint/body name lists, marker geometry, and reset-pose offsets consumed by both
9-
the Direct and manager-based variants. Scalar task parameters are defined
10-
per-paradigm in the respective environment configurations, following the
11-
convention of the other core tasks.
9+
the Direct and manager-based variants, plus the manager term factories and the
10+
shared termination section used by the robot-specific manager tasks. The
11+
factory defaults carry the Shadow Hand state-task values; each variant declares
12+
its section class stating only its deltas.
1213
"""
1314

15+
from isaaclab.managers import RewardTermCfg as RewTerm
16+
from isaaclab.managers import SceneEntityCfg
17+
from isaaclab.managers import TerminationTermCfg as DoneTerm
18+
from isaaclab.utils.configclass import configclass
19+
20+
import isaaclab_tasks.core.reorient.mdp as mdp
21+
1422
GOAL_MARKER_POSITION: tuple[float, float, float] = (-0.2, -0.45, 0.68)
1523
"""Fixed goal-marker display position [m], environment frame (state-based tasks)."""
1624

@@ -92,3 +100,61 @@
92100
"robot0_THJ0",
93101
]
94102
"""Shadow Hand actuated joint names, in the Direct task's actuation order."""
103+
104+
105+
def reorient_goal_command(**overrides) -> "mdp.ReorientEpisodeCommandCfg":
106+
"""Build the object-pose goal command with the Direct-parity defaults.
107+
108+
Keyword overrides replace the corresponding command fields; robot-specific
109+
variants declare the goal marker (``goal_pose_visualizer_cfg``) and their
110+
success threshold this way at the declaration site.
111+
"""
112+
return mdp.ReorientEpisodeCommandCfg(
113+
asset_name="object",
114+
init_pos_offset=IN_HAND_POS_OFFSET,
115+
update_goal_on_success=True,
116+
orientation_success_threshold=0.1,
117+
make_quat_unique=False,
118+
fixed_marker_pos=GOAL_MARKER_POSITION,
119+
debug_vis=True,
120+
).replace(**overrides)
121+
122+
123+
def reorient_reward_term(**param_overrides) -> RewTerm:
124+
"""Build the :class:`~isaaclab_tasks.core.reorient.mdp.ReorientReward` term.
125+
126+
The parameter defaults are the Direct-parity values of the Shadow Hand
127+
state task; keyword overrides are merged on top, so variants state only
128+
their deltas at the declaration site.
129+
"""
130+
params = {
131+
"command_name": "object_pose",
132+
"distance_scale": -10.0,
133+
"rotation_scale": 1.0,
134+
"rotation_epsilon": 0.1,
135+
"action_penalty_scale": -0.0002,
136+
"success_tolerance": 0.1,
137+
"success_bonus": 250.0,
138+
"fall_distance": 0.24,
139+
"fall_penalty": 0.0,
140+
"averaging_factor": 0.1,
141+
"success_count_threshold": 1,
142+
"object_cfg": SceneEntityCfg("object"),
143+
}
144+
params.update(param_overrides)
145+
return RewTerm(func=mdp.ReorientReward, weight=1.0, params=params)
146+
147+
148+
@configclass
149+
class ReorientTerminationsCfg:
150+
"""Termination conditions matching the Direct task."""
151+
152+
object_out_of_reach = DoneTerm(
153+
func=mdp.object_reorientation_out_of_reach,
154+
params={
155+
"threshold": 0.24,
156+
"command_name": "object_pose",
157+
"object_cfg": SceneEntityCfg("object"),
158+
},
159+
)
160+
time_out = DoneTerm(func=mdp.time_out, time_out=True)

0 commit comments

Comments
 (0)