-
Notifications
You must be signed in to change notification settings - Fork 1
add contact fetching #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds contact fetching functionality for rigid objects and articulation links in the simulation. The implementation provides a filtering mechanism to retrieve contact information from physics simulations, including contact positions, normals, friction forces, impulses, and distances. The PR includes a new ContactReport data structure, configuration classes for filtering contacts, and methods in SimulationManager to fetch and filter contact data.
- Adds
ContactReportdataclass andContactFilterCfgconfiguration for managing contact queries - Implements
get_contact()method inSimulationManagerwith GPU and CPU support - Provides an example script demonstrating rigid object contact fetching
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 19 comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/tutorials/sim/fetch_contact.py | New tutorial script demonstrating contact fetching for rigid objects |
| embodichain/lab/sim/contact.py | New ContactReport dataclass to store and filter contact data |
| embodichain/lab/sim/cfg.py | Adds ContactFilterCfg and ArticulationContactFilterCfg configuration classes |
| embodichain/lab/sim/sim_manager.py | Implements get_contact() method and internal contact buffer management |
| embodichain/lab/sim/objects/rigid_object.py | Adds all_env_ids property for accessing environment indices |
| embodichain/lab/sim/objects/articulation.py | Adds all_env_ids property and updates get_user_ids() signature to support link-specific queries |
| embodichain/lab/sim/objects/gizmo.py | Updates import from dexsim.render to dexsim.engine for GizmoController |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| This script demonstrates how to create a simulation scene using SimulationManager. | ||
| It shows the basic setup of simulation context, adding objects, and sensors. |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring is incorrect. This script demonstrates contact fetching, not general scene setup with sensors. Update to accurately describe the script's purpose.
| This script demonstrates how to create a simulation scene using SimulationManager. | |
| It shows the basic setup of simulation context, adding objects, and sensors. | |
| This script demonstrates how to fetch and process contact information between rigid objects | |
| in a simulation using SimulationManager. It shows how to set up the simulation, add objects, | |
| and retrieve contact reports for analysis. |
| contact_positions = contact_report.contact_data[:, 0:3] | ||
| contact_normals = contact_report.contact_data[:, 3:6] | ||
| contact_frictions = contact_report.contact_data[:, 6:9] | ||
| contact_impluses = contact_report.contact_data[:, 9] |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'impluses' to 'impulses'.
| contact_impluses = contact_report.contact_data[:, 9] | |
| contact_impulses = contact_report.contact_data[:, 9] |
| for link_name in link_names: | ||
| if link_name not in all_link_names: | ||
| logger.log_warning( | ||
| f"Link {link_name} not found in articulation {articulation_cfg.uid}." |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect attribute access. Should use articulation_cfg.articulation_uid instead of articulation_cfg.uid, as the field is named articulation_uid in ArticulationContactFilterCfg (line 1141).
| f"Link {link_name} not found in articulation {articulation_cfg.uid}." | |
| f"Link {link_name} not found in articulation {articulation_cfg.articulation_uid}." |
embodichain/lab/sim/cfg.py
Outdated
| all_link_names = articulation.link_names() | ||
| link_names = ( | ||
| all_link_names | ||
| if articulation_cfg.link_name_list is None |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition checks if link_name_list is None, but the default is an empty list [] (line 1144). This check will never be true. Change condition to if not articulation_cfg.link_name_list or update the default to None.
| if articulation_cfg.link_name_list is None | |
| if not articulation_cfg.link_name_list |
| (self.item_env_ids, articulation.all_env_ids) | ||
| ) | ||
|
|
||
| # build user_id to env_id map |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential runtime error if item_user_ids is empty. Add a check before computing max() to handle the case when no items are found, e.g., if self.item_user_ids.numel() == 0: return.
| # build user_id to env_id map | |
| # build user_id to env_id map | |
| if self.item_user_ids.numel() == 0: | |
| return |
| contact_user_ids = ( | ||
| contact_report.contact_user_ids | ||
| ) # user can use userid to identify which object the contact belongs to, using rigid_object.get_user_id() |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable contact_user_ids is not used.
| contact_user_ids = ( | |
| contact_report.contact_user_ids | |
| ) # user can use userid to identify which object the contact belongs to, using rigid_object.get_user_id() |
| contact_env_ids = ( | ||
| contact_report.contact_env_ids | ||
| ) # contact belongs to which environment |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable contact_env_ids is not used.
| contact_env_ids = ( | |
| contact_report.contact_env_ids | |
| ) # contact belongs to which environment |
| cube1 = sim.get_rigid_object("cube1") | ||
| filtered_contact_report = contact_report.filter_by_user_ids( | ||
| cube1.get_user_ids() | ||
| ) |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable filtered_contact_report is not used.
| ) | |
| ) | |
| # Example usage: print number of filtered contacts for cube1 | |
| n_filtered = filtered_contact_report.contact_data.shape[0] | |
| print(f"[INFO]: Filtered contacts for cube1: {n_filtered}") | |
| if n_filtered > 0: | |
| print(f"[INFO]: Filtered contact positions for cube1: {filtered_contact_report.contact_data[:, 0:3]}") |
|
|
||
| import argparse | ||
| import time | ||
| import torch |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'torch' is not used.
| import torch |
embodichain/lab/sim/objects/gizmo.py
Outdated
| PhysicalAttr, | ||
| ) | ||
| from dexsim.render import GizmoController | ||
| from dexsim.engine import GizmoController |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'GizmoController' is not used.
| from dexsim.engine import GizmoController |
Description
Support contact fetching for rigid object and articulation link.
scripts/tutorials/sim/fetch_contact.pyscripts/tutorials/sim/fetch_contact.pyTODO:
Type of change
Checklist
black .command to format the code base.