Skip to content

Fixes joint out of position limits terminations #2442

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

GiulioRomualdi
Copy link
Contributor

Description

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

Type of change

  • 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.

Checklist

  • I have run the pre-commit checks with ./isaaclab.sh --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • 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
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

Comment on lines -103 to -104
out_of_upper_limits = torch.any(asset.data.joint_pos[:, asset_cfg.joint_ids] > bounds[1], dim=1)
out_of_lower_limits = torch.any(asset.data.joint_pos[:, asset_cfg.joint_ids] < bounds[0], dim=1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the implementation is correct since it is only operating over subset of joints.

Comment on lines +88 to +94
# Per‑env‑per‑joint mask of violations
joint_pos = asset.data.joint_pos # [N_envs, N_joints]
joint_lower = asset.data.soft_joint_pos_limits[..., 0]
joint_upper = asset.data.soft_joint_pos_limits[..., 1]
violations = (joint_pos < joint_lower) | (joint_pos > joint_upper)

joint_ids = asset_cfg.joint_ids if asset_cfg.joint_ids is not None else slice(None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it simpler to do it this way?

if asset_cfg.joint_ids is None:
   asset_cfg.joint_ids = slice(None)

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)

@Mayankm96
Copy link
Contributor

I don't see why we need to make a masking first. As long as any of the joints are out of their limits, the returned value should be True. If that's not the case, then could you please also share a repro for the issue?

@Mayankm96 Mayankm96 changed the title Fix joint_pos_out_limit and joint_pos_out_of_manual_limit terminations Fixes joint out of position limits terminations May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug Report] joint‑limit termination helpers raise *IndexError: too many indices* when joint_ids is set
2 participants