Skip to content

Commit 42a5bd2

Browse files
Creampeltkellyguo11Mayankm96ooctipus
authored
Fixes IndexError in reset_joints_by_scale and reset_joints_by_offset (isaac-sim#2949)
# Description Fixes the IndexError caused by simultaneously indexing env_ids and joint_ids in `reset_joints_by_scale` and `reset_joints_by_offset`. Fixes # [2948](isaac-sim#2948) ## 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 - [ ] 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 --------- Signed-off-by: Kelly Guo <kellyg@nvidia.com> Signed-off-by: Emily Sturman <emily@sturman.org> Signed-off-by: ooctipus <zhengyuz@nvidia.com> Co-authored-by: Kelly Guo <kellyg@nvidia.com> Co-authored-by: Mayank Mittal <12863862+Mayankm96@users.noreply.github.com> Co-authored-by: ooctipus <zhengyuz@nvidia.com>
1 parent ba9f0a7 commit 42a5bd2

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Guidelines for modifications:
5959
* David Yang
6060
* Dhananjay Shendre
6161
* Dorsa Rohani
62+
* Emily Sturman
6263
* Fabian Jenelten
6364
* Felipe Mohr
6465
* Felix Yu

source/isaaclab/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.44.12 (2025-08-12)
5+
~~~~~~~~~~~~~~~~~~~
6+
7+
Fixed
8+
^^^^^
9+
10+
* Fixed IndexError in :meth:`isaaclab.envs.mdp.events.reset_joints_by_scale`,
11+
:meth:`isaaclab.envs.mdp.events.reset_joints_by_offsets` by adding dimension to env_ids when indexing.
12+
13+
414
0.44.11 (2025-08-11)
515
~~~~~~~~~~~~~~~~~~~
616

source/isaaclab/isaaclab/envs/mdp/events.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,28 +1041,30 @@ def reset_joints_by_scale(
10411041
"""
10421042
# extract the used quantities (to enable type-hinting)
10431043
asset: Articulation = env.scene[asset_cfg.name]
1044+
1045+
# cast env_ids to allow broadcasting
1046+
if asset_cfg.joint_ids != slice(None):
1047+
iter_env_ids = env_ids[:, None]
1048+
else:
1049+
iter_env_ids = env_ids
1050+
10441051
# get default joint state
1045-
joint_pos = asset.data.default_joint_pos[env_ids, asset_cfg.joint_ids].clone()
1046-
joint_vel = asset.data.default_joint_vel[env_ids, asset_cfg.joint_ids].clone()
1052+
joint_pos = asset.data.default_joint_pos[iter_env_ids, asset_cfg.joint_ids].clone()
1053+
joint_vel = asset.data.default_joint_vel[iter_env_ids, asset_cfg.joint_ids].clone()
10471054

10481055
# scale these values randomly
10491056
joint_pos *= math_utils.sample_uniform(*position_range, joint_pos.shape, joint_pos.device)
10501057
joint_vel *= math_utils.sample_uniform(*velocity_range, joint_vel.shape, joint_vel.device)
10511058

10521059
# clamp joint pos to limits
1053-
joint_pos_limits = asset.data.soft_joint_pos_limits[env_ids, asset_cfg.joint_ids]
1060+
joint_pos_limits = asset.data.soft_joint_pos_limits[iter_env_ids, asset_cfg.joint_ids]
10541061
joint_pos = joint_pos.clamp_(joint_pos_limits[..., 0], joint_pos_limits[..., 1])
10551062
# clamp joint vel to limits
1056-
joint_vel_limits = asset.data.soft_joint_vel_limits[env_ids, asset_cfg.joint_ids]
1063+
joint_vel_limits = asset.data.soft_joint_vel_limits[iter_env_ids, asset_cfg.joint_ids]
10571064
joint_vel = joint_vel.clamp_(-joint_vel_limits, joint_vel_limits)
10581065

10591066
# set into the physics simulation
1060-
asset.write_joint_state_to_sim(
1061-
joint_pos.view(len(env_ids), -1),
1062-
joint_vel.view(len(env_ids), -1),
1063-
env_ids=env_ids,
1064-
joint_ids=asset_cfg.joint_ids,
1065-
)
1067+
asset.write_joint_state_to_sim(joint_pos, joint_vel, joint_ids=asset_cfg.joint_ids, env_ids=env_ids)
10661068

10671069

10681070
def reset_joints_by_offset(
@@ -1080,28 +1082,29 @@ def reset_joints_by_offset(
10801082
# extract the used quantities (to enable type-hinting)
10811083
asset: Articulation = env.scene[asset_cfg.name]
10821084

1085+
# cast env_ids to allow broadcasting
1086+
if asset_cfg.joint_ids != slice(None):
1087+
iter_env_ids = env_ids[:, None]
1088+
else:
1089+
iter_env_ids = env_ids
1090+
10831091
# get default joint state
1084-
joint_pos = asset.data.default_joint_pos[env_ids, asset_cfg.joint_ids].clone()
1085-
joint_vel = asset.data.default_joint_vel[env_ids, asset_cfg.joint_ids].clone()
1092+
joint_pos = asset.data.default_joint_pos[iter_env_ids, asset_cfg.joint_ids].clone()
1093+
joint_vel = asset.data.default_joint_vel[iter_env_ids, asset_cfg.joint_ids].clone()
10861094

10871095
# bias these values randomly
10881096
joint_pos += math_utils.sample_uniform(*position_range, joint_pos.shape, joint_pos.device)
10891097
joint_vel += math_utils.sample_uniform(*velocity_range, joint_vel.shape, joint_vel.device)
10901098

10911099
# clamp joint pos to limits
1092-
joint_pos_limits = asset.data.soft_joint_pos_limits[env_ids, asset_cfg.joint_ids]
1100+
joint_pos_limits = asset.data.soft_joint_pos_limits[iter_env_ids, asset_cfg.joint_ids]
10931101
joint_pos = joint_pos.clamp_(joint_pos_limits[..., 0], joint_pos_limits[..., 1])
10941102
# clamp joint vel to limits
1095-
joint_vel_limits = asset.data.soft_joint_vel_limits[env_ids, asset_cfg.joint_ids]
1103+
joint_vel_limits = asset.data.soft_joint_vel_limits[iter_env_ids, asset_cfg.joint_ids]
10961104
joint_vel = joint_vel.clamp_(-joint_vel_limits, joint_vel_limits)
10971105

10981106
# set into the physics simulation
1099-
asset.write_joint_state_to_sim(
1100-
joint_pos.view(len(env_ids), -1),
1101-
joint_vel.view(len(env_ids), -1),
1102-
env_ids=env_ids,
1103-
joint_ids=asset_cfg.joint_ids,
1104-
)
1107+
asset.write_joint_state_to_sim(joint_pos, joint_vel, joint_ids=asset_cfg.joint_ids, env_ids=env_ids)
11051108

11061109

11071110
def reset_nodal_state_uniform(

0 commit comments

Comments
 (0)