Skip to content

[Newton] Splits the Contact Sensor Configurations into base and Newton#4708

Open
camevor wants to merge 6 commits intoisaac-sim:dev/newtonfrom
camevor:ca/contact-sensor-config
Open

[Newton] Splits the Contact Sensor Configurations into base and Newton#4708
camevor wants to merge 6 commits intoisaac-sim:dev/newtonfrom
camevor:ca/contact-sensor-config

Conversation

@camevor
Copy link

@camevor camevor commented Feb 24, 2026

Description

Separate NewtonContactSensorCfg with shape-level fields, rename base config fields for consistency, a
nd resolve regex expressions to integer indices in add_contact_sensor instead of passing raw patterns
through match_fn.

  • Extract NewtonContactSensorCfg into its own file with shape-level fields (sensor_shape_prim_expr, filter_shape_prim_expr), sensor_body_prim_expr property alias, from_base_cfg factory, and __post_init__ guards for unsupported options
  • Rename base ContactSensorCfg fields: filter_prim_paths_exprfilter_body_prim_expr, drop shape_path and filter_shape_paths_expr (moved to Newton subclass)
  • Resolve regex expressions to list[int] indices in add_contact_sensor via resolve_matching_names, removing flipped_match / match_fn
  • Simplify ContactSensor._initialize_impl — pass cfg fields directly instead of building joined regex strings
  • Update interactive_scene.py env-regex expansion to use renamed fields
  • Update docstring references in contact_sensor_data.py

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

- Extract NewtonContactSensorCfg into its own file with shape-level fields (sensor_shape_prim_expr,
filter_shape_prim_expr), sensor_body_prim_expr property alias, from_base_cfg factory, and __post_init__
guards for unsupported options
- Rename base ContactSensorCfg fields: filter_prim_paths_expr → filter_body_prim_expr, drop shape_path and
filter_shape_paths_expr (moved to Newton subclass)
- Resolve regex expressions to list[int] indices in add_contact_sensor via resolve_matching_names, removing
 flipped_match / match_fn
- Simplify ContactSensor._initialize_impl — pass cfg fields directly instead of building joined regex
strings
- Update interactive_scene.py env-regex expansion to use renamed fields
- Update docstring references in contact_sensor_data.py
@github-actions github-actions bot added the isaac-lab Related to Isaac Lab team label Feb 24, 2026
@camevor camevor self-assigned this Feb 24, 2026
@camevor camevor marked this pull request as ready for review February 24, 2026 15:49
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 24, 2026

Greptile Summary

Refactors contact sensor configuration to separate base (body-level) and Newton (shape-level) implementations, renames config fields for consistency (filter_prim_paths_expr replaces previous naming), and resolves regex expressions to integer indices in add_contact_sensor.

Key Changes:

  • Extracts NewtonContactSensorCfg into separate file with shape-level fields (sensor_shape_prim_expr, filter_shape_prim_expr)
  • Renames base ContactSensorCfg field and removes shape-level options (moved to Newton subclass)
  • Resolves regex expressions to list[int] indices via resolve_matching_names instead of passing raw patterns to Newton
  • Updates Newton API usage: body_keybody_label, shape_keyshape_label, eval()update()
  • Adds from_base_cfg factory method for converting base config to Newton config
  • Updates environment regex expansion in interactive_scene.py

Issues Found:

  • Missing f-string prefix in TypeError message (line 71 of contact_sensor.py)
  • Missing environment regex expansion for sensor_shape_prim_expr in interactive_scene.py

Confidence Score: 4/5

  • Safe to merge after fixing the two identified issues
  • Well-structured refactoring with clear separation of concerns and proper API updates. However, two bugs need fixing: missing f-string prefix causing incorrect error message, and missing env regex expansion that could break shape-level sensor configuration
  • Fix contact_sensor.py:71 (f-string) and interactive_scene.py:622-625 (add sensor_shape_prim_expr expansion) before merging

Important Files Changed

