Skip to content

Adds newton contact sensor - #4716

Merged
AntoineRichard merged 4 commits into
isaac-sim:developfrom
camevor:ca/newton-contact-sensor
Feb 26, 2026
Merged

AntoineRichard merged 4 commits into
isaac-sim:developfrom
camevor:ca/newton-contact-sensor

Conversation

@camevor

@camevor camevor commented Feb 25, 2026

Copy link
Copy Markdown
Contributor

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.
List any dependencies that are required for this change.

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (existing functionality will not work without user modification)
  • Documentation update

Screenshots

Please attach before and after screenshots of the change if applicable.

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 the isaac-lab Related to Isaac Lab team label Feb 25, 2026
@greptile-apps

greptile-apps Bot commented Feb 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds Newton backend support for contact sensors with shape-level sensing capabilities. Refactors the base contact sensor interface to support multiple backends (PhysX and Newton) through abstract methods, adds num_instances property, and improves null handling for filter_prim_paths_expr.

Key changes:

  • New isaaclab_newton.sensors.contact_sensor module with Newton-specific implementation using warp kernels
  • NewtonContactSensorCfg extends base config with shape-level sensing (sensor_shape_prim_expr) and filtering (filter_shape_prim_expr)
  • Base interface refactored with proper abstract methods, improved error messages, and _create_buffers() abstraction
  • PhysX implementation updated to handle optional filter_prim_paths_expr (changed from list to list | None)
  • Factory pattern in ContactSensor now creates Newton or PhysX instances based on backend

The implementation follows the existing pattern established by the PhysX backend and properly integrates with the factory-based architecture.

Confidence Score: 4/5

  • Safe to merge with minor fix needed for error message accuracy
  • Implementation follows established patterns and properly extends the base interface. One syntax issue found in error message that should be corrected. The refactoring maintains backward compatibility while adding Newton backend support.
  • source/isaaclab_newton/isaaclab_newton/sensors/contact_sensor/contact_sensor.py needs the error message fix on line 302

Important Files Changed

Filename Overview
source/isaaclab/isaaclab/sensors/contact_sensor/base_contact_sensor.py Refactored to make abstract interface more explicit with proper error messages and added num_instances, _create_buffers, and reset with env_mask support
source/isaaclab_newton/isaaclab_newton/sensors/contact_sensor/contact_sensor.py New Newton-based contact sensor implementation with shape-level sensing, warp kernels for data processing, and conversion from base config
source/isaaclab_newton/isaaclab_newton/sensors/contact_sensor/contact_sensor_kernels.py New warp kernels for copying Newton data, resetting buffers, updating history/time tracking, and computing first transitions
source/isaaclab_physx/isaaclab_physx/sensors/contact_sensor/contact_sensor.py Fixed null handling for optional filter_prim_paths_expr to avoid iteration errors

Class Diagram

%%{init: {'theme': 'neutral'}}%%
classDiagram
    class BaseContactSensor {
        <<abstract>>
        +num_instances int
        +data BaseContactSensorData
        +num_sensors int
        +body_names list
        +contact_view
        +reset(env_ids, env_mask)
        +compute_first_contact(dt) wp.array
        +compute_first_air(dt) wp.array
        +_initialize_impl()*
        +_create_buffers()*
        +_update_buffers_impl(env_mask)*
    }
    
    class ContactSensor {
        <<factory>>
        +__new__() BaseContactSensor
    }
    
    class NewtonContactSensor {
        +cfg NewtonContactSensorCfg
        +data ContactSensorData
        +sensor_names list
        +filter_object_names list
        +contact_view NewtonContactSensor
        +_create_buffers()
        +_update_buffers_impl(env_mask)
    }
    
    class PhysXContactSensor {
        +cfg ContactSensorCfg
        +body_names list
        +contact_view RigidContactView
        +_create_buffers()
        +_update_buffers_impl(env_mask)
    }
    
    class NewtonContactSensorCfg {
        +sensor_shape_prim_expr list
        +filter_shape_prim_expr list
        +from_base_cfg(base_cfg) NewtonContactSensorCfg
    }
    
    class ContactSensorCfg {
        +filter_prim_paths_expr list|None
        +track_air_time bool
        +track_pose bool
    }
    
    BaseContactSensor <|-- NewtonContactSensor
    BaseContactSensor <|-- PhysXContactSensor
    ContactSensor ..> BaseContactSensor : creates
    ContactSensor ..> NewtonContactSensor : creates
    ContactSensor ..> PhysXContactSensor : creates
    NewtonContactSensor --> NewtonContactSensorCfg
    PhysXContactSensor --> ContactSensorCfg
    NewtonContactSensorCfg --|> ContactSensorCfg
Loading

Last reviewed commit: a0524ac

@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.

