Skip to content

Fix contact sensor activation for nested rigid bodies#6259

Merged
ooctipus merged 3 commits into
isaac-sim:developfrom
ooctipus:fix/activate-contact-sensors-nested-rigid-bodies
Jul 4, 2026
Merged

Fix contact sensor activation for nested rigid bodies#6259
ooctipus merged 3 commits into
isaac-sim:developfrom
ooctipus:fix/activate-contact-sensors-nested-rigid-bodies

Conversation

@ooctipus

Copy link
Copy Markdown
Collaborator

Summary

  • use get_all_matching_child_prims when activating PhysX contact report schemas
  • continue matching rigid descendants under nested rigid-body trees instead of stopping at the first rigid body
  • add regression coverage for nested rigid bodies receiving PhysxContactReportAPI

Testing

  • ./isaaclab.sh -p -m pytest source/isaaclab/test/sim/test_schemas.py -k activate_contact_sensors_nested_rigid_bodies -q
  • ./isaaclab.sh -p -m py_compile source/isaaclab/isaaclab/sim/schemas/schemas.py source/isaaclab/test/sim/test_schemas.py

Note

  • Attempted ./isaaclab.sh -p -m pytest source/isaaclab_physx/test/sensors/test_contact_sensor.py -k contact_sensor_threshold -q, but collection failed because flaky is not installed in the local environment.

@github-actions github-actions Bot added bug Something isn't working isaac-lab Related to Isaac Lab team labels Jun 24, 2026
@greptile-apps

greptile-apps Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes activate_contact_sensors to correctly apply PhysxContactReportAPI to all rigid bodies in a nested hierarchy by replacing a hand-written BFS that stopped traversal at the first rigid body found with get_all_matching_child_prims, which continues into children of matched prims.

  • schemas.py: Replaces the manual traversal (which skipped children of rigid bodies) with get_all_matching_child_prims, enabling activation for nested rigid-body trees. The num_contact_sensors counter is removed in favor of checking if not rigid_body_prims.
  • test_schemas.py: Adds a new regression test that builds a 3-level nested rigid-body hierarchy (pelvis → left_hip → left_knee) and asserts all three prims receive PhysxRigidBodyAPI, PhysxContactReportAPI, and correct attribute values.

Confidence Score: 5/5

Safe to merge — the change is a targeted, well-scoped fix with a direct regression test.

The old manual traversal was deliberately stopping at rigid-body prims and never enqueuing their children, which is exactly the bug being fixed. The replacement get_all_matching_child_prims already used elsewhere in the same file always continues traversal past matched nodes, so nested rigid bodies are now discovered. The per-prim schema-application logic is untouched. The new test constructs the exact hierarchy that previously broke and asserts all three levels receive the correct schemas and attribute values.

No files require special attention.

Important Files Changed

Filename Overview
source/isaaclab/isaaclab/sim/schemas/schemas.py Replaces manual BFS with get_all_matching_child_prims; correctly traverses nested rigid-body trees. Import was already present. Logic for applying schemas per-prim is unchanged.
source/isaaclab/test/sim/test_schemas.py Adds test_activate_contact_sensors_nested_rigid_bodies covering a 3-deep rigid-body chain; all required imports (UsdPhysics, pytest) are already present.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["activate_contact_sensors(prim_path)"] --> B["Validate prim"]
    B --> C["get_all_matching_child_prims\n(predicate: HasAPI RigidBodyAPI)"]
    C --> D{Full BFS traversal\nof all descendants}
    D -->|prim matches| E["Add to output list\n+ continue into children"]
    D -->|prim doesn't match| F["Continue into children"]
    E --> D
    F --> D
    D -->|queue empty| G["rigid_body_prims list"]
    G -->|empty| H["Warning: no rigid bodies found"]
    G -->|not empty| I["For each rigid body prim"]
    I --> J["Ensure PhysxRigidBodyAPI\nsleepThreshold = 0.0"]
    J --> K["Ensure PhysxContactReportAPI\nthreshold = user value"]
    K --> I
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A["activate_contact_sensors(prim_path)"] --> B["Validate prim"]
    B --> C["get_all_matching_child_prims\n(predicate: HasAPI RigidBodyAPI)"]
    C --> D{Full BFS traversal\nof all descendants}
    D -->|prim matches| E["Add to output list\n+ continue into children"]
    D -->|prim doesn't match| F["Continue into children"]
    E --> D
    F --> D
    D -->|queue empty| G["rigid_body_prims list"]
    G -->|empty| H["Warning: no rigid bodies found"]
    G -->|not empty| I["For each rigid body prim"]
    I --> J["Ensure PhysxRigidBodyAPI\nsleepThreshold = 0.0"]
    J --> K["Ensure PhysxContactReportAPI\nthreshold = user value"]
    K --> I
