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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions habitat-lab/habitat/sims/habitat_simulator/habitat_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
VisualObservation,
)
from habitat.core.spaces import Space
from habitat_sim.physics import ContactPointData

if TYPE_CHECKING:
from torch import Tensor
Expand Down Expand Up @@ -306,6 +307,9 @@ def __init__(self, config: DictConfig) -> None:
)
self._prev_sim_obs: Optional[Observations] = None

self._contact_point_cache_time = 0.0
self._contact_point_cache: List[ContactPointData] = []

def create_sim_config(
self, _sensor_suite: SensorSuite
) -> habitat_sim.Configuration:
Expand Down Expand Up @@ -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.

if not contact_points_dirty:
return self._contact_point_cache
else:
self._contact_point_cache = super().get_physics_contact_points()
self._contact_point_cache_time = sim_time
return self._contact_point_cache

def distance_to_closest_obstacle(
self, position: np.ndarray, max_search_radius: float = 2.0
) -> float:
Expand Down