-
Notifications
You must be signed in to change notification settings - Fork 15
Fix crashing when no grasp pose found. #232
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
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -583,7 +583,7 @@ def get_grasp_poses( | |||||
| approach_direction: torch.Tensor, | ||||||
| visualize_collision: bool = False, | ||||||
| visualize_pose: bool = False, | ||||||
| ) -> tuple[torch.Tensor, torch.Tensor]: | ||||||
| ) -> tuple[bool, torch.Tensor, float]: | ||||||
| """Get grasp pose given approach direction. | ||||||
|
|
||||||
| Uses the antipodal point pairs stored in ``self._hit_point_pairs`` | ||||||
|
|
@@ -603,19 +603,20 @@ def get_grasp_poses( | |||||
| after computation. | ||||||
|
|
||||||
| Returns: | ||||||
| A tuple ``(best_grasp_pose, best_open_length)`` where | ||||||
| ``best_grasp_pose`` is a ``(4, 4)`` homogeneous matrix and | ||||||
| ``best_open_length`` is a scalar. | ||||||
| is_success (bool): Whether a valid grasp pose is found. | ||||||
| best_grasp_pose (torch.Tensor): If a valid grasp pose is found, a tensor of shape (4, 4) representing the homogeneous transformation matrix of the best grasp pose in the world frame. Otherwise, an identity matrix. | ||||||
| best_open_length (float): If a valid grasp pose is found, a scalar representing the optimal gripper opening length. Otherwise, a zero tensor. | ||||||
|
|
||||||
| Raises: | ||||||
| RuntimeError: If :meth:`generate` or :meth:`annotate` has not | ||||||
| been called yet. | ||||||
| """ | ||||||
| if self._hit_point_pairs is None: | ||||||
| raise RuntimeError( | ||||||
| logger.log_warning( | ||||||
| "No antipodal point pairs available. " | ||||||
| "Call generate() or annotate() first." | ||||||
| ) | ||||||
| return False, torch.eye(4, device=self.device), 0.0 | ||||||
|
Comment on lines
610
to
+619
|
||||||
| origin_points = self._hit_point_pairs[:, 0, :] | ||||||
| hit_points = self._hit_point_pairs[:, 1, :] | ||||||
| origin_points_ = self._apply_transform(origin_points, object_pose) | ||||||
|
|
@@ -632,6 +633,10 @@ def get_grasp_poses( | |||||
| valid_mask = ( | ||||||
| positive_angle - torch.pi / 2 | ||||||
| ).abs() <= self.cfg.max_deviation_angle | ||||||
| if valid_mask.sum() == 0: | ||||||
| logger.log_warning("No valid antipodal pairs after angle filtering.") | ||||||
| return False, torch.eye(4, device=self.device), 0.0 | ||||||
|
|
||||||
| valid_grasp_x = grasp_x[valid_mask] | ||||||
| valid_centers = centers[valid_mask] | ||||||
|
|
||||||
|
|
@@ -650,6 +655,9 @@ def get_grasp_poses( | |||||
| is_visual=visualize_collision, | ||||||
| collision_threshold=0.0, | ||||||
| ) | ||||||
| if is_colliding.logical_not().sum() == 0: | ||||||
| logger.log_warning("No valid antipodal pairs after angle filtering.") | ||||||
|
||||||
| logger.log_warning("No valid antipodal pairs after angle filtering.") | |
| logger.log_warning("No valid antipodal pairs after collision filtering.") |
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.
The return type/documentation for
best_open_lengthis inconsistent with what the function actually returns. The type hint saysfloat, the docstring mentions a "zero tensor" on failure, but the success path returns a 0-dimtorch.Tensor(best_open_length) while failure returns a Python0.0. Please make the return type consistent (either always return a Python float via.item()or update the type hint/docstring totorch.Tensorand returntorch.tensor(0.0, device=...)on failure).