Skip to content

Commit a75dc55

Browse files
committed
Refresh views only when accessed with invalidated view
1 parent b808c1c commit a75dc55

15 files changed

+127
-137
lines changed

omnigibson/examples/teleoperation/vr_robot_control_demo.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,19 @@ def main():
8080
eef_tracking_mode="controller",
8181
align_anchor_to="camera",
8282
# roll, pitch, yaw
83-
view_angle_limits=[180, 30, 30],
83+
# view_angle_limits=[180, 30, 30],
8484
)
8585
vrsys.start()
8686

87-
for _ in range(3000):
87+
robot = env.robots[0]
88+
89+
for _ in range(2000):
8890
# update the VR system
8991
vrsys.update()
9092
# get the action from the VR system and step the environment
91-
env.step(vrsys.get_robot_teleop_action())
93+
action = vrsys.get_robot_teleop_action()
94+
env.step(action)
95+
print("Controller action: " + str(action[robot.base_action_idx]))
9296

9397
print("Cleaning up...")
9498
vrsys.stop()

omnigibson/examples/teleoperation/vr_scene_tour_demo.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ def main():
4141
)
4242
vrsys.start()
4343
# set headset position to be 1m above ground and facing +x
44-
vrsys.vr_profile.set_physical_world_to_world_anchor_transform_to_match_xr_device(
45-
vrsys.og2xr(th.tensor([0.0, 0.0, 1.0]), th.tensor([-0.5, 0.5, 0.5, -0.5])).numpy(), vrsys.hmd
46-
)
44+
# vrsys.vr_profile.set_physical_world_to_world_anchor_transform_to_match_xr_device(
45+
# vrsys.og2xr(th.tensor([0.0, 0.0, 1.0]), th.tensor([-0.5, 0.5, 0.5, -0.5])).numpy(), vrsys.hmd
46+
# )
47+
48+
# anchor_pose = self.og2xr(anchor_pos, anchor_orn)
49+
# self.xr_core.schedule_set_camera(anchor_pose.numpy())
4750

4851
# main simulation loop
4952
for _ in range(3000):

omnigibson/object_states/attached_to.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ def _detach(self):
390390
if self.parent_link is not None:
391391
# Remove the attachment joint prim from the stage
392392
og.sim.stage.RemovePrim(self.attachment_joint_prim_path)
393-
og.sim.update_handles()
394393

395394
# Remove child reference from the parent object
396395
self.parent.states[AttachedTo].children[self.parent_link.body_name] = None

omnigibson/prims/cloth_prim.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -780,10 +780,6 @@ def report_hit(hit):
780780

781781
return contacts
782782

783-
def update_handles(self):
784-
# no handles to update
785-
pass
786-
787783
@property
788784
def volume(self):
789785
mesh = mesh_prim_to_trimesh_mesh(self.prim, include_normals=False, include_texcoord=False, world_frame=True)

omnigibson/prims/entity_prim.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ def update_joints(self):
277277
"""
278278
# Initialize joints dictionary
279279
self._joints = dict()
280-
self.update_handles()
281280

282281
# Handle case separately based on whether we are actually articulated or not
283282
if self._articulation_view and not self.kinematic_only:
@@ -379,10 +378,10 @@ def _articulation_view(self):
379378
# Validate that the articulation view is initialized and that if physics is running, the
380379
# view is valid.
381380
if og.sim.is_playing() and self.initialized:
382-
assert (
383-
self._articulation_view_direct.is_physics_handle_valid()
384-
and self._articulation_view_direct._physics_view.check()
385-
), "Articulation view must be valid if physics is running!"
381+
physics_valid = self._articulation_view_direct.is_physics_handle_valid() and self._articulation_view_direct._physics_view.check()
382+
if not physics_valid:
383+
breakpoint()
384+
assert physics_valid, "Articulation view must be valid if physics is running!"
386385

387386
return self._articulation_view_direct
388387

@@ -864,27 +863,6 @@ def _denormalize_efforts(self, efforts, indices=None):
864863
"""
865864
return efforts * self.max_joint_efforts if indices is None else efforts * self.max_joint_efforts[indices]
866865

