-
Notifications
You must be signed in to change notification settings - Fork 81
Add Franka soft lift scene #978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
TuurStuyck
wants to merge
2
commits into
tstuyck/feature/deformable-pick-place
Choose a base branch
from
tstuyck/feature/franka-soft-lift
base: tstuyck/feature/deformable-pick-place
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #usda 1.0 | ||
| ( | ||
| defaultPrim = "FrankaSoftLiftBlock" | ||
| metersPerUnit = 1 | ||
| upAxis = "Z" | ||
| ) | ||
|
|
||
| def Xform "FrankaSoftLiftBlock" | ||
| { | ||
| def TetMesh "sim_mesh" | ||
| { | ||
| point3f[] points = [(-0.15, -0.025, -0.025), (-0.15, -0.025, 0.025), (-0.15, 0.025, -0.025), (-0.15, 0.025, 0.025), (-0.13, -0.025, -0.025), (-0.13, -0.025, 0.025), (-0.13, 0.025, -0.025), (-0.13, 0.025, 0.025), (-0.11, -0.025, -0.025), (-0.11, -0.025, 0.025), (-0.11, 0.025, -0.025), (-0.11, 0.025, 0.025), (-0.09, -0.025, -0.025), (-0.09, -0.025, 0.025), (-0.09, 0.025, -0.025), (-0.09, 0.025, 0.025), (-0.07, -0.025, -0.025), (-0.07, -0.025, 0.025), (-0.07, 0.025, -0.025), (-0.07, 0.025, 0.025), (-0.05, -0.025, -0.025), (-0.05, -0.025, 0.025), (-0.05, 0.025, -0.025), (-0.05, 0.025, 0.025), (-0.03, -0.025, -0.025), (-0.03, -0.025, 0.025), (-0.03, 0.025, -0.025), (-0.03, 0.025, 0.025), (-0.01, -0.025, -0.025), (-0.01, -0.025, 0.025), (-0.01, 0.025, -0.025), (-0.01, 0.025, 0.025), (0.01, -0.025, -0.025), (0.01, -0.025, 0.025), (0.01, 0.025, -0.025), (0.01, 0.025, 0.025), (0.03, -0.025, -0.025), (0.03, -0.025, 0.025), (0.03, 0.025, -0.025), (0.03, 0.025, 0.025), (0.05, -0.025, -0.025), (0.05, -0.025, 0.025), (0.05, 0.025, -0.025), (0.05, 0.025, 0.025), (0.07, -0.025, -0.025), (0.07, -0.025, 0.025), (0.07, 0.025, -0.025), (0.07, 0.025, 0.025), (0.09, -0.025, -0.025), (0.09, -0.025, 0.025), (0.09, 0.025, -0.025), (0.09, 0.025, 0.025), (0.11, -0.025, -0.025), (0.11, -0.025, 0.025), (0.11, 0.025, -0.025), (0.11, 0.025, 0.025), (0.13, -0.025, -0.025), (0.13, -0.025, 0.025), (0.13, 0.025, -0.025), (0.13, 0.025, 0.025), (0.15, -0.025, -0.025), (0.15, -0.025, 0.025), (0.15, 0.025, -0.025), (0.15, 0.025, 0.025)] | ||
| int4[] tetVertexIndices = [(0, 1, 7, 3), (0, 3, 7, 2), (0, 2, 7, 6), (0, 6, 7, 4), (0, 4, 7, 5), (0, 5, 7, 1), (4, 5, 11, 7), (4, 7, 11, 6), (4, 6, 11, 10), (4, 10, 11, 8), (4, 8, 11, 9), (4, 9, 11, 5), (8, 9, 15, 11), (8, 11, 15, 10), (8, 10, 15, 14), (8, 14, 15, 12), (8, 12, 15, 13), (8, 13, 15, 9), (12, 13, 19, 15), (12, 15, 19, 14), (12, 14, 19, 18), (12, 18, 19, 16), (12, 16, 19, 17), (12, 17, 19, 13), (16, 17, 23, 19), (16, 19, 23, 18), (16, 18, 23, 22), (16, 22, 23, 20), (16, 20, 23, 21), (16, 21, 23, 17), (20, 21, 27, 23), (20, 23, 27, 22), (20, 22, 27, 26), (20, 26, 27, 24), (20, 24, 27, 25), (20, 25, 27, 21), (24, 25, 31, 27), (24, 27, 31, 26), (24, 26, 31, 30), (24, 30, 31, 28), (24, 28, 31, 29), (24, 29, 31, 25), (28, 29, 35, 31), (28, 31, 35, 30), (28, 30, 35, 34), (28, 34, 35, 32), (28, 32, 35, 33), (28, 33, 35, 29), (32, 33, 39, 35), (32, 35, 39, 34), (32, 34, 39, 38), (32, 38, 39, 36), (32, 36, 39, 37), (32, 37, 39, 33), (36, 37, 43, 39), (36, 39, 43, 38), (36, 38, 43, 42), (36, 42, 43, 40), (36, 40, 43, 41), (36, 41, 43, 37), (40, 41, 47, 43), (40, 43, 47, 42), (40, 42, 47, 46), (40, 46, 47, 44), (40, 44, 47, 45), (40, 45, 47, 41), (44, 45, 51, 47), (44, 47, 51, 46), (44, 46, 51, 50), (44, 50, 51, 48), (44, 48, 51, 49), (44, 49, 51, 45), (48, 49, 55, 51), (48, 51, 55, 50), (48, 50, 55, 54), (48, 54, 55, 52), (48, 52, 55, 53), (48, 53, 55, 49), (52, 53, 59, 55), (52, 55, 59, 54), (52, 54, 59, 58), (52, 58, 59, 56), (52, 56, 59, 57), (52, 57, 59, 53), (56, 57, 63, 59), (56, 59, 63, 58), (56, 58, 63, 62), (56, 62, 63, 60), (56, 60, 63, 61), (56, 61, 63, 57)] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| # Copyright (c) 2026, The Isaac Lab Arena Project Developers (https://github.com/isaac-sim/IsaacLab-Arena/blob/main/CONTRIBUTORS.md). | ||
| # All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Goal-reached metric for deformable lift evaluation.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import numpy as np | ||
| import torch | ||
|
|
||
| import warp as wp | ||
| from isaaclab.envs.manager_based_rl_env import ManagerBasedEnv | ||
| from isaaclab.managers import SceneEntityCfg | ||
| from isaaclab.managers.recorder_manager import RecorderTerm, RecorderTermCfg | ||
| from isaaclab.utils.configclass import configclass | ||
| from isaaclab.utils.math import combine_frame_transforms | ||
|
|
||
| from isaaclab_arena.metrics.metric_base import MetricBase | ||
| from isaaclab_arena.metrics.metric_term_cfg import MetricTermCfg | ||
|
|
||
|
|
||
| def _deformable_goal_reached( | ||
| env: ManagerBasedEnv, | ||
| *, | ||
| command_name: str, | ||
| minimal_height: float, | ||
| position_tolerance: float, | ||
| robot_cfg: SceneEntityCfg, | ||
| asset_cfg: SceneEntityCfg, | ||
| ) -> torch.Tensor: | ||
| robot = env.scene[robot_cfg.name] | ||
| asset = env.scene[asset_cfg.name] | ||
| command = env.command_manager.get_command(command_name) | ||
| desired_pos_b = command[:, :3] | ||
| desired_pos_w, _ = combine_frame_transforms( | ||
| wp.to_torch(robot.data.root_pos_w), | ||
| wp.to_torch(robot.data.root_quat_w), | ||
| desired_pos_b, | ||
| ) | ||
| com_w = wp.to_torch(asset.data.root_pos_w) | ||
| distance = torch.linalg.norm(desired_pos_w - com_w, dim=1) | ||
| return (com_w[:, 2] > minimal_height) & (distance < position_tolerance) | ||
|
|
||
|
|
||
| class DeformableGoalReachedRecorder(RecorderTerm): | ||
| """Record whether the deformable reached its command goal at any point in the episode.""" | ||
|
|
||
| def __init__(self, cfg: RecorderTermCfg, env: ManagerBasedEnv): | ||
| super().__init__(cfg, env) | ||
| self.name = cfg.name | ||
| self.command_name = cfg.command_name | ||
| self.minimal_height = cfg.minimal_height | ||
| self.position_tolerance = cfg.position_tolerance | ||
| self.robot_cfg = cfg.robot_cfg | ||
| self.asset_cfg = cfg.asset_cfg | ||
| self._ever_reached = torch.zeros(env.num_envs, dtype=torch.bool, device=env.device) | ||
| self._first_reset = True | ||
|
|
||
| def _update_state(self) -> None: | ||
| self._ever_reached |= _deformable_goal_reached( | ||
| self._env, | ||
| command_name=self.command_name, | ||
| minimal_height=self.minimal_height, | ||
| position_tolerance=self.position_tolerance, | ||
| robot_cfg=self.robot_cfg, | ||
| asset_cfg=self.asset_cfg, | ||
| ) | ||
|
|
||
| def record_post_step(self): | ||
| self._update_state() | ||
| return None, None | ||
|
|
||
| def record_pre_reset(self, env_ids): | ||
| if self._first_reset: | ||
| self._first_reset = False | ||
| return None, None | ||
| self._update_state() | ||
| reached = self._ever_reached[env_ids].clone() | ||
| self._ever_reached[env_ids] = False | ||
| return self.name, reached | ||
|
|
||
|
|
||
| @configclass | ||
| class DeformableGoalReachedRecorderCfg(RecorderTermCfg): | ||
| """Recorder config for the deformable goal-reached metric.""" | ||
|
|
||
| class_type: type[RecorderTerm] = DeformableGoalReachedRecorder | ||
| name: str = "deformable_goal_reached" | ||
| command_name: str = "deformable_pose" | ||
| minimal_height: float = 0.075 | ||
| position_tolerance: float = 0.05 | ||
| robot_cfg: SceneEntityCfg = SceneEntityCfg("robot") | ||
| asset_cfg: SceneEntityCfg = SceneEntityCfg("deformable") | ||
|
|
||
|
|
||
| def compute_deformable_goal_reached_rate(recorded_metric_data: list[np.ndarray]) -> float: | ||
| """Compute the fraction of episodes whose deformable reached the commanded goal.""" | ||
| if len(recorded_metric_data) == 0: | ||
| return 0.0 | ||
| goal_reached = np.concatenate([np.asarray(data, dtype=bool).reshape(-1) for data in recorded_metric_data]) | ||
| if goal_reached.size == 0: | ||
| return 0.0 | ||
| return float(np.mean(goal_reached)) | ||
|
|
||
|
|
||
| class DeformableGoalReachedRateMetric(MetricBase): | ||
| """Non-terminating goal-reached rate for deformable lift evaluation.""" | ||
|
|
||
| name = "deformable_goal_reached_rate" | ||
| recorder_term_name = "deformable_goal_reached" | ||
|
|
||
| def __init__( | ||
| self, | ||
| command_name: str = "deformable_pose", | ||
| minimal_height: float = 0.075, | ||
| position_tolerance: float = 0.05, | ||
| robot_cfg: SceneEntityCfg | None = None, | ||
| asset_cfg: SceneEntityCfg | None = None, | ||
| ): | ||
| self.command_name = command_name | ||
| self.minimal_height = minimal_height | ||
| self.position_tolerance = position_tolerance | ||
| self.robot_cfg = robot_cfg if robot_cfg is not None else SceneEntityCfg("robot") | ||
| self.asset_cfg = asset_cfg if asset_cfg is not None else SceneEntityCfg("deformable") | ||
|
|
||
| def get_recorder_term_cfg(self) -> RecorderTermCfg: | ||
| return DeformableGoalReachedRecorderCfg( | ||
| name=self.recorder_term_name, | ||
| command_name=self.command_name, | ||
| minimal_height=self.minimal_height, | ||
| position_tolerance=self.position_tolerance, | ||
| robot_cfg=self.robot_cfg, | ||
| asset_cfg=self.asset_cfg, | ||
| ) | ||
|
|
||
| def get_metric_term_cfg(self) -> MetricTermCfg: | ||
| return MetricTermCfg( | ||
| compute_metric_func=compute_deformable_goal_reached_rate, | ||
| params={}, | ||
| recorder_term_name=self.recorder_term_name, | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔵 One-line docstring would help
_deformable_goal_reachedis the success predicate the whole metric hangs on, but the name doesn't convey what it returns. A short line — e.g."""Return a per-env bool tensor: the deformable COM is aboveminimal_heightand withinposition_toleranceof the commanded goal."""— saves readers from re-deriving the frame math.