Unverified Commit 9a2a877b authored by Mayank Mittal's avatar Mayank Mittal Committed by GitHub

Adds invalidation of physics handles when simulation is stopped (#332)

# Description

Since we now handle the PhysX views directly, we need to make sure they
are deleted properly when the simulation is stopped. This MR adds the
missing implementation for invalidating the views in all sensors and
asset classes.

## Type of change

- Bug fix (non-breaking change which fixes an issue)

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./orbit.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there
parent 333c5f2f
[package] [package]
# Note: Semantic Versioning is used: https://semver.org/ # Note: Semantic Versioning is used: https://semver.org/
version = "0.10.8" version = "0.10.9"
# Description # Description
title = "ORBIT framework for Robot Learning" title = "ORBIT framework for Robot Learning"
......
Changelog Changelog
--------- ---------
0.10.9 (2023-12-21)
~~~~~~~~~~~~~~~~~~~
Fixed
^^^^^
* Fixed invalidation of physics views inside the asset and sensor classes. Earlier, they were left initialized
even when the simulation was stopped. This caused issues when closing the application.
0.10.8 (2023-12-20) 0.10.8 (2023-12-20)
~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~
......
...@@ -383,3 +383,16 @@ class RigidObject(AssetBase): ...@@ -383,3 +383,16 @@ class RigidObject(AssetBase):
# -- heading direction of root # -- heading direction of root
forward_w = math_utils.quat_apply(self._data.root_quat_w, self.FORWARD_VEC_B) forward_w = math_utils.quat_apply(self._data.root_quat_w, self.FORWARD_VEC_B)
self._data.heading_w[:] = torch.atan2(forward_w[:, 1], forward_w[:, 0]) self._data.heading_w[:] = torch.atan2(forward_w[:, 1], forward_w[:, 0])
"""
Internal simulation callbacks.
"""
def _invalidate_initialize_callback(self, event):
"""Invalidates the scene elements."""
# call parent
super()._invalidate_initialize_callback(event)
# set all existing views to None to invalidate them
self._physics_sim_view = None
self._root_physx_view = None
self._body_physx_view = None
...@@ -554,3 +554,14 @@ class Camera(SensorBase): ...@@ -554,3 +554,14 @@ class Camera(SensorBase):
data = convert_to_torch(data, device=self.device) data = convert_to_torch(data, device=self.device)
# return the data and info # return the data and info
return data, info return data, info
"""
Internal simulation callbacks.
"""
def _invalidate_initialize_callback(self, event):
"""Invalidates the scene elements."""
# call parent
super()._invalidate_initialize_callback(event)
# set all existing views to None to invalidate them
self._view = None
...@@ -291,3 +291,16 @@ class ContactSensor(SensorBase): ...@@ -291,3 +291,16 @@ class ContactSensor(SensorBase):
frame_origins = pose.view(-1, self._num_bodies, 7)[:, :, :3] frame_origins = pose.view(-1, self._num_bodies, 7)[:, :, :3]
# visualize # visualize
self.contact_visualizer.visualize(frame_origins.view(-1, 3), marker_indices=marker_indices.view(-1)) self.contact_visualizer.visualize(frame_origins.view(-1, 3), marker_indices=marker_indices.view(-1))
"""
Internal simulation callbacks.
"""
def _invalidate_initialize_callback(self, event):
"""Invalidates the scene elements."""
# call parent
super()._invalidate_initialize_callback(event)
# set all existing views to None to invalidate them
self._physics_sim_view = None
self._body_physx_view = None
self._contact_physx_view = None
...@@ -351,3 +351,15 @@ class FrameTransformer(SensorBase): ...@@ -351,3 +351,15 @@ class FrameTransformer(SensorBase):
# Update the visualized markers # Update the visualized markers
if self.frame_visualizer is not None: if self.frame_visualizer is not None:
self.frame_visualizer.visualize(self._data.target_pos_w.view(-1, 3), self._data.target_rot_w.view(-1, 4)) self.frame_visualizer.visualize(self._data.target_pos_w.view(-1, 3), self._data.target_rot_w.view(-1, 4))
"""
Internal simulation callbacks.
"""
def _invalidate_initialize_callback(self, event):
"""Invalidates the scene elements."""
# call parent
super()._invalidate_initialize_callback(event)
# set all existing views to None to invalidate them
self._physics_sim_view = None
self._frame_physx_view = None
...@@ -279,3 +279,15 @@ class RayCaster(SensorBase): ...@@ -279,3 +279,15 @@ class RayCaster(SensorBase):
def _debug_vis_callback(self, event): def _debug_vis_callback(self, event):
# show ray hit positions # show ray hit positions
self.ray_visualizer.visualize(self._data.ray_hits_w.view(-1, 3)) self.ray_visualizer.visualize(self._data.ray_hits_w.view(-1, 3))
"""
Internal simulation callbacks.
"""
def _invalidate_initialize_callback(self, event):
"""Invalidates the scene elements."""
# call parent
super()._invalidate_initialize_callback(event)
# set all existing views to None to invalidate them
self._physics_sim_view = None
self._view = None
...@@ -201,7 +201,7 @@ class SimulationContext(_SimulationContext): ...@@ -201,7 +201,7 @@ class SimulationContext(_SimulationContext):
self._app_control_on_stop_handle = timeline_event_stream.create_subscription_to_pop_by_type( self._app_control_on_stop_handle = timeline_event_stream.create_subscription_to_pop_by_type(
int(omni.timeline.TimelineEventType.STOP), int(omni.timeline.TimelineEventType.STOP),
lambda *args, obj=weakref.proxy(self): obj._app_control_on_stop_callback(*args), lambda *args, obj=weakref.proxy(self): obj._app_control_on_stop_callback(*args),
order=10, order=15,
) )
else: else:
self._app_control_on_stop_handle = None self._app_control_on_stop_handle = None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment