Unverified Commit b3ecfe3d authored by Kelly Guo's avatar Kelly Guo Committed by GitHub

Fixes indexing bug in write_joint_limits_to_sim (#1401)

# 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
-->
parent 9d6594b4
[package] [package]
# Note: Semantic Versioning is used: https://semver.org/ # Note: Semantic Versioning is used: https://semver.org/
version = "0.27.14" version = "0.27.15"
# Description # Description
title = "Isaac Lab framework for Robot Learning" title = "Isaac Lab framework for Robot Learning"
......
Changelog 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) 0.27.14 (2024-10-23)
~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~
......
...@@ -540,8 +540,13 @@ class Articulation(AssetBase): ...@@ -540,8 +540,13 @@ class Articulation(AssetBase):
# set into internal buffers # set into internal buffers
self._data.joint_limits[env_ids, joint_ids] = limits self._data.joint_limits[env_ids, joint_ids] = limits
# update default joint pos to stay within the new 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])): if torch.any(
self._data.default_joint_pos = torch.clamp(self._data.default_joint_pos, limits[..., 0], limits[..., 1]) (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( omni.log.warn(
"Some default joint positions are outside of the range of the new joint limits. Default joint positions" "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." " will be clamped to be within the new joint limits."
......
...@@ -572,6 +572,18 @@ class TestArticulation(unittest.TestCase): ...@@ -572,6 +572,18 @@ class TestArticulation(unittest.TestCase):
torch.testing.assert_close(articulation._data.joint_limits, limits) torch.testing.assert_close(articulation._data.joint_limits, limits)
torch.testing.assert_close(articulation._data.default_joint_pos, default_joint_pos) 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 # Set new joint limits that invalidate default joint pos
limits = torch.zeros(num_articulations, articulation.num_joints, 2, device=device) limits = torch.zeros(num_articulations, articulation.num_joints, 2, device=device)
limits[..., 0] = torch.rand(num_articulations, articulation.num_joints, device=device) * -0.1 limits[..., 0] = torch.rand(num_articulations, articulation.num_joints, device=device) * -0.1
...@@ -584,6 +596,18 @@ class TestArticulation(unittest.TestCase): ...@@ -584,6 +596,18 @@ class TestArticulation(unittest.TestCase):
) )
self.assertTrue(torch.all(within_bounds)) 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): def test_external_force_on_single_body(self):
"""Test application of external force on the base of the articulation.""" """Test application of external force on the base of the articulation."""
for num_articulations in (1, 2): for num_articulations in (1, 2):
......
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