867-
def update_handles(self):
868-
"""
869-
Updates all internal handles for this prim, in case they change since initialization
870-
"""
871-
assert og.sim.is_playing(), "Simulator must be playing if updating handles!"
872-
873-
# Reinitialize the articulation view
874-
if self._articulation_view_direct is not None:
875-
self._articulation_view_direct.initialize(og.sim.physics_sim_view)
876-
877-
# Update all links and joints as well
878-
for link in self._links.values():
879-
if not link.initialized:
880-
link.initialize()
881-
link.update_handles()
882-
883-
for joint in self._joints.values():
884-
if not joint.initialized:
885-
joint.initialize()
886-
joint.update_handles()
887-
888866
def get_joint_positions(self, normalized=False):
889867
"""
890868
Grabs this entity's joint positions

omnigibson/prims/joint_prim.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,17 @@ def _initialize(self):
135135
# Always run super first
136136
super()._initialize()
137137

138-
# Update the joint indices etc.
139-
self.update_handles()
138+
# It's a bit tricky to get the joint index here. We need to find the first dof at this prim path
139+
# first, then get the corresponding joint index from that dof offset.
140+
self._joint_dof_offset = list(self._articulation_view._dof_paths[0]).index(self.prim_path)
141+
joint_dof_offsets = self._articulation_view._metadata.joint_dof_offsets
142+
# Note that we are finding the last occurrence of the dof offset, since that corresponds to the joint index
143+
# The first occurrence can be a fixed link that is 0-dof, meaning the offset will be repeated.
144+
self._joint_idx = next(
145+
i for i in reversed(range(len(joint_dof_offsets))) if joint_dof_offsets[i] == self._joint_dof_offset
146+
)
147+
self._joint_name = self._articulation_view._metadata.joint_names[self._joint_idx]
148+
self._n_dof = self._articulation_view._metadata.joint_dof_counts[self._joint_idx]
140149

141150
# Get control type
142151
if self.articulated:
@@ -157,22 +166,6 @@ def _initialize(self):
157166
assert len(set(control_types)) == 1, f"Got multiple control types for this single joint: {control_types}"
158167
self._control_type = control_types[0]
159168

160-
def update_handles(self):
161-
"""
162-
Updates all internal handles for this prim, in case they change since initialization
163-
"""
164-
# It's a bit tricky to get the joint index here. We need to find the first dof at this prim path
165-
# first, then get the corresponding joint index from that dof offset.
166-
self._joint_dof_offset = list(self._articulation_view._dof_paths[0]).index(self.prim_path)
167-
joint_dof_offsets = self._articulation_view._metadata.joint_dof_offsets
168-
# Note that we are finding the last occurrence of the dof offset, since that corresponds to the joint index
169-
# The first occurrence can be a fixed link that is 0-dof, meaning the offset will be repeated.
170-
self._joint_idx = next(
171-
i for i in reversed(range(len(joint_dof_offsets))) if joint_dof_offsets[i] == self._joint_dof_offset
172-
)
173-
self._joint_name = self._articulation_view._metadata.joint_names[self._joint_idx]
174-
self._n_dof = self._articulation_view._metadata.joint_dof_counts[self._joint_idx]
175-
176169
def set_control_type(self, control_type, kp=None, kd=None):
177170
"""
178171
Sets the control type for this joint. Note that ControlType.NONE is equivalent to

omnigibson/prims/material_prim.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ def _load(self):
9696

9797
# Move prim to desired location
9898
lazy.omni.kit.commands.execute("MovePrim", path_from=material_path, path_to=self.prim_path)
99-
og.sim.update_handles()
10099

101100
# Return generated material
102101
return lazy.isaacsim.core.utils.prims.get_prim_at_path(self.prim_path)

omnigibson/prims/rigid_dynamic_prim.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,6 @@ def _initialize(self):
6666
if self.contact_reporting_enabled:
6767
og.sim.contact_sensor.get_rigid_body_raw_data(self.prim_path)
6868