11 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Co-authored-by: Antoine RICHARD <[email protected]>
@camevor
camevor force-pushed the ca/newton-contact-sensor branch from 8f37302 to 56eaf45 Compare February 25, 2026 09:09

@AntoineRichard AntoineRichard left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Aside from the init it looks good to me.

Comment on lines +25 to +34
| Camera | /World/robot/base/camera | Leaf is available, and it will spawn a USD camera |
+---------------------+---------------------------+---------------------------------------------------------------+
| Contact Sensor | /World/robot/feet_* | Leaf is available and checks if the schema exists |
+---------------------+---------------------------+---------------------------------------------------------------+
| Ray Caster | /World/robot/base | Leaf exists and is a physics body (Articulation / Rigid Body) |
+---------------------+---------------------------+---------------------------------------------------------------+
| Frame Transformer | /World/robot/base | Leaf exists and is a physics body (Articulation / Rigid Body) |
+---------------------+---------------------------+---------------------------------------------------------------+
| Imu | /World/robot/base | Leaf exists and is a physics body (Rigid Body) |
+---------------------+---------------------------+---------------------------------------------------------------+

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Might want to shrink that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, done

"""Number of past frames to store in the sensor buffers. Defaults to 0, which means that only
the current data is stored (no history)."""

filter_prim_paths_expr: list[str] | None = None

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This leads to test failures in PhysX. I had to change some code to:

if (self.cfg.filter_prim_paths_expr is not None) and len(self.cfg.filter_prim_paths_expr) > 0:

to make the tests pass. Could there be an error with the logic somewhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, fixed

net_forces_flat = self.contact_view.get_net_contact_forces(dt=self._sim_physics_dt).view(wp.vec3f)
# PhysX returns (N*B, M, 3) float32 -> (N*B, M) vec3f
if len(self.cfg.filter_prim_paths_expr) != 0:
if self.cfg.filter_prim_paths_expr is not None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

if (self.cfg.filter_prim_paths_expr is not None) and len(self.cfg.filter_prim_paths_expr) > 0:

@AntoineRichard

Copy link
Copy Markdown
Collaborator

Also getting a bunch more errors:

FAILED source/isaaclab_physx/test/sensors/test_contact_sensor.py::test_sensor_print - TypeError: 'NoneType' object is not iterable
FAILED source/isaaclab_physx/test/sensors/test_contact_sensor.py::test_contact_sensor_threshold[cuda:0] - TypeError: 'NoneType' object is not iterable
FAILED source/isaaclab_physx/test/sensors/test_contact_sensor.py::test_contact_sensor_threshold[cpu] - TypeError: 'NoneType' object is not iterable
FAILED source/isaaclab_physx/test/sensors/test_contact_sensor.py::test_invalid_prim_paths_config - AssertionError: Expected ValueError due to invalid contact sensor configuration.

@AntoineRichard AntoineRichard left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tests are looking good!