Loading

Reviews (1): Last reviewed commit: "Fix contact sensor activation for nested..." | Re-trigger Greptile

@ooctipus
ooctipus force-pushed the fix/activate-contact-sensors-nested-rigid-bodies branch from f3c2201 to 2e853b0 Compare July 2, 2026 03:44
@ooctipus
ooctipus merged commit 17136c6 into isaac-sim:develop Jul 4, 2026
59 of 61 checks passed
@ooctipus
ooctipus deleted the fix/activate-contact-sensors-nested-rigid-bodies branch July 4, 2026 10:55
hujc7 added a commit that referenced this pull request Jul 17, 2026
…erarchy assets (#6377)

# Description

Spawning an asset whose rigid bodies are nested (child link prims
authored under their parent link prim, as produced by the URDF importer
in Isaac Sim 6.0 and later) only applied `rigid_props` and `mass_props`
to the first link: the `apply_nested` decorator stops descending into a
prim's children once the wrapped function succeeds, assuming physics
schemas cannot nest. On a 29-link arm, `disable_gravity=True` reached
1/29 bodies with no warning.

This completes the nested-hierarchy fix started in #6259 (which covered
contact-sensor activation):

- `apply_nested` gains a `stop_on_success` flag (default `True`; the
dual-form decorator keeps every existing bare `@apply_nested` usage
working unchanged).
- `modify_rigid_body_properties` and `modify_mass_properties` opt out of
the early stop, since their anchor prims are exactly the link prims that
nest.
- Regression test with a 3-deep nested rigid-body chain verifying both
properties land on every body (mirrors the #6259 test).

## Scope: why only the rigid-body and mass writers

An audit of the 40 asset stages referenced by
`isaaclab_assets`/`isaaclab_tasks` informed the scoping:

1. Rigid-body nesting is the only *independent-anchor* nesting in use:
`ShadowHandNewton` authors 24 of its 25 links body-under-body and is
spawned with `rigid_props` by the shadow-hand task — this fix is
required for those values to reach every link.
2. No joint-under-joint nesting and no nested articulation roots exist
in any audited asset; keeping the early stop for those writers is safe.
3. Collider-under-collider exists only as duplicated same-intent anchors
in a few props (e.g. the factory gear assets author `CollisionAPI` with
SDF approximation on two ancestor Xforms of the same meshes, via layer
composition). Those anchors describe the *same* geometry rather than
independent colliders — the USD Physics spec ties `CollisionAPI` to leaf
gprims, so nested Xform-level anchors have no defined precedence.
Widening the traversal there would paper over an asset-level duplication
instead of fixing schema application, so the collision writers keep the
early stop; the asset duplication is being followed up separately.
4. Some flat assets (e.g. Franka) author `MassAPI` on both link prims
and mesh prims beneath them. With this change `mass_props` now also
authors the nested `MassAPI` prims; per the [USD Physics
spec](https://openusd.org/release/wp_rigid_body_physics.html), a
parent's explicit mass overrides mass properties authored further down
the subtree, so effective per-body mass is unchanged.

## Behavior note

The Newton shadow-hand task cfg sets `disable_gravity=True` (and related
rigid-body properties) that previously reached only 1 of 25 links. With
this fix the cfg applies to all 25 links as intended. This is the bug
being fixed, but baselines tuned against the old (partial) behavior may
shift for tasks whose assets have nested links.

## Verification

- End-to-end through the spawner (`UsdFileCfg` → the same
property-application path `UrdfFileCfg` uses) on a nested
Geometry-scoped 3-link chain: `disable_gravity` and `mass` author on 1/3
bodies before the fix and 3/3 after; contact-report API 3/3 on both (via
#6259).
- New regression test in `test_schemas.py` (nested chain, asserts both
properties on every link).
- Full CI green (34/34 checks).

Fixes #5918

## Type of change

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

## Checklist

- [x] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [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
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] I have added a changelog fragment under
`source/<pkg>/changelog.d/` for every touched package (do **not** edit
`CHANGELOG.rst` or bump `extension.toml` — CI handles that)
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there
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.

2 participants