-
Notifications
You must be signed in to change notification settings - Fork 3.5k
OMPE-92490: Fix singular rotation matrix and non-rotation quaternion #5609
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
Merged
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| Fixed | ||
| ^^^^^ | ||
|
|
||
| * Fixed :func:`~isaaclab.utils.math.create_rotation_matrix_from_view` returning a singular | ||
| matrix when the look-at direction was parallel to the up axis. The function now produces | ||
| a valid orthonormal frame via an alternate reference vector, and fills NaN for rows with | ||
| truly undefined forward direction (``eyes == targets`` or non-finite input). Callers | ||
| detect per-row failure with ``torch.isnan(R).any(dim=(-2, -1))``. | ||
| * Fixed :func:`~isaaclab.utils.math.quat_from_matrix` silently returning a non-unit | ||
| quaternion for non-rotation input (singular, reflection, or scale-error matrices). | ||
| Such inputs now return NaN, detectable via :func:`torch.isnan`. | ||
| * Fixed :meth:`~isaaclab.sensors.camera.Camera.set_world_poses_from_view` and | ||
| :meth:`~isaaclab.sensors.ray_caster.RayCasterCamera.set_world_poses_from_view` silently | ||
| applying garbage poses when an eye position equaled its target. Degenerate rows are now | ||
| skipped (with a logged warning), and ``ValueError`` is raised if every row in the batch | ||
| is degenerate. |
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 | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -252,13 +252,35 @@ def set_world_poses_from_view( | |||||||||||||||||||
| Raises: | ||||||||||||||||||||
| RuntimeError: If the camera prim is not set. Need to call :meth:`initialize` method first. | ||||||||||||||||||||
| NotImplementedError: If the stage up-axis is not "Y" or "Z". | ||||||||||||||||||||
| ValueError: If every eye position equals its target (look-at direction undefined for the | ||||||||||||||||||||
| whole batch). When only some rows are degenerate, those rows are skipped and the | ||||||||||||||||||||
| remaining poses are still applied; a warning is logged. | ||||||||||||||||||||
| """ | ||||||||||||||||||||
| # resolve env_ids to a tensor up front so we can index it during partial-failure filtering | ||||||||||||||||||||
| if env_ids is None: | ||||||||||||||||||||
| env_ids = self._ALL_INDICES | ||||||||||||||||||||
| if not isinstance(env_ids, torch.Tensor): | ||||||||||||||||||||
| env_ids = torch.tensor(env_ids, dtype=torch.long, device=self._device) | ||||||||||||||||||||
| # get up axis of current stage | ||||||||||||||||||||
| up_axis = UsdGeom.GetStageUpAxis(self.stage) | ||||||||||||||||||||
| # camera position and rotation in opengl convention | ||||||||||||||||||||
| orientations = math_utils.quat_from_matrix( | ||||||||||||||||||||
| math_utils.create_rotation_matrix_from_view(eyes, targets, up_axis=up_axis, device=self._device) | ||||||||||||||||||||
| # camera position and rotation in opengl convention; degenerate rows (eye == target) come back as NaN | ||||||||||||||||||||
| rotation_matrix = math_utils.create_rotation_matrix_from_view( | ||||||||||||||||||||
| eyes, targets, up_axis=up_axis, device=self._device | ||||||||||||||||||||
| ) | ||||||||||||||||||||
| valid_indices = (~torch.isnan(rotation_matrix).any(dim=(-2, -1))).nonzero(as_tuple=True)[0] | ||||||||||||||||||||
| n_valid = valid_indices.numel() | ||||||||||||||||||||
| n_total = rotation_matrix.shape[0] | ||||||||||||||||||||
| if n_valid == 0: | ||||||||||||||||||||
| raise ValueError("look-at is undefined: every eye position equals its target") | ||||||||||||||||||||
| if n_valid < n_total: | ||||||||||||||||||||
| logger.warning( | ||||||||||||||||||||
| "set_world_poses_from_view: skipping %d pose(s) where eye equals target", | ||||||||||||||||||||
| n_total - n_valid, | ||||||||||||||||||||
| ) | ||||||||||||||||||||
|
Comment on lines
+276
to
+279
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
| rotation_matrix = rotation_matrix.index_select(0, valid_indices) | ||||||||||||||||||||
| eyes = eyes.index_select(0, valid_indices) | ||||||||||||||||||||
| env_ids = env_ids.index_select(0, valid_indices) | ||||||||||||||||||||
| orientations = math_utils.quat_from_matrix(rotation_matrix) | ||||||||||||||||||||
| self.set_world_poses(eyes, orientations, env_ids, convention="opengl") | ||||||||||||||||||||
|
|
||||||||||||||||||||
| """ | ||||||||||||||||||||
|
|
||||||||||||||||||||
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
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
7 changes: 7 additions & 0 deletions
7
source/isaaclab_newton/changelog.d/jmart-singular-rotation.rst
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,7 @@ | ||
| Fixed | ||
| ^^^^^ | ||
|
|
||
| * Fixed the acceleration-arrow debug visualizer in | ||
| :class:`~isaaclab_newton.sensors.pva.Pva` drawing arrows in undefined directions for | ||
| bodies with effectively zero acceleration. Such bodies are now skipped from the | ||
| visualization. |
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.
eye == targetas the reason for skipping a row, but the updated contract ofcreate_rotation_matrix_from_viewalso returns NaN for non-finite inputs (eyesortargetscontaininginf/NaN). A caller seeing this warning while debugging a non-finite-coordinate issue would be misled.