@AntoineRichard
AntoineRichard merged commit af8f013 into isaac-sim:develop Feb 26, 2026
7 of 10 checks passed
kellyguo11 pushed a commit that referenced this pull request Sep 7, 2026
… ages (#7574)

# Description

`ContactSensor.compute_first_contact(dt)` / `compute_first_air(dt)`
silently missed most touchdowns and lift-offs once the simulation had
run for a few seconds. On a transition step the contact (resp. air)
timer is exactly one sensor update interval, so the check degenerated to
`dt < dt + 1e-8`. The sensor clock is a float32 accumulator whose
rounding error reaches ~1e-6 after a few seconds of simulated time,
roughly 100x the default tolerance, so the events vanished depending on
the magnitude of the sim clock. The reporter's CPU reproducer shows
352/500 touchdowns and lift-offs missed at the default tolerance; it
reproduces exactly on `develop`. All three backends (Newton, PhysX,
OVPhysX) share the same logic, and the 2.x torch sensor had the same
defect, so this is long-standing rather than a Newton regression.

**Fix.** `abs_tol` now defaults to `None` and is resolved at call time
by a single helper in `BaseContactSensor` to **half the sensor update
interval**, i.e. `0.5 * max(cfg.update_period, physics_dt)`. Valid timer
values are integer multiples of that interval, so half an interval is
the midpoint between "one update ago" and "two updates ago". This stays
robust to float32 clock drift for hours of simulated time and works for
both `history_length == 0` (lazy, once-per-policy-step refresh) and
`history_length > 0` (every physics substep). The Warp kernels are
unchanged. Passing an explicit `abs_tol` still works; callers who want
the previous behaviour can pass `abs_tol=1e-8`.

**Tests.** Public-API regression tests in the Newton, PhysX and OVPhysX
contact sensor suites: settle a body in contact, age the sensor clock to
2.5 / 10 / 30 s, lift and land the body, and poll
`compute_first_contact` / `compute_first_air` with default arguments.
These fail on the unfixed code (e.g. `compute_first_air missed the
lift-off at clock 2.833s: reported [], expected [0]`) and pass with the
fix. The Newton variant covers both `history_length` modes.

**Refresh before query.** Both methods now call the sensor's
outdated-buffer refresh before comparing, restoring what the 2.x torch
sensor did by reading through `self.data`. The Warp port (#4707 / #4716)
read the private timer buffer directly, so a `history_length == 0`
caller that polled before touching `data` saw the previous step's
timers. The aged-clock tests now poll before reading `data`; the Newton
lazy-mode cases fail without the refresh (transition reported one policy
step late) and pass with it. Adopted from the approach in #7294.

**Out of scope, noted for follow-up.**
- The transition interval is counted in both the ending and the starting
phase, so `last_air_time` / `last_contact_time` overestimate each phase
by one update interval (also raised in the issue). That bias is present
since 2.x and baked into tuned `feet_air_time` thresholds, so changing
it would rescale rewards for trained velocity policies and deserves its
own PR.
- On `cuda:0` with `history_length == 0`, the PhysX and OVPhysX sensors
serve stale net forces when buffers refresh only on data access,
independently of this change. That is why the PhysX/OVPhysX public-API
tests cover only the substep cadence.

Fixes #7283

## Type of change

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

## Release backport

- [x] <!-- backport-active-release --> Backport this pull request to the
active release branch after it merges into `develop`

## 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`
- [x] 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
isaaclab-bot Bot pushed a commit that referenced this pull request Sep 7, 2026
… ages (#7574)

# Description

`ContactSensor.compute_first_contact(dt)` / `compute_first_air(dt)`
silently missed most touchdowns and lift-offs once the simulation had
run for a few seconds. On a transition step the contact (resp. air)
timer is exactly one sensor update interval, so the check degenerated to
`dt < dt + 1e-8`. The sensor clock is a float32 accumulator whose
rounding error reaches ~1e-6 after a few seconds of simulated time,
roughly 100x the default tolerance, so the events vanished depending on
the magnitude of the sim clock. The reporter's CPU reproducer shows
352/500 touchdowns and lift-offs missed at the default tolerance; it
reproduces exactly on `develop`. All three backends (Newton, PhysX,
OVPhysX) share the same logic, and the 2.x torch sensor had the same
defect, so this is long-standing rather than a Newton regression.

**Fix.** `abs_tol` now defaults to `None` and is resolved at call time
by a single helper in `BaseContactSensor` to **half the sensor update
interval**, i.e. `0.5 * max(cfg.update_period, physics_dt)`. Valid timer
values are integer multiples of that interval, so half an interval is
the midpoint between "one update ago" and "two updates ago". This stays
robust to float32 clock drift for hours of simulated time and works for
both `history_length == 0` (lazy, once-per-policy-step refresh) and
`history_length > 0` (every physics substep). The Warp kernels are
unchanged. Passing an explicit `abs_tol` still works; callers who want
the previous behaviour can pass `abs_tol=1e-8`.

**Tests.** Public-API regression tests in the Newton, PhysX and OVPhysX
contact sensor suites: settle a body in contact, age the sensor clock to
2.5 / 10 / 30 s, lift and land the body, and poll
`compute_first_contact` / `compute_first_air` with default arguments.
These fail on the unfixed code (e.g. `compute_first_air missed the
lift-off at clock 2.833s: reported [], expected [0]`) and pass with the
fix. The Newton variant covers both `history_length` modes.

**Refresh before query.** Both methods now call the sensor's
outdated-buffer refresh before comparing, restoring what the 2.x torch
sensor did by reading through `self.data`. The Warp port (#4707 / #4716)
read the private timer buffer directly, so a `history_length == 0`
caller that polled before touching `data` saw the previous step's
timers. The aged-clock tests now poll before reading `data`; the Newton
lazy-mode cases fail without the refresh (transition reported one policy
step late) and pass with it. Adopted from the approach in #7294.

**Out of scope, noted for follow-up.**
- The transition interval is counted in both the ending and the starting
phase, so `last_air_time` / `last_contact_time` overestimate each phase
by one update interval (also raised in the issue). That bias is present
since 2.x and baked into tuned `feet_air_time` thresholds, so changing
it would rescale rewards for trained velocity policies and deserves its
own PR.
- On `cuda:0` with `history_length == 0`, the PhysX and OVPhysX sensors
serve stale net forces when buffers refresh only on data access,
independently of this change. That is why the PhysX/OVPhysX public-API
tests cover only the substep cadence.

Fixes #7283

## Type of change

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

## Release backport

- [x] <!-- backport-active-release --> Backport this pull request to the
active release branch after it merges into `develop`

## 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`
- [x] 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

(cherry picked from commit 4cf35cc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants