Skip to content

Commit b3ecfe3

Browse files
authored
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 -->
1 parent 9d6594b commit b3ecfe3

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

source/extensions/omni.isaac.lab/config/extension.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
# Note: Semantic Versioning is used: https://semver.org/
4-
version = "0.27.14"
4+
version = "0.27.15"
55

66
# Description
77
title = "Isaac Lab framework for Robot Learning"

source/extensions/omni.isaac.lab/docs/CHANGELOG.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Changelog
22
---------
33

4+
0.27.15 (2024-11-09)
5+
~~~~~~~~~~~~~~~~~~~~
6+
7+
Fixed
8+
^^^^^
9+
10+
* Fixed indexing in :meth:`omni.isaac.lab.assets.Articulation.write_joint_limits_to_sim` to correctly process non-None ``env_ids`` and ``joint_ids``.
11+
12+
413
0.27.14 (2024-10-23)
514
~~~~~~~~~~~~~~~~~~~~
615

source/extensions/omni.isaac.lab/omni/isaac/lab/assets/articulation/articulation.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,13 @@ def write_joint_limits_to_sim(
540540
# set into internal buffers
541541
self._data.joint_limits[env_ids, joint_ids] = limits
542542
# update default joint pos to stay within the new limits
543-
if torch.any((self._data.default_joint_pos < limits[..., 0]) | (self._data.default_joint_pos > limits[..., 1])):
544-
self._data.default_joint_pos = torch.clamp(self._data.default_joint_pos, limits[..., 0], limits[..., 1])
543+
if torch.any(
544+
(self._data.default_joint_pos[env_ids, joint_ids] < limits[..., 0])
545+
| (self._data.default_joint_pos[env_ids, joint_ids] > limits[..., 1])
546+
):
547+
self._data.default_joint_pos[env_ids, joint_ids] = torch.clamp(
548+
self._data.default_joint_pos[env_ids, joint_ids], limits[..., 0], limits[..., 1]
549+
)
545550
omni.log.warn(
546551
"Some default joint positions are outside of the range of the new joint limits. Default joint positions"
547552
" will be clamped to be within the new joint limits."

source/extensions/omni.isaac.lab/test/assets/test_articulation.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,18 @@ def test_joint_limits(self):
572572
torch.testing.assert_close(articulation._data.joint_limits, limits)
573573
torch.testing.assert_close(articulation._data.default_joint_pos, default_joint_pos)
574574

575+
# Set new joint limits with indexing
576+
env_ids = torch.arange(1, device=device)
577+
joint_ids = torch.arange(2, device=device)
578+
limits = torch.zeros(env_ids.shape[0], joint_ids.shape[0], 2, device=device)
579+
limits[..., 0] = (torch.rand(env_ids.shape[0], joint_ids.shape[0], device=device) + 5.0) * -1.0
580+
limits[..., 1] = torch.rand(env_ids.shape[0], joint_ids.shape[0], device=device) + 5.0
581+
articulation.write_joint_limits_to_sim(limits, env_ids=env_ids, joint_ids=joint_ids)
582+
583+
# Check new limits are in place
584+
torch.testing.assert_close(articulation._data.joint_limits[env_ids][:, joint_ids], limits)
585+
torch.testing.assert_close(articulation._data.default_joint_pos, default_joint_pos)
586+
575587
# Set new joint limits that invalidate default joint pos
576588
limits = torch.zeros(num_articulations, articulation.num_joints, 2, device=device)
577589
limits[..., 0] = torch.rand(num_articulations, articulation.num_joints, device=device) * -0.1
@@ -584,6 +596,18 @@ def test_joint_limits(self):
584596
)
585597
self.assertTrue(torch.all(within_bounds))
586598

599+
# Set new joint limits that invalidate default joint pos with indexing
600+
limits = torch.zeros(env_ids.shape[0], joint_ids.shape[0], 2, device=device)
601+
limits[..., 0] = torch.rand(env_ids.shape[0], joint_ids.shape[0], device=device) * -0.1
602+
limits[..., 1] = torch.rand(env_ids.shape[0], joint_ids.shape[0], device=device) * 0.1
603+
articulation.write_joint_limits_to_sim(limits, env_ids=env_ids, joint_ids=joint_ids)
604+
605+
# Check if all values are within the bounds
606+
within_bounds = (
607+
articulation._data.default_joint_pos[env_ids][:, joint_ids] >= limits[..., 0]
608+
) & (articulation._data.default_joint_pos[env_ids][:, joint_ids] <= limits[..., 1])
609+
self.assertTrue(torch.all(within_bounds))
610+
587611
def test_external_force_on_single_body(self):
588612
"""Test application of external force on the base of the articulation."""
589613
for num_articulations in (1, 2):

0 commit comments

Comments
 (0)