Skip to content

[FEATURE] Add filter_link_idx to ContactForceSensor (#2771)#2856

Open
yeezhouyi wants to merge 3 commits into
Genesis-Embodied-AI:mainfrom
yeezhouyi:feature/contact-force-filter-link-idx
Open

[FEATURE] Add filter_link_idx to ContactForceSensor (#2771)#2856
yeezhouyi wants to merge 3 commits into
Genesis-Embodied-AI:mainfrom
yeezhouyi:feature/contact-force-filter-link-idx

Conversation

@yeezhouyi
Copy link
Copy Markdown

Summary

  • Add filter_link_idx parameter to gs.sensors.ContactForce, mirroring the existing ContactSensor.filter_link_idx feature from [FEATURE] Add history_length to Sensors #2655.
  • Filters out contact forces where the other participant in the collision is one of the specified links, keeping only forces from interactions with non-filtered geometries.

Implementation

  • genesis/options/sensors/options.py: Added filter_link_idx: OptionalIArrayType field to ContactForce options class with scene validation.
  • genesis/engine/sensors/contact_force.py: Added filter_links_idx and filtered_sensor_idx metadata tensors; processing logic in the zero-copy _update_raw_data path.

Test plan

  • Existing sensor tests pass: pytest tests/test_rigid_sensors.py -x -v
  • The test_contact_sensors_gravity_force[0] failure is pre-existing on main (int64 dtype issue, unrelated to these changes).

…-AI#2771)

Adds `filter_link_idx` parameter to `gs.sensors.ContactForce`, mirroring
the existing `ContactSensor.filter_link_idx`. Contacts whose counterpart
link is in the filter list are excluded from the reported force.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 353a252a23

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

force_mask_b = link_b[:, None] == shared_metadata.links_idx[None, :, None]
force_mask = force_mask_b.to(dtype=gs.tc_float) - force_mask_a.to(dtype=gs.tc_float)
# Apply filter_link_idx: zero out contacts where the counterpart link is in the filter list.
if shared_metadata.filtered_sensor_idx.numel() > 0:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Apply contact-force filters outside zerocopy

When GS_ENABLE_ZEROCOPY=0 or zero-copy is unsupported for the selected backend/device, this new filter is never applied: the else branch still calls _kernel_get_contacts_forces with only links_idx, so filter_link_idx is accepted by options/build but contact forces from filtered counterpart links are still included. Users running those configurations will get different sensor readings for the same ContactForce(filter_link_idx=...) setup.

Useful? React with 👍 / 👎.

yeezhouyi and others added 2 commits May 28, 2026 12:37
…nesis-Embodied-AI#2771)

The filter_link_idx feature was only implemented in the zerocopy (PyTorch)
path. The quadrants kernel _kernel_get_contacts_forces ignored the filter,
so users with GS_ENABLE_ZEROCOPY=0 or backends without zerocopy support
would get different sensor readings for the same ContactForce setup.
Fix by adding filter_links_idx parameter to the kernel and checking the
filter before accumulating forces for each contact-sensor pair.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…th (Genesis-Embodied-AI#2771)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant