Unverified Commit 089015fc authored by Emily Sturman's avatar Emily Sturman Committed by GitHub

Fixes IndexError in reset_joints_by_scale and reset_joints_by_offset (#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](https://github.com/isaac-sim/IsaacLab/issues/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: 's avatarKelly Guo <kellyg@nvidia.com>
Signed-off-by: 's avatarEmily Sturman <emily@sturman.org>
Signed-off-by: 's avatarooctipus <zhengyuz@nvidia.com>
Co-authored-by: 's avatarKelly Guo <kellyg@nvidia.com>
Co-authored-by: 's avatarMayank Mittal <12863862+Mayankm96@users.noreply.github.com>
Co-authored-by: 's avatarooctipus <zhengyuz@nvidia.com>
parent 5ca0c323
......@@ -59,6 +59,7 @@ Guidelines for modifications:
* David Yang
* Dhananjay Shendre
* Dorsa Rohani
* Emily Sturman
* Fabian Jenelten
* Felipe Mohr
* Felix Yu
......
Changelog
---------
0.44.12 (2025-08-12)
~~~~~~~~~~~~~~~~~~~
Fixed
^^^^^
* Fixed IndexError in :meth:`isaaclab.envs.mdp.events.reset_joints_by_scale`,
:meth:`isaaclab.envs.mdp.events.reset_joints_by_offsets` by adding dimension to env_ids when indexing.
0.44.11 (2025-08-11)
~~~~~~~~~~~~~~~~~~~
......
......@@ -1041,28 +1041,30 @@ def reset_joints_by_scale(
"""
# extract the used quantities (to enable type-hinting)
asset: Articulation = env.scene[asset_cfg.name]
# cast env_ids to allow broadcasting
if asset_cfg.joint_ids != slice(None):
iter_env_ids = env_ids[:, None]
else:
iter_env_ids = env_ids
# get default joint state
joint_pos = asset.data.default_joint_pos[env_ids, asset_cfg.joint_ids].clone()
joint_vel = asset.data.default_joint_vel[env_ids, asset_cfg.joint_ids].clone()
joint_pos = asset.data.default_joint_pos[iter_env_ids, asset_cfg.joint_ids].clone()
joint_vel = asset.data.default_joint_vel[iter_env_ids, asset_cfg.joint_ids].clone()
# scale these values randomly
joint_pos *= math_utils.sample_uniform(*position_range, joint_pos.shape, joint_pos.device)
joint_vel *= math_utils.sample_uniform(*velocity_range, joint_vel.shape, joint_vel.device)
# clamp joint pos to limits
joint_pos_limits = asset.data.soft_joint_pos_limits[env_ids, asset_cfg.joint_ids]
joint_pos_limits = asset.data.soft_joint_pos_limits[iter_env_ids, asset_cfg.joint_ids]
joint_pos = joint_pos.clamp_(joint_pos_limits[..., 0], joint_pos_limits[..., 1])
# clamp joint vel to limits
joint_vel_limits = asset.data.soft_joint_vel_limits[env_ids, asset_cfg.joint_ids]
joint_vel_limits = asset.data.soft_joint_vel_limits[iter_env_ids, asset_cfg.joint_ids]
joint_vel = joint_vel.clamp_(-joint_vel_limits, joint_vel_limits)
# set into the physics simulation
asset.write_joint_state_to_sim(
joint_pos.view(len(env_ids), -1),
joint_vel.view(len(env_ids), -1),
env_ids=env_ids,
joint_ids=asset_cfg.joint_ids,
)
asset.write_joint_state_to_sim(joint_pos, joint_vel, joint_ids=asset_cfg.joint_ids, env_ids=env_ids)
def reset_joints_by_offset(
......@@ -1080,28 +1082,29 @@ def reset_joints_by_offset(
# extract the used quantities (to enable type-hinting)
asset: Articulation = env.scene[asset_cfg.name]
# cast env_ids to allow broadcasting
if asset_cfg.joint_ids != slice(None):
iter_env_ids = env_ids[:, None]
else:
iter_env_ids = env_ids
# get default joint state
joint_pos = asset.data.default_joint_pos[env_ids, asset_cfg.joint_ids].clone()
joint_vel = asset.data.default_joint_vel[env_ids, asset_cfg.joint_ids].clone()
joint_pos = asset.data.default_joint_pos[iter_env_ids, asset_cfg.joint_ids].clone()
joint_vel = asset.data.default_joint_vel[iter_env_ids, asset_cfg.joint_ids].clone()
# bias these values randomly
joint_pos += math_utils.sample_uniform(*position_range, joint_pos.shape, joint_pos.device)
joint_vel += math_utils.sample_uniform(*velocity_range, joint_vel.shape, joint_vel.device)
# clamp joint pos to limits
joint_pos_limits = asset.data.soft_joint_pos_limits[env_ids, asset_cfg.joint_ids]
joint_pos_limits = asset.data.soft_joint_pos_limits[iter_env_ids, asset_cfg.joint_ids]
joint_pos = joint_pos.clamp_(joint_pos_limits[..., 0], joint_pos_limits[..., 1])
# clamp joint vel to limits
joint_vel_limits = asset.data.soft_joint_vel_limits[env_ids, asset_cfg.joint_ids]
joint_vel_limits = asset.data.soft_joint_vel_limits[iter_env_ids, asset_cfg.joint_ids]
joint_vel = joint_vel.clamp_(-joint_vel_limits, joint_vel_limits)
# set into the physics simulation
asset.write_joint_state_to_sim(
joint_pos.view(len(env_ids), -1),
joint_vel.view(len(env_ids), -1),
env_ids=env_ids,
joint_ids=asset_cfg.joint_ids,
)
asset.write_joint_state_to_sim(joint_pos, joint_vel, joint_ids=asset_cfg.joint_ids, env_ids=env_ids)
def reset_nodal_state_uniform(
......
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