Filename Overview
source/isaaclab/isaaclab/sensors/contact_sensor/contact_sensor_cfg.py Renames filter_prim_paths_expr field, removes shape-level fields, adds new config options, updates docs to clarify body-level only support
source/isaaclab_newton/isaaclab_newton/sensors/contact_sensor/contact_sensor_cfg.py New file introducing NewtonContactSensorCfg with shape-level support, from_base_cfg factory, and proper validation in __post_init__
source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py Replaces regex-based matching with resolved integer indices, removes flipped_match function, updates Newton API usage (evalupdate), adds return type for add_contact_sensor
source/isaaclab_newton/isaaclab_newton/sensors/contact_sensor/contact_sensor.py Auto-converts ContactSensorCfg to NewtonContactSensorCfg, simplifies _initialize_impl, updates Newton API usage. Has syntax error in TypeError message (line 71)
source/isaaclab/isaaclab/scene/interactive_scene.py Updates env regex expansion for renamed fields, but missing expansion for sensor_shape_prim_expr

Class Diagram

%%{init: {'theme': 'neutral'}}%%
classDiagram
    class ContactSensorCfg {
        +str prim_path
        +list[str] filter_prim_paths_expr
        +bool track_air_time
        +float force_threshold = 1.0
        Body-level sensing only
    }
    
    class NewtonContactSensorCfg {
        +list[str] sensor_shape_prim_expr
        +list[str] filter_shape_prim_expr
        +float force_threshold = 0.0
        +sensor_body_prim_expr property
        +from_base_cfg() classmethod
        +__post_init__()
        Shape-level sensing support
    }
    
    class NewtonManager {
        +add_contact_sensor(body_names_expr, shape_names_expr, contact_partners_body_expr, contact_partners_shape_expr)
        Resolves regex to list[int] indices
    }
    
    class ContactSensor {
        +__init__(cfg)
        Auto-converts ContactSensorCfg
    }
    
    ContactSensorCfg <|-- NewtonContactSensorCfg : extends
    NewtonContactSensorCfg --> ContactSensor : configures
    ContactSensor --> NewtonManager : uses add_contact_sensor()
    NewtonManager --> NewtonContactSensor : creates Newton sensor with indices
Loading

Last reviewed commit: 241caa0

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.

11 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines 53 to 71
cfg: NewtonContactSensorCfg
"""The configuration parameters."""

def __init__(self, cfg: ContactSensorCfg):
def __init__(self, cfg: ContactSensorCfg | NewtonContactSensorCfg):
"""Initializes the contact sensor object.

Args:
cfg: The configuration parameters.
"""
# initialize base class
from isaaclab.sensors.contact_sensor.contact_sensor_cfg import ContactSensorCfg

from .contact_sensor_cfg import NewtonContactSensorCfg

if isinstance(cfg, NewtonContactSensorCfg):
pass
elif isinstance(cfg, ContactSensorCfg):
cfg = NewtonContactSensorCfg.from_base_cfg(cfg)
else:
raise TypeError("Invalid config: {cfg}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might need to add:

        # check if max_contact_data_count_per_prim is set
        if self.cfg.max_contact_data_count_per_prim is not None:
            raise ValueError("Newton doesn't use max_contact_data_count_per_prim, setting this parameter has no impact on the simulation.")

        # check if force_threshold is set
        if self.cfg.force_threshold is None:
            self.cfg.force_threshold = 0.0

Copy link
Collaborator

Choose a reason for hiding this comment

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

No sure if the raise is not a bit too violent. A warning might be enough.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, the if self.cfg.force_threshold is None: self.cfg.force_threshold = 0.0 is not needed nevermind that. You apply the overload.

Copy link
Author

Choose a reason for hiding this comment

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

The data count per prim is handled in the NewtonContactSensorCfg's __post_init__. Will handle the force here though 👍

@camevor camevor force-pushed the ca/contact-sensor-config branch from 3805d55 to 589af7a Compare February 24, 2026 16:13
@camevor camevor changed the title Contact Sensor CFG split [Newton] Splits the Contact Sensor Configurations into base and Newton Feb 24, 2026
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