Repository navigation
Adds newton contact sensor - #4716
Conversation
Greptile SummaryAdds 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 Key changes:
The implementation follows the existing pattern established by the PhysX backend and properly integrates with the factory-based architecture. Confidence Score: 4/5
Important Files Changed
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
Last reviewed commit: a0524ac |
Co-authored-by: Antoine RICHARD <[email protected]>
8f37302 to
56eaf45
Compare
AntoineRichard
left a comment
There was a problem hiding this comment.
Aside from the init it looks good to me.
| | 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) | | ||
| +---------------------+---------------------------+---------------------------------------------------------------+ |
There was a problem hiding this comment.
Might want to shrink that
| """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 |
There was a problem hiding this comment.
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?
| 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: |
There was a problem hiding this comment.
if (self.cfg.filter_prim_paths_expr is not None) and len(self.cfg.filter_prim_paths_expr) > 0:
|
Also getting a bunch more errors: |
AntoineRichard
left a comment
There was a problem hiding this comment.
Tests are looking good!
… 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
… 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)
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
Screenshots
Please attach before and after screenshots of the change if applicable.
Checklist
pre-commitchecks with./isaaclab.sh --formatconfig/extension.tomlfileCONTRIBUTORS.mdor my name already exists there