Skip to content

Commit

Permalink
Fixes default joint pos when setting joint limits (#1040)
Browse files Browse the repository at this point in the history
# Description

When setting joint limits, the existing default joint positions can fall
outside of the bounds of the new joint limits. This change clips the
default joint positions to ensure they are within the bounds of the new
limits.

## Type of change

- 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
- [ ] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there
  • Loading branch information
kellyguo11 authored Oct 10, 2024
1 parent 73c47e4 commit cb9fee6
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 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.25.0"
version = "0.25.1"

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

0.25.1 (2024-10-10)
~~~~~~~~~~~~~~~~~~~

Fixed
^^^^^

* Fixed potential issue where default joint positions can fall outside of the limits being set with Articulation's
``write_joint_limits_to_sim`` API.


0.25.0 (2024-10-06)
~~~~~~~~~~~~~~~~~~~

Expand All @@ -14,7 +24,7 @@ Added
0.24.20 (2024-10-07)
~~~~~~~~~~~~~~~~~~~~

Fixes
Fixed
^^^^^

* Fixed the :meth:`omni.isaac.lab.envs.mdp.events.randomize_rigid_body_material` function to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,13 @@ def write_joint_limits_to_sim(
env_ids = env_ids[:, None]
# 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])
carb.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."
)
# set into simulation
self.root_physx_view.set_dof_limits(self._data.joint_limits.cpu(), indices=physx_env_ids.cpu())

Expand Down
42 changes: 42 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 @@ -542,6 +542,48 @@ def test_out_of_range_default_joint_vel(self):
# Check if articulation is initialized
self.assertFalse(articulation._is_initialized)

def test_joint_limits(self):
"""Test write_joint_limits_to_sim API and when default pos falls outside of the new limits."""
for num_articulations in (1, 2):
for device in ("cuda:0", "cpu"):
with self.subTest(num_articulations=num_articulations, device=device):
with build_simulation_context(device=device, add_ground_plane=True, auto_add_lighting=True) as sim:
# Create articulation
articulation_cfg = generate_articulation_cfg(articulation_type="panda")
articulation, _ = generate_articulation(articulation_cfg, num_articulations, device)

# Play sim
sim.reset()
# Check if articulation is initialized
self.assertTrue(articulation._is_initialized)

# Get current default joint pos
default_joint_pos = articulation._data.default_joint_pos.clone()

# Set new joint limits
limits = torch.zeros(num_articulations, articulation.num_joints, 2, device=device)
limits[..., 0] = (
torch.rand(num_articulations, articulation.num_joints, device=device) + 5.0
) * -1.0
limits[..., 1] = torch.rand(num_articulations, articulation.num_joints, device=device) + 5.0
articulation.write_joint_limits_to_sim(limits)

# Check new limits are in place
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 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
limits[..., 1] = torch.rand(num_articulations, articulation.num_joints, device=device) * 0.1
articulation.write_joint_limits_to_sim(limits)

# Check if all values are within the bounds
within_bounds = (articulation._data.default_joint_pos >= limits[..., 0]) & (
articulation._data.default_joint_pos <= 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
1 change: 1 addition & 0 deletions tools/per_test_timeouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Any tests not listed here will use the default timeout.
"""
PER_TEST_TIMEOUTS = {
"test_articulation.py": 200,
"test_environments.py": 1200, # This test runs through all the environments for 100 steps each
"test_environment_determinism.py": 200, # This test runs through many the environments for 100 steps each
"test_env_rendering_logic.py": 300,
Expand Down

0 comments on commit cb9fee6

Please sign in to comment.