Skip to content

Commit ed8fe3c

Browse files
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 #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: Giulio Romualdi <giulio.romualdi@gmail.com> Co-authored-by: Kelly Guo <kellyg@nvidia.com>
1 parent ff9c752 commit ed8fe3c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

source/isaaclab/isaaclab/envs/mdp/terminations.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,13 @@ def joint_pos_out_of_limit(env: ManagerBasedRLEnv, asset_cfg: SceneEntityCfg = S
8181
"""Terminate when the asset's joint positions are outside of the soft joint limits."""
8282
# extract the used quantities (to enable type-hinting)
8383
asset: Articulation = env.scene[asset_cfg.name]
84-
# compute any violations
85-
out_of_upper_limits = torch.any(asset.data.joint_pos > asset.data.soft_joint_pos_limits[..., 1], dim=1)
86-
out_of_lower_limits = torch.any(asset.data.joint_pos < asset.data.soft_joint_pos_limits[..., 0], dim=1)
87-
return torch.logical_or(out_of_upper_limits[:, asset_cfg.joint_ids], out_of_lower_limits[:, asset_cfg.joint_ids])
84+
if asset_cfg.joint_ids is None:
85+
asset_cfg.joint_ids = slice(None)
86+
87+
limits = asset.data.soft_joint_pos_limits[:, asset_cfg.joint_ids]
88+
out_of_upper_limits = torch.any(asset.data.joint_pos[:, asset_cfg.joint_ids] > limits[..., 1], dim=1)
89+
out_of_lower_limits = torch.any(asset.data.joint_pos[:, asset_cfg.joint_ids] < limits[..., 0], dim=1)
90+
return torch.logical_or(out_of_upper_limits, out_of_lower_limits)
8891

8992

9093
def joint_pos_out_of_manual_limit(

0 commit comments

Comments
 (0)