Skip to content

Conversation

@jtigue-bdai
Copy link
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
Copy link
Contributor

greptile-apps bot commented Nov 21, 2025

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

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

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

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

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

None yet

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

2 participants