Skip to content

Commit 4ee4957

Browse files
Fixes actuator velocity limits propagation down the articulation root_physx_view (#1509)
# Description <!-- Thank you for your interest in sending a pull request. Please make sure to check the contribution guidelines. Link: https://isaac-sim.github.io/IsaacLab/source/refs/contributing.html --> Previously the velocity limits of the the ActuatorBaseCfg do not get used in most actuators. Only the DCMotor actuator uses it but it only uses it for torque-speed limitations. This PR propagates the velocity_limits of the ActuatorBaseCfg to the articulation root_physx_view. Fixes #1384 <!-- As a practice, it is recommended to open an issue to have discussions on the proposed pull request. This makes it easier for the community to keep track of what is being developed or added, and if a given feature is demanded by more than one party. --> ## 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) ## Screenshots Please attach before and after screenshots of the change if applicable. <!-- Example: | Before | After | | ------ | ----- | | _gif/png before_ | _gif/png after_ | To upload images to a PR -- simply drag and drop an image while in edit mode and it should upload the image directly. You can then paste that source into the above before/after sections. --> ## Checklist - [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with `./isaaclab.sh --format` - [x] 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 --> --------- Signed-off-by: Kelly Guo <[email protected]> Co-authored-by: Kelly Guo <[email protected]> Co-authored-by: Kelly Guo <[email protected]>
1 parent c2b3266 commit 4ee4957

File tree

5 files changed

+90
-3
lines changed

5 files changed

+90
-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.22"
4+
version = "0.27.23"
55

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

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

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

4+
0.27.23 (2024-12-06)
5+
~~~~~~~~~~~~~~~~~~~~
6+
7+
Fixed
8+
^^^^^
9+
10+
* Fixed the enforcement of :attr:`~omni.isaac.lab.actuators.ActuatorBaseCfg.velocity_limits` at the
11+
:attr:`~omni.isaac.lab.assets.Articulation.root_physx_view` level.
12+
13+
414
0.27.22 (2024-12-06)
515
~~~~~~~~~~~~~~~~~~~~
616

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,39 @@ def write_joint_damping_to_sim(
424424
# set into simulation
425425
self.root_physx_view.set_dof_dampings(self._data.joint_damping.cpu(), indices=physx_env_ids.cpu())
426426

427+
def write_joint_velocity_limit_to_sim(
428+
self,
429+
limits: torch.Tensor | float,
430+
joint_ids: Sequence[int] | slice | None = None,
431+
env_ids: Sequence[int] | None = None,
432+
):
433+
"""Write joint max velocity to the simulation.
434+
435+
Args:
436+
limits: Joint max velocity. Shape is (len(env_ids), len(joint_ids)).
437+
joint_ids: The joint indices to set the max velocity for. Defaults to None (all joints).
438+
env_ids: The environment indices to set the max velocity for. Defaults to None (all environments).
439+
"""
440+
# resolve indices
441+
physx_env_ids = env_ids
442+
if env_ids is None:
443+
env_ids = slice(None)
444+
physx_env_ids = self._ALL_INDICES
445+
if joint_ids is None:
446+
joint_ids = slice(None)
447+
# broadcast env_ids if needed to allow double indexing
448+
if env_ids != slice(None) and joint_ids != slice(None):
449+
env_ids = env_ids[:, None]
450+
# move tensor to cpu if needed
451+
if isinstance(limits, torch.Tensor):
452+
limits = limits.to(self.device)
453+
454+
# set into internal buffers
455+
self._data.joint_velocity_limits = self.root_physx_view.get_dof_max_velocities().to(self.device)
456+
self._data.joint_velocity_limits[env_ids, joint_ids] = limits
457+
# set into simulation
458+
self.root_physx_view.set_dof_max_velocities(self._data.joint_velocity_limits.cpu(), indices=physx_env_ids.cpu())
459+
427460
def write_joint_effort_limit_to_sim(
428461
self,
429462
limits: torch.Tensor | float,
@@ -1158,6 +1191,7 @@ def _process_actuators_cfg(self):
11581191
self.write_joint_stiffness_to_sim(actuator.stiffness, joint_ids=actuator.joint_indices)
11591192
self.write_joint_damping_to_sim(actuator.damping, joint_ids=actuator.joint_indices)
11601193
self.write_joint_effort_limit_to_sim(actuator.effort_limit, joint_ids=actuator.joint_indices)
1194+
self.write_joint_velocity_limit_to_sim(actuator.velocity_limit, joint_ids=actuator.joint_indices)
11611195
self.write_joint_armature_to_sim(actuator.armature, joint_ids=actuator.joint_indices)
11621196
self.write_joint_friction_to_sim(actuator.friction, joint_ids=actuator.joint_indices)
11631197
else:
@@ -1166,6 +1200,7 @@ def _process_actuators_cfg(self):
11661200
self.write_joint_stiffness_to_sim(0.0, joint_ids=actuator.joint_indices)
11671201
self.write_joint_damping_to_sim(0.0, joint_ids=actuator.joint_indices)
11681202
self.write_joint_effort_limit_to_sim(1.0e9, joint_ids=actuator.joint_indices)
1203+
self.write_joint_velocity_limit_to_sim(actuator.velocity_limit, joint_ids=actuator.joint_indices)
11691204
self.write_joint_armature_to_sim(actuator.armature, joint_ids=actuator.joint_indices)
11701205
self.write_joint_friction_to_sim(actuator.friction, joint_ids=actuator.joint_indices)
11711206
# Store the actual default stiffness and damping values for explicit actuators (not written the sim)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ def update(self, dt: float):
220220
joint_limits: torch.Tensor = None
221221
"""Joint limits provided to simulation. Shape is (num_instances, num_joints, 2)."""
222222

223+
joint_velocity_limits: torch.Tensor = None
224+
"""Joint maximum velocity provided to simulation. Shape is (num_instances, num_joints)."""
225+
223226
##
224227
# Fixed tendon properties.
225228
##

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

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def generate_articulation_cfg(
4242
articulation_type: Literal["humanoid", "panda", "anymal", "shadow_hand", "single_joint"],
4343
stiffness: float | None = 10.0,
4444
damping: float | None = 2.0,
45+
vel_limit: float | None = 100.0,
46+
effort_limit: float | None = 400.0,
4547
) -> ArticulationCfg:
4648
"""Generate an articulation configuration.
4749
@@ -72,8 +74,8 @@ def generate_articulation_cfg(
7274
actuators={
7375
"joint": ImplicitActuatorCfg(
7476
joint_names_expr=[".*"],
75-
effort_limit=400.0,
76-
velocity_limit=100.0,
77+
effort_limit=effort_limit,
78+
velocity_limit=vel_limit,
7779
stiffness=0.0,
7880
damping=10.0,
7981
),
@@ -813,6 +815,43 @@ def test_setting_gains_from_cfg_dict(self):
813815
torch.testing.assert_close(articulation.actuators["body"].stiffness, expected_stiffness)
814816
torch.testing.assert_close(articulation.actuators["body"].damping, expected_damping)
815817

818+
def test_setting_velocity_limits(self):
819+
"""Test that velocity limits are loaded form the configuration correctly."""
820+
for num_articulations in (1, 2):
821+
for device in ("cuda:0", "cpu"):
822+
for limit in (5.0, None):
823+
with self.subTest(num_articulations=num_articulations, device=device, limit=limit):
824+
with build_simulation_context(
825+
device=device, add_ground_plane=False, auto_add_lighting=True
826+
) as sim:
827+
articulation_cfg = generate_articulation_cfg(
828+
articulation_type="single_joint", vel_limit=limit, effort_limit=limit
829+
)
830+
articulation, _ = generate_articulation(
831+
articulation_cfg=articulation_cfg, num_articulations=num_articulations, device=device
832+
)
833+
# Play sim
834+
sim.reset()
835+
836+
if limit is not None:
837+
# Expected gains
838+
expected_velocity_limit = torch.full(
839+
(articulation.num_instances, articulation.num_joints),
840+
limit,
841+
device=articulation.device,
842+
)
843+
# Check that gains are loaded from USD file
844+
torch.testing.assert_close(
845+
articulation.actuators["joint"].velocity_limit, expected_velocity_limit
846+
)
847+
torch.testing.assert_close(
848+
articulation.data.joint_velocity_limits, expected_velocity_limit
849+
)
850+
torch.testing.assert_close(
851+
articulation.root_physx_view.get_dof_max_velocities().to(device),
852+
expected_velocity_limit,
853+
)
854+
816855
def test_reset(self):
817856
"""Test that reset method works properly.
818857

0 commit comments

Comments
 (0)