69-
def update_handles(self):
70-
"""
71-
Updates all internal handles for this prim, in case they change since initialization
72-
"""
73-
# Validate that the view is valid if physics is running
74-
if og.sim.is_playing() and self.initialized:
75-
assert (
76-
self._rigid_prim_view.is_physics_handle_valid() and self._rigid_prim_view._physics_view.check()
77-
), "Rigid prim view must be valid if physics is running!"
78-
79-
assert not (
80-
og.sim.is_playing() and not self._rigid_prim_view.is_valid
81-
), "Rigid prim view must be valid if physics is running!"
82-
83-
self._rigid_prim_view.initialize(og.sim.physics_sim_view)
84-
8569
def set_linear_velocity(self, velocity):
8670
"""
8771
Sets the linear velocity of the prim in stage.

omnigibson/prims/rigid_prim.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ def _initialize(self):
141141
mesh.initialize()
142142

143143
# Grab handle to this rigid body and get name
144-
self.update_handles()
145144
self._body_name = self.prim_path.split("/")[-1]
146145

147146
def remove(self):
@@ -228,13 +227,6 @@ def disable_collisions(self):
228227
for col_mesh in self._collision_meshes.values():
229228
col_mesh.collision_enabled = False
230229

231-
def update_handles(self):
232-
"""
233-
Updates all internal handles for this prim, in case they change since initialization.
234-
To be implemented by subclasses as needed.
235-
"""
236-
pass
237-
238230
def enable_gravity(self):
239231
"""
240232
Enables gravity for this rigid body.

omnigibson/robots/manipulation_robot.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,6 @@ def _release_grasp(self, arm="default"):
613613

614614
# Remove joint and filtered collision restraints
615615
og.sim.stage.RemovePrim(self._ag_obj_constraint_params[arm]["ag_joint_prim_path"])
616-
og.sim.update_handles()
617616
self._ag_obj_constraints[arm] = None
618617
self._ag_obj_constraint_params[arm] = {}
619618
self._ag_freeze_gripper[arm] = False

omnigibson/simulator.py

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -765,11 +765,7 @@ def adding_objects(self, objs):
765765
# The objects have been added to the USD stage but PhysX hasn't been synchronized yet.
766766
# We must flush USD changes to PhysX before updating handles to avoid errors like
767767
# "Provided pattern list did not match any rigid bodies".
768-
# The order of operations should strictly be:
769-
# 1. Flush USD changes to PhysX
770-
# 2. Update handles to reinitialize physics view
771768
SimulationManager._physx_sim_interface.flush_changes()
772-
self.update_handles()
773769

774770
def _post_import_object(self, obj):
775771
"""
@@ -846,9 +842,6 @@ def removing_objects(self, objs):
846842

847843
# Run post-processing required if we were playing
848844
if playing:
849-
# Update all handles that are now broken because objects have changed
850-
self.update_handles()
851-
852845
if gm.ENABLE_TRANSITION_RULES:
853846
# Prune the transition rules that are currently active
854847
for scene in scenes_modified:
@@ -902,9 +895,6 @@ def remove_prim(self, prim):
902895
# Remove prim
903896
prim.remove()
904897

905-
# Update all handles that are now broken because prims have changed
906-
self.update_handles()
907-
908898
def _reset_variables(self):
909899
"""
910900
Reset internal variables when a new stage is loaded
@@ -916,6 +906,9 @@ def render(self):
916906
PoseAPI.mark_valid()
917907

918908
def _refresh_physics_sim_view(self):
909+
# TODO: Figure out if we need to refresh this
910+
breakpoint()
911+
919912
SimulationManager = lazy.isaacsim.core.simulation_manager.SimulationManager
920913
IsaacEvents = lazy.isaacsim.core.simulation_manager.IsaacEvents
921914

@@ -926,30 +919,6 @@ def _refresh_physics_sim_view(self):
926919
SimulationManager._message_bus.dispatch(IsaacEvents.SIMULATION_VIEW_CREATED.value, payload={})
927920
SimulationManager._message_bus.dispatch(IsaacEvents.PHYSICS_READY.value, payload={})
928921

