Skip to content
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

Add simulator physics collision cache. #2080

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

0mdc
Copy link
Contributor

@0mdc 0mdc commented Sep 15, 2024

Motivation and Context

This adds a cache for the habitat-sim get_physics_contact_points() function.

This function is called multiple times a frame and is quite expensive.

On a reference single-learn HITL application, this improves the framerate from 11.3 to 13.8 FPS.

How Has This Been Tested

Tested locally + unit tests.

Types of changes

  • [Optimization]

Checklist

  • My code follows the code style of this project.
  • I have updated the documentation if required.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes if required.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Sep 15, 2024
@@ -696,6 +700,16 @@ def get_observations_at(
else:
return None

def get_physics_contact_points(self) -> List[ContactPointData]:
sim_time = self.get_world_time()
contact_points_dirty = sim_time != self._contact_point_cache_time
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add this as a member variable and set it to dirty on reset/reconfigure also. Those events will both reset time and change the scene state.

Copy link
Contributor

@aclegg3 aclegg3 left a comment

Choose a reason for hiding this comment

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

My other concern here is that moving objects will invalidate the cache and any calls to Simulator.perform_discrete_collision_detection will be missed.
Perhaps you want to override that function also to modify the dirty flag.
I think at that point the likelihood of erroneous contact point data should be minimized.

@0mdc
Copy link
Contributor Author

0mdc commented Sep 16, 2024

My other concern here is that moving objects will invalidate the cache and any calls to Simulator.perform_discrete_collision_detection will be missed.

Shouldn't this function change the world time?

No, the role of this function is to run the collision detection procedure one time to update the internal caches which we query when calling the contact point getter. No physics are done by that function, so world time shouldn't change.

@0mdc 0mdc force-pushed the 0mdc/collision_cache branch from 7d6c734 to 83651fa Compare September 17, 2024 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants