-
Notifications
You must be signed in to change notification settings - Fork 8
Draft: Add grasp annotator #196
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,6 +34,11 @@ | |||||||||||||||||||||||||||||||||||||||||
| from embodichain.utils.math import convert_quat | ||||||||||||||||||||||||||||||||||||||||||
| from embodichain.utils.math import matrix_from_quat, quat_from_matrix, matrix_from_euler | ||||||||||||||||||||||||||||||||||||||||||
| from embodichain.utils import logger | ||||||||||||||||||||||||||||||||||||||||||
| from embodichain.toolkits.graspkit.pg_grasp.antipodal_annotator import ( | ||||||||||||||||||||||||||||||||||||||||||
| GraspAnnotator, | ||||||||||||||||||||||||||||||||||||||||||
| GraspAnnotatorCfg, | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
| import torch.nn.functional as F | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @dataclass | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1108,3 +1113,65 @@ def destroy(self) -> None: | |||||||||||||||||||||||||||||||||||||||||
| arenas = [env] | ||||||||||||||||||||||||||||||||||||||||||
| for i, entity in enumerate(self._entities): | ||||||||||||||||||||||||||||||||||||||||||
| arenas[i].remove_actor(entity) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| def get_grasp_pose( | ||||||||||||||||||||||||||||||||||||||||||
| self, | ||||||||||||||||||||||||||||||||||||||||||
| cfg: GraspAnnotatorCfg, | ||||||||||||||||||||||||||||||||||||||||||
| approach_direction: torch.Tensor = None, | ||||||||||||||||||||||||||||||||||||||||||
| is_visual: bool = False, | ||||||||||||||||||||||||||||||||||||||||||
| ) -> torch.Tensor: | ||||||||||||||||||||||||||||||||||||||||||
| if approach_direction is None: | ||||||||||||||||||||||||||||||||||||||||||
| approach_direction = torch.tensor( | ||||||||||||||||||||||||||||||||||||||||||
| [0, 0, -1], dtype=torch.float32, device=self.device | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
| approach_direction = F.normalize(approach_direction, dim=-1) | ||||||||||||||||||||||||||||||||||||||||||
| if hasattr(self, "_grasp_annotator") is False: | ||||||||||||||||||||||||||||||||||||||||||
| self._grasp_annotator = GraspAnnotator(cfg=cfg) | ||||||||||||||||||||||||||||||||||||||||||
| if hasattr(self, "_hit_point_pairs") is False or cfg.force_regenerate: | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1128
to
+1130
|
||||||||||||||||||||||||||||||||||||||||||
| if hasattr(self, "_grasp_annotator") is False: | |
| self._grasp_annotator = GraspAnnotator(cfg=cfg) | |
| if hasattr(self, "_hit_point_pairs") is False or cfg.force_regenerate: | |
| # (Re)create grasp annotator if it does not exist yet or if the | |
| # configuration has changed since the last call. | |
| annotator_needs_update = ( | |
| not hasattr(self, "_grasp_annotator") | |
| or not hasattr(self, "_grasp_annotator_cfg") | |
| or self._grasp_annotator_cfg != cfg | |
| ) | |
| if annotator_needs_update: | |
| self._grasp_annotator = GraspAnnotator(cfg=cfg) | |
| self._grasp_annotator_cfg = cfg | |
| # Invalidate cached hit point pairs so they will be regenerated | |
| # with the new annotator / configuration. | |
| if hasattr(self, "_hit_point_pairs"): | |
| del self._hit_point_pairs | |
| if not hasattr(self, "_hit_point_pairs") or cfg.force_regenerate: |
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.
RigidObjectnow importsGraspAnnotator(and its dependencies likeviser/trimesh/open3d) at module import time. This makes the core sim objects package depend on optional UI/geometry libraries and can break environments that don’t have those extras installed, even if grasp annotation isn’t used. Consider moving these imports insideget_grasp_pose()and raising a clear, actionable error if the optional deps are missing.