Unverified Commit ed8fe3c4 authored by Giulio Romualdi's avatar Giulio Romualdi Committed by GitHub

Fixes joint out of position limits terminations (#2442)

# Description

<!--
Thank you for your interest in sending a pull request. Please make sure
to check the contribution guidelines.

Link:
https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html
-->

This PR fixes shape‑handling bugs in the termination helpers
**`joint_pos_out_of_limit`** and **`joint_pos_out_of_manual_limit`**:

* **Root cause** – both functions reduced across joints with
`torch.any(dim=1)` **before** slicing with `asset_cfg.joint_ids`,
leaving a 1‑D tensor and triggering an `IndexError: too many indices`.
* **Fix** – construct a single `violations` mask, optionally slice
joints, **then** reduce with `torch.any(dim=1)`.
This preserves correct shapes (`[num_envs]`) and works for any
joint‑selection type (`None`, `slice`, list, or tensor).
* **Additional improvements**

* Made `asset_cfg` immutable by avoiding in‑place modification of
`joint_ids`.
  * Added docstring details and harmonised logic between both helpers.

No new dependencies were introduced.

Fixes https://github.com/isaac-sim/IsaacLab/issues/2441

<!-- As a practice, it is recommended to open an issue to have
discussions on the proposed pull request.
This makes it easier for the community to keep track of what is being
developed or added, and if a given feature
is demanded by more than one party. -->

## Type of change

<!-- As you go through the list, delete the ones that are not
applicable. -->

* [x] Bug fix (non-breaking change which fixes an issue)
* [ ] New feature (non-breaking change which adds functionality)
* [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
* [ ] This change requires a documentation update

## Screenshots

*Not applicable – logic‑only change.*

<!--
Example:

| Before | After |
| ------ | ----- |
| _gif/png before_ | _gif/png after_ |

To upload images to a PR -- simply drag and drop an image while in edit
mode and it should upload the image directly. You can then paste that
source into the above before/after sections.
-->

## Checklist

* [ ] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
* [ ] I have made corresponding changes to the documentation
* [x] My changes generate no new warnings
* [x] I have added tests that prove my fix is effective or that my
feature works
* [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
* [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

<!--
As you go through the checklist above, you can mark something as done by
putting an x character in it

For example,
- [x] I have done this task
- [ ] I have not done this task
-->

---------
Signed-off-by: 's avatarGiulio Romualdi <giulio.romualdi@gmail.com>
Co-authored-by: 's avatarKelly Guo <kellyg@nvidia.com>
parent ff9c7529
...@@ -81,10 +81,13 @@ def joint_pos_out_of_limit(env: ManagerBasedRLEnv, asset_cfg: SceneEntityCfg = S ...@@ -81,10 +81,13 @@ def joint_pos_out_of_limit(env: ManagerBasedRLEnv, asset_cfg: SceneEntityCfg = S
"""Terminate when the asset's joint positions are outside of the soft joint limits.""" """Terminate when the asset's joint positions are outside of the soft joint limits."""
# extract the used quantities (to enable type-hinting) # extract the used quantities (to enable type-hinting)
asset: Articulation = env.scene[asset_cfg.name] asset: Articulation = env.scene[asset_cfg.name]
# compute any violations if asset_cfg.joint_ids is None:
out_of_upper_limits = torch.any(asset.data.joint_pos > asset.data.soft_joint_pos_limits[..., 1], dim=1) asset_cfg.joint_ids = slice(None)
out_of_lower_limits = torch.any(asset.data.joint_pos < asset.data.soft_joint_pos_limits[..., 0], dim=1)
return torch.logical_or(out_of_upper_limits[:, asset_cfg.joint_ids], out_of_lower_limits[:, asset_cfg.joint_ids]) limits = asset.data.soft_joint_pos_limits[:, asset_cfg.joint_ids]
out_of_upper_limits = torch.any(asset.data.joint_pos[:, asset_cfg.joint_ids] > limits[..., 1], dim=1)
out_of_lower_limits = torch.any(asset.data.joint_pos[:, asset_cfg.joint_ids] < limits[..., 0], dim=1)
return torch.logical_or(out_of_upper_limits, out_of_lower_limits)
def joint_pos_out_of_manual_limit( def joint_pos_out_of_manual_limit(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment