Skip to content

Commit

Permalink
Fixes indexing bug in write_joint_limits_to_sim (#1401)
Browse files Browse the repository at this point in the history
# Description

This change fixes bugs in Articulation class `write_joint_limits_to_sim`
method, where previously env_ids and joint_ids were not taken into
account when ids passed in are not None.

## Type of change

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

- Bug fix (non-breaking change which fixes an issue)


## Checklist

- [x] 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
- [x] 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
-->
  • Loading branch information
kellyguo11 authored Nov 17, 2024
1 parent 9d6594b commit b3ecfe3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion source/extensions/omni.isaac.lab/config/extension.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

# Note: Semantic Versioning is used: https://semver.org/
version = "0.27.14"
version = "0.27.15"

# Description
title = "Isaac Lab framework for Robot Learning"
Expand Down
9 changes: 9 additions & 0 deletions source/extensions/omni.isaac.lab/docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Changelog
---------

0.27.15 (2024-11-09)
~~~~~~~~~~~~~~~~~~~~

Fixed
^^^^^

* Fixed indexing in :meth:`omni.isaac.lab.assets.Articulation.write_joint_limits_to_sim` to correctly process non-None ``env_ids`` and ``joint_ids``.


0.27.14 (2024-10-23)
~~~~~~~~~~~~~~~~~~~~

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,13 @@ def write_joint_limits_to_sim(
# set into internal buffers
self._data.joint_limits[env_ids, joint_ids] = limits
# update default joint pos to stay within the new limits
if torch.any((self._data.default_joint_pos < limits[..., 0]) | (self._data.default_joint_pos > limits[..., 1])):
self._data.default_joint_pos = torch.clamp(self._data.default_joint_pos, limits[..., 0], limits[..., 1])
if torch.any(
(self._data.default_joint_pos[env_ids, joint_ids] < limits[..., 0])
| (self._data.default_joint_pos[env_ids, joint_ids] > limits[..., 1])
):
self._data.default_joint_pos[env_ids, joint_ids] = torch.clamp(
self._data.default_joint_pos[env_ids, joint_ids], limits[..., 0], limits[..., 1]
)
omni.log.warn(
"Some default joint positions are outside of the range of the new joint limits. Default joint positions"
" will be clamped to be within the new joint limits."
Expand Down
24 changes: 24 additions & 0 deletions source/extensions/omni.isaac.lab/test/assets/test_articulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,18 @@ def test_joint_limits(self):
torch.testing.assert_close(articulation._data.joint_limits, limits)
torch.testing.assert_close(articulation._data.default_joint_pos, default_joint_pos)

# Set new joint limits with indexing
env_ids = torch.arange(1, device=device)
joint_ids = torch.arange(2, device=device)
limits = torch.zeros(env_ids.shape[0], joint_ids.shape[0], 2, device=device)
limits[..., 0] = (torch.rand(env_ids.shape[0], joint_ids.shape[0], device=device) + 5.0) * -1.0
limits[..., 1] = torch.rand(env_ids.shape[0], joint_ids.shape[0], device=device) + 5.0
articulation.write_joint_limits_to_sim(limits, env_ids=env_ids, joint_ids=joint_ids)

# Check new limits are in place
torch.testing.assert_close(articulation._data.joint_limits[env_ids][:, joint_ids], limits)
torch.testing.assert_close(articulation._data.default_joint_pos, default_joint_pos)

# Set new joint limits that invalidate default joint pos
limits = torch.zeros(num_articulations, articulation.num_joints, 2, device=device)
limits[..., 0] = torch.rand(num_articulations, articulation.num_joints, device=device) * -0.1
Expand All @@ -584,6 +596,18 @@ def test_joint_limits(self):
)
self.assertTrue(torch.all(within_bounds))

# Set new joint limits that invalidate default joint pos with indexing
limits = torch.zeros(env_ids.shape[0], joint_ids.shape[0], 2, device=device)
limits[..., 0] = torch.rand(env_ids.shape[0], joint_ids.shape[0], device=device) * -0.1
limits[..., 1] = torch.rand(env_ids.shape[0], joint_ids.shape[0], device=device) * 0.1
articulation.write_joint_limits_to_sim(limits, env_ids=env_ids, joint_ids=joint_ids)

# Check if all values are within the bounds
within_bounds = (
articulation._data.default_joint_pos[env_ids][:, joint_ids] >= limits[..., 0]
) & (articulation._data.default_joint_pos[env_ids][:, joint_ids] <= limits[..., 1])
self.assertTrue(torch.all(within_bounds))

def test_external_force_on_single_body(self):
"""Test application of external force on the base of the articulation."""
for num_articulations in (1, 2):
Expand Down

0 comments on commit b3ecfe3

Please sign in to comment.