929-
def update_handles(self):
930-
# Handles are only relevant when physx is running
931-
if not self.is_playing():
932-
return
933-
934-
# Refresh the sim view
935-
self._refresh_physics_sim_view()
936-
937-
# Then update the handles for all objects
938-
for scene in self.scenes:
939-
if scene is not None:
940-
for obj in scene.objects:
941-
# Only need to update if object is already initialized as well
942-
if obj.initialized:
943-
obj.update_handles()
944-
for system in scene.active_systems.values():
945-
if isinstance(system, MacroPhysicalParticleSystem):
946-
system.refresh_particles_view()
947-
948-
# Finally update any unified views
949-
RigidContactAPI.initialize_view()
950-
GripperRigidContactAPI.initialize_view()
951-
ControllableObjectViewAPI.initialize_view()
952-
953922
def _non_physics_step(self):
954923
"""
955924
Complete any non-physics steps such as state updates.
@@ -981,9 +950,6 @@ def _non_physics_step(self):
981950

982951
self._objects_to_initialize = self._objects_to_initialize[n_objects_to_initialize:]
983952

984-
# Re-initialize the physics view because the number of objects has changed
985-
self.update_handles()
986-
987953
if gm.ENABLE_TRANSITION_RULES:
988954
# Refresh the transition rules
989955
for scene in scenes_modified:
@@ -1046,10 +1012,6 @@ def play(self):
10461012
# correctly.
10471013
self.render()
10481014

1049-
# Update all object handles, unless this is a play during initialization
1050-
if og.sim is not None:
1051-
self.update_handles()
1052-
10531015
if was_stopped:
10541016
# We need to update controller mode because kp and kd were set to the original (incorrect) values when
10551017
# sim was stopped. We need to reset them to default_kp and default_kd defined in ControllableObject.
@@ -1461,6 +1423,7 @@ def psi(self):
14611423
Returns:
14621424
IPhysxSimulation: Physx Simulation Interface (psi) for controlling low-level physx simulation
14631425
"""
1426+
self._refresh_physics_sim_view()
14641427
return self._physx_simulation_interface
14651428

14661429
@property

omnigibson/systems/macro_particle_system.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,6 @@ def generate_particles(
285285
for scale in scales:
286286
self.add_particle(relative_prim_path=f"{self.relative_prim_path}/particles", scale=scale)
287287

288-
og.sim.update_handles()
289-
290288
# Set the tfs
291289
self.set_particles_position_orientation(positions=positions, orientations=orientations)
292290

@@ -1178,7 +1176,7 @@ def __init__(self, name, create_particle_template, particle_density, scale=None,
11781176
self._particle_density = particle_density
11791177

11801178
# Physics rigid body view for keeping track of all particles' state
1181-
self.particles_view = None
1179+
self._particles_view = None
11821180

11831181
# Approximate radius of the macro particle, and distance from particle frame to approximate center
11841182
self._particle_radius = None
@@ -1198,6 +1196,11 @@ def initialize(self, scene):
11981196
if og.sim.is_playing():
11991197
self.refresh_particles_view()
12001198

1199+
@property
1200+
def particles_view(self):
1201+
self.refresh_particles_view()
1202+
return self._particles_view
1203+
12011204
def _load_new_particle(self, relative_prim_path, name):
12021205
# We copy the template prim and generate the new object if the prim doesn't already exist, otherwise we
12031206
# reference the pre-existing one
@@ -1250,9 +1253,12 @@ def refresh_particles_view(self):
12501253
12511254
Should be called every time sim.play() is called
12521255
"""
1256+
# TODO: Figure out if we need to update?
1257+
breakpoint()
1258+
12531259
og.sim.pi.update_simulation(elapsedStep=0, currentTime=og.sim.current_time)
12541260
with suppress_omni_log(channels=["omni.physx.tensors.plugin"]):
1255-
self.particles_view = og.sim.physics_sim_view.create_rigid_body_view(
1261+
self._particles_view = og.sim.physics_sim_view.create_rigid_body_view(
12561262
pattern=f"{self.prim_path}/particles/*"
12571263
)
12581264

@@ -1261,7 +1267,7 @@ def _clear(self):
12611267
super()._clear()
12621268

12631269
# Clear internal variables
1264-
self.particles_view = None
1270+
self._particles_view = None
12651271
self._particle_radius = None
12661272
self._particle_offset = None
12671273

omnigibson/systems/system_base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ def _clear(self):
204204

205205
self.reset()
206206
lazy.isaacsim.core.utils.prims.delete_prim(self.prim_path)
207-
og.sim.update_handles()
208207

209208
if og.sim.is_playing() and gm.ENABLE_TRANSITION_RULES:
210209
self.scene.transition_rule_api.prune_active_rules()

0 commit comments

Comments
 (0)