Skip to content

Prevents randomizing mass to zero or less - #4060

Merged
kellyguo11 merged 5 commits into
isaac-sim:mainfrom
jtigue-bdai:jat/fix/prevent_randomizing_mass_negative
Dec 11, 2025
Merged

kellyguo11 merged 5 commits into
isaac-sim:mainfrom
jtigue-bdai:jat/fix/prevent_randomizing_mass_negative

Conversation

@jtigue-bdai

Copy link
Copy Markdown
Collaborator

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

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks 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

@github-actions github-actions Bot added bug Something isn't working isaac-lab Related to Isaac Lab team labels Nov 21, 2025
@jtigue-bdai jtigue-bdai self-assigned this Nov 21, 2025
@greptile-apps

greptile-apps Bot commented Nov 21, 2025

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

Added a single line of code to clamp randomized rigid body masses to a minimum value of 1e-6 kg in the randomize_rigid_body_mass class. This prevents PhysX errors (PxRigidBody::setMass(): mass must be non-negative!) that occur when mass randomization operations (particularly scaling with values near zero or adding negative values) result in zero or negative masses. The fix is applied after randomization but before setting masses into the physics simulation, ensuring all downstream operations (including inertia recomputation) work with valid mass values.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is minimal, well-placed, and directly addresses the reported PhysX error. The clamping value (1e-6 kg) is physically reasonable and small enough to not interfere with intended randomization while preventing the zero/negative mass error. The change preserves all existing functionality and the validation logic at initialization already prevents problematic scale ranges.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
source/isaaclab/isaaclab/envs/mdp/events.py 5/5 Added mass clamping to prevent PhysX errors from zero/negative masses during randomization
source/isaaclab/docs/CHANGELOG.rst 5/5 Documented the bug fix in changelog with version bump to 0.48.6

Sequence Diagram

sequenceDiagram
    participant User
    participant randomize_rigid_body_mass
    participant _randomize_prop_by_op
    participant PhysX

    User->>randomize_rigid_body_mass: Call with mass_distribution_params
    randomize_rigid_body_mass->>PhysX: Get current masses
    randomize_rigid_body_mass->>randomize_rigid_body_mass: Reset to default_mass
    randomize_rigid_body_mass->>_randomize_prop_by_op: Apply randomization (add/scale/abs)
    _randomize_prop_by_op-->>randomize_rigid_body_mass: Return randomized masses
    randomize_rigid_body_mass->>randomize_rigid_body_mass: Clamp masses to min=1e-6
    Note over randomize_rigid_body_mass: Prevents zero/negative masses
    randomize_rigid_body_mass->>PhysX: Set masses
    alt recompute_inertia=True
        randomize_rigid_body_mass->>randomize_rigid_body_mass: Calculate mass ratios
        randomize_rigid_body_mass->>randomize_rigid_body_mass: Scale inertia tensors
        randomize_rigid_body_mass->>PhysX: Set inertias
    end
Loading

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@@ -360,6 +360,7 @@ def __call__(
masses = _randomize_prop_by_op(
masses, mass_distribution_params, env_ids, body_ids, operation=operation, distribution=distribution
)
masses = torch.clamp(masses, min=1e-6) # ensure masses are positive

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe good to have as an arg?

@jtigue-bdai
jtigue-bdai force-pushed the jat/fix/prevent_randomizing_mass_negative branch from 28f9c7c to 5b44405 Compare December 1, 2025 19:01
@kellyguo11 kellyguo11 moved this to In review in Isaac Lab Dec 8, 2025
@kellyguo11 kellyguo11 changed the title Prevent randomizing mass to zero or less Prevents randomizing mass to zero or less Dec 11, 2025
@kellyguo11
kellyguo11 merged commit c1ad81d into isaac-sim:main Dec 11, 2025
@github-project-automation github-project-automation Bot moved this from In review to Done in Isaac Lab Dec 11, 2025
T-K-233 pushed a commit to ucb-bar/IsaacLab that referenced this pull request Dec 29, 2025
# Description

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

Fixes isaac-sim#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: Kelly Guo <[email protected]>
Co-authored-by: Kelly Guo <[email protected]>
Edify0991 pushed a commit to Edify0991/IsaacLab that referenced this pull request Jan 14, 2026
# Description

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

Fixes isaac-sim#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: Kelly Guo <[email protected]>
Co-authored-by: Kelly Guo <[email protected]>
nitesh-subedi pushed a commit to nitesh-subedi/IsaacLab that referenced this pull request Feb 5, 2026
# Description

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

Fixes isaac-sim#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: Kelly Guo <[email protected]>
Co-authored-by: Kelly Guo <[email protected]>
csj-275 pushed a commit to csj-275/IsaacLab that referenced this pull request Jul 8, 2026
# Description

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

Fixes isaac-sim#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: Kelly Guo <[email protected]>
Co-authored-by: Kelly Guo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working isaac-lab Related to Isaac Lab team

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Question] Only during training, encounter "PhysX error: PxRigidBody::setMass(): mass must be non-negative!" despite non-negative/non-zero masses

3 participants