Unverified Commit c1ad81d9 authored by James Tigue's avatar James Tigue Committed by GitHub

Prevents randomizing mass to zero or less (#4060)

# Description

This PR prevents users from accidentally randomizing the mass of rigid
body to small and negative by clamping at 1e-6 kg.

Fixes #518 

## 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

- [ ] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [ ] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] 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

<!--
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: 's avatarKelly Guo <kellyg@nvidia.com>
Co-authored-by: 's avatarKelly Guo <kellyg@nvidia.com>
parent 560e7b89
[package]
# Note: Semantic Versioning is used: https://semver.org/
version = "0.50.1"
version = "0.50.2"
# Description
title = "Isaac Lab framework for Robot Learning"
......
Changelog
---------
0.50.2 (2025-11-21)
~~~~~~~~~~~~~~~~~~~
Fixed
^^^^^
* Prevent randomizing mass to zero in :meth:`~isaaclab.envs.mdp.events.randomize_mass_by_scale` to avoid physics errors.
0.50.1 (2025-11-25)
~~~~~~~~~~~~~~~~~~~
......
......@@ -323,6 +323,12 @@ class randomize_rigid_body_mass(ManagerTermBase):
"Randomization term 'randomize_rigid_body_mass' does not support operation:"
f" '{cfg.params['operation']}'."
)
if cfg.params.get("min_mass") is not None:
if cfg.params.get("min_mass") < 1e-6:
raise ValueError(
"Randomization term 'randomize_rigid_body_mass' does not support 'min_mass' less than 1e-6 to avoid"
" physics errors."
)
def __call__(
self,
......@@ -333,6 +339,7 @@ class randomize_rigid_body_mass(ManagerTermBase):
operation: Literal["add", "scale", "abs"],
distribution: Literal["uniform", "log_uniform", "gaussian"] = "uniform",
recompute_inertia: bool = True,
min_mass: float = 1e-6,
):
# resolve environment ids
if env_ids is None:
......@@ -360,6 +367,7 @@ class randomize_rigid_body_mass(ManagerTermBase):
masses = _randomize_prop_by_op(
masses, mass_distribution_params, env_ids, body_ids, operation=operation, distribution=distribution
)
masses = torch.clamp(masses, min=min_mass) # ensure masses are positive
# set the mass into the physics simulation
self.asset.root_physx_view.set_masses(masses, env_ids)
......
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