|
| 1 | +# Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | + |
| 5 | +from __future__ import annotations |
| 6 | + |
| 7 | +from collections.abc import Callable |
| 8 | + |
| 9 | +import isaaclab.envs.mdp as mdp_isaac_lab |
| 10 | +import isaaclab.sim as sim_utils |
| 11 | +from isaaclab.managers import EventTermCfg as EventTerm |
| 12 | +from isaaclab.managers import ObservationGroupCfg as ObsGroup |
| 13 | +from isaaclab.managers import ObservationTermCfg as ObsTerm |
| 14 | +from isaaclab.managers import SceneEntityCfg |
| 15 | +from isaaclab.sensors import CameraCfg |
| 16 | +from isaaclab.utils.configclass import configclass |
| 17 | +from isaaclab_arena.assets.register import register_asset, register_retargeter |
| 18 | +from isaaclab_arena.assets.retargeter_library import RetargetterBase |
| 19 | +from isaaclab_arena.embodiments.common.arm_mode import ArmMode |
| 20 | +from isaaclab_arena.embodiments.franka.franka import FrankaIKEmbodiment |
| 21 | +from isaaclab_arena.utils.cameras import ArenaCameraCfg |
| 22 | +from isaaclab_arena.utils.pose import Pose |
| 23 | +from isaaclab_physx.renderers import IsaacRtxRendererCfg, IsaacRtxRendererGlobalSettingsCfg |
| 24 | + |
| 25 | +from . import mdp |
| 26 | + |
| 27 | +_FRANKA_ROPE_INIT_JOINT_POS: dict[str, float] = { |
| 28 | + "panda_joint1": 0.0444, |
| 29 | + "panda_joint2": -0.1894, |
| 30 | + "panda_joint3": -0.1107, |
| 31 | + "panda_joint4": -2.5148, |
| 32 | + "panda_joint5": 0.0044, |
| 33 | + "panda_joint6": 2.3775, |
| 34 | + "panda_joint7": 2.43, |
| 35 | + "panda_finger_joint.*": 0.04, |
| 36 | +} |
| 37 | + |
| 38 | +_FRANKA_ROPE_INIT_JOINT_POSE = [ |
| 39 | + 0.0444, |
| 40 | + -0.1894, |
| 41 | + -0.1107, |
| 42 | + -2.5148, |
| 43 | + 0.0044, |
| 44 | + 2.3775, |
| 45 | + 2.43, |
| 46 | + 0.04, |
| 47 | + 0.04, |
| 48 | +] |
| 49 | + |
| 50 | + |
| 51 | +@configclass |
| 52 | +class FrankaRopeCameraCfg(ArenaCameraCfg): |
| 53 | + """Wrist and fixed-view cameras matching the Isaac Lab rope environment.""" |
| 54 | + |
| 55 | + robot0_eye_in_hand_image = CameraCfg( |
| 56 | + prim_path="{ENV_REGEX_NS}/Robot/panda_hand/robot0_eye_in_hand_image", |
| 57 | + update_period=0.0, |
| 58 | + height=128, |
| 59 | + width=128, |
| 60 | + data_types=["rgb"], |
| 61 | + renderer_cfg=IsaacRtxRendererCfg(global_settings=IsaacRtxRendererGlobalSettingsCfg(antialiasing_mode="DLSS")), |
| 62 | + spawn=sim_utils.PinholeCameraCfg( |
| 63 | + focal_length=24.0, |
| 64 | + focus_distance=400.0, |
| 65 | + horizontal_aperture=20.955, |
| 66 | + clipping_range=(0.1, 2.0), |
| 67 | + ), |
| 68 | + offset=CameraCfg.OffsetCfg( |
| 69 | + pos=(0.13, 0.0, -0.15), |
| 70 | + rot=(0.03701, 0.03701, -0.70614, -0.70614), |
| 71 | + convention="ros", |
| 72 | + ), |
| 73 | + ) |
| 74 | + |
| 75 | + agentview_image = CameraCfg( |
| 76 | + prim_path="{ENV_REGEX_NS}/agentview_image", |
| 77 | + update_period=0.0, |
| 78 | + height=128, |
| 79 | + width=128, |
| 80 | + data_types=["rgb"], |
| 81 | + renderer_cfg=IsaacRtxRendererCfg(global_settings=IsaacRtxRendererGlobalSettingsCfg(antialiasing_mode="DLSS")), |
| 82 | + spawn=sim_utils.PinholeCameraCfg( |
| 83 | + focal_length=14.0, |
| 84 | + focus_distance=400.0, |
| 85 | + horizontal_aperture=20.955, |
| 86 | + clipping_range=(0.1, 2.0), |
| 87 | + ), |
| 88 | + offset=CameraCfg.OffsetCfg( |
| 89 | + pos=(0.5, 0.5, 0.4), |
| 90 | + rot=(0.0, 0.38268, 0.92388, 0.0), |
| 91 | + convention="opengl", |
| 92 | + ), |
| 93 | + ) |
| 94 | + |
| 95 | + |
| 96 | +@configclass |
| 97 | +class FrankaRopeObservationsCfg: |
| 98 | + """Arena-standard Franka observations plus deformable rope nodal state.""" |
| 99 | + |
| 100 | + @configclass |
| 101 | + class PolicyCfg(ObsGroup): |
| 102 | + """Policy observations recorded into demonstration datasets.""" |
| 103 | + |
| 104 | + actions = ObsTerm(func=mdp_isaac_lab.last_action) |
| 105 | + joint_pos = ObsTerm(func=mdp_isaac_lab.joint_pos_rel) |
| 106 | + joint_vel = ObsTerm(func=mdp_isaac_lab.joint_vel_rel) |
| 107 | + eef_pos = ObsTerm(func=mdp.ee_frame_pos) |
| 108 | + eef_quat = ObsTerm(func=mdp.ee_frame_quat) |
| 109 | + gripper_pos = ObsTerm( |
| 110 | + func=mdp.gripper_pos, |
| 111 | + params={"robot_cfg": SceneEntityCfg("robot", joint_names=["panda_finger_joint.*"])}, |
| 112 | + ) |
| 113 | + object_nodal_pos = ObsTerm(func=mdp.object_nodal_pos) |
| 114 | + |
| 115 | + def __post_init__(self) -> None: |
| 116 | + self.enable_corruption = False |
| 117 | + self.concatenate_terms = False |
| 118 | + |
| 119 | + policy: PolicyCfg = PolicyCfg() |
| 120 | + |
| 121 | + |
| 122 | +@configclass |
| 123 | +class FrankaRopeEventsCfg: |
| 124 | + """Reset the Franka exactly as the equivalent Isaac Lab rope environment.""" |
| 125 | + |
| 126 | + reset_all = EventTerm(func=mdp_isaac_lab.reset_scene_to_default, mode="reset") |
| 127 | + randomize_franka_joint_state = EventTerm( |
| 128 | + func=mdp_isaac_lab.reset_joints_by_offset, |
| 129 | + mode="reset", |
| 130 | + params={ |
| 131 | + "position_range": (-0.02, 0.02), |
| 132 | + "velocity_range": (0.0, 0.0), |
| 133 | + "asset_cfg": SceneEntityCfg("robot", joint_names=["panda_joint.*"]), |
| 134 | + }, |
| 135 | + ) |
| 136 | + |
| 137 | + |
| 138 | +@register_asset |
| 139 | +class FrankaRopeIKEmbodiment(FrankaIKEmbodiment): |
| 140 | + """Arena Franka IK embodiment with rope-specific pose, observations, and cameras.""" |
| 141 | + |
| 142 | + name = "franka_rope_ik" |
| 143 | + |
| 144 | + def __init__( |
| 145 | + self, |
| 146 | + enable_cameras: bool = False, |
| 147 | + initial_pose: Pose | None = None, |
| 148 | + concatenate_observation_terms: bool = False, |
| 149 | + arm_mode: ArmMode | None = None, |
| 150 | + ) -> None: |
| 151 | + super().__init__( |
| 152 | + enable_cameras=enable_cameras, |
| 153 | + initial_pose=initial_pose, |
| 154 | + initial_joint_pose=list(_FRANKA_ROPE_INIT_JOINT_POSE), |
| 155 | + concatenate_observation_terms=concatenate_observation_terms, |
| 156 | + arm_mode=arm_mode, |
| 157 | + ) |
| 158 | + self.scene_config.robot.init_state.joint_pos = dict(_FRANKA_ROPE_INIT_JOINT_POS) |
| 159 | + self.observation_config = FrankaRopeObservationsCfg() |
| 160 | + self.observation_config.policy.concatenate_terms = concatenate_observation_terms |
| 161 | + self.camera_config = FrankaRopeCameraCfg() |
| 162 | + self.event_config = FrankaRopeEventsCfg() |
| 163 | + self.reward_config = None |
| 164 | + |
| 165 | + |
| 166 | +@register_retargeter |
| 167 | +class FrankaRopeKeyboardRetargeter(RetargetterBase): |
| 168 | + """Use the standard relative-pose keyboard pipeline for the rope embodiment.""" |
| 169 | + |
| 170 | + device = "keyboard" |
| 171 | + embodiment = FrankaRopeIKEmbodiment.name |
| 172 | + |
| 173 | + def get_pipeline_builder(self, embodiment: object) -> Callable | None: |
| 174 | + """Return no custom pipeline; Isaac Lab handles relative-pose keyboard input.""" |
| 175 | + |
| 176 | + del embodiment |
| 177 | + |
| 178 | + |
| 179 | +@register_retargeter |
| 180 | +class FrankaRopeSpaceMouseRetargeter(RetargetterBase): |
| 181 | + """Use the standard relative-pose SpaceMouse pipeline for the rope embodiment.""" |
| 182 | + |
| 183 | + device = "spacemouse" |
| 184 | + embodiment = FrankaRopeIKEmbodiment.name |
| 185 | + |
| 186 | + def get_pipeline_builder(self, embodiment: object) -> Callable | None: |
| 187 | + """Return no custom pipeline; Isaac Lab handles relative-pose SpaceMouse input.""" |
| 188 | + |
| 189 | + del embodiment |
0 commit comments