-
Notifications
You must be signed in to change notification settings - Fork 3k
Fixes IndexError in reset_joints_by_scale and reset_joints_by_offset #2949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes IndexError in reset_joints_by_scale and reset_joints_by_offset #2949
Conversation
ooctipus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Creampelt Sorry I was my miss!
Thank you for the fix, it looks very good XD
|
This content has not yet been merged into the main branch.. (2025.07.24) |
Signed-off-by: Kelly Guo <kellyg@nvidia.com>
Signed-off-by: Emily Sturman <emily@sturman.org>
Add dimension to env_ids (rather than indexing twice) Co-authored-by: Mayank Mittal <12863862+Mayankm96@users.noreply.github.com> Signed-off-by: Emily Sturman <emily@sturman.org>
|
Am I using git incorrectly? Still after downloading to git clone, the main branch does not have that issue updated, please check. i can`t find this commit or branch in gitlab original code |
|
@jhs3330395 this PR hasn't been merged yet -- I don't have push access, so it needs to be approved & merged by someone who does. I don't think you'll be able to see the commit in gitlab, since it is on a branch on my own fork of the repo. @Mayankm96 let me know if there are any other edits you'd like to see; otherwise, feel free to merge whenever :) |
Signed-off-by: Kelly Guo <kellyg@nvidia.com>
Signed-off-by: Kelly Guo <kellyg@nvidia.com>
|
I can't seem to get CI to run properly :( but locally most tests are passing. @Creampelt @ooctipus have either of you tried running the unit tests locally just to be sure? |
|
let me do that overnight :)) |
|
I went over my own implementation for the fix. Sharing it here in case we find this implementation better: def reset_joints_by_scale(
env: ManagerBasedEnv,
env_ids: torch.Tensor,
position_range: tuple[float, float],
velocity_range: tuple[float, float],
asset_cfg: SceneEntityCfg = SceneEntityCfg("robot"),
):
"""Reset the robot joints by scaling the default position and velocity by the given ranges.
This function samples random values from the given ranges and scales the default joint positions and velocities
by these values. The scaled values are then set into the physics simulation.
"""
# 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[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[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[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, joint_vel, joint_ids=asset_cfg.joint_ids, env_ids=env_ids)
def reset_joints_by_offset(
env: ManagerBasedEnv,
env_ids: torch.Tensor,
position_range: tuple[float, float],
velocity_range: tuple[float, float],
asset_cfg: SceneEntityCfg = SceneEntityCfg("robot"),
):
"""Reset the robot joints with offsets around the default position and velocity by the given ranges.
This function samples random values from the given ranges and biases the default joint positions and velocities
by these values. The biased values are then set into the physics simulation.
"""
# 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[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[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[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, joint_vel, joint_ids=asset_cfg.joint_ids, env_ids=env_ids) |
|
Yeah I like it, thanks @Mayankm96 |
|
@ooctipus @Creampelt Could you please take a look at above so we can merge the fix soon? :) |
Signed-off-by: Emily Sturman <emily@sturman.org>
|
@Mayankm96 pushed and tested the edits, everything is good to go! |
Signed-off-by: Emily Sturman <emily@sturman.org>
|
taking look at this right now! one ci passed I will make sure merge it soon |
Signed-off-by: ooctipus <zhengyuz@nvidia.com>
Signed-off-by: ooctipus <zhengyuz@nvidia.com>
…saac-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>
…saac-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>
Description
Fixes the IndexError caused by simultaneously indexing env_ids and joint_ids in
reset_joints_by_scaleandreset_joints_by_offset.Fixes # 2948
Type of change
Checklist
pre-commitchecks with./isaaclab.sh --formatconfig/extension.tomlfileCONTRIBUTORS.mdor my name already exists there