Skip to content

Commit 50cbc76

Browse files
committed
fixes for internal multimesh raycaster
1 parent 087957f commit 50cbc76

File tree

1 file changed

+76
-25
lines changed

1 file changed

+76
-25
lines changed

exts/nav_tasks/nav_tasks/mdp/observations/height_scan_observations.py

Lines changed: 76 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
from isaaclab.utils import configclass
1919
from isaaclab.utils.warp import raycast_mesh
2020

21+
# Workaround for the fact that MultiMeshRayCaster and raycast_dynamic_meshes are not publicly available
22+
try:
23+
from isaaclab.sensors import MultiMeshRayCaster
24+
from isaaclab.utils.warp import raycast_dynamic_meshes
25+
except ImportError:
26+
MultiMeshRayCaster = None
27+
raycast_dynamic_meshes = None
28+
2129
if TYPE_CHECKING:
2230
from isaaclab.envs import ManagerBasedEnv, ManagerBasedRLEnv
2331

@@ -100,21 +108,41 @@ def height_scan_door_recognition(
100108
ray_directions = torch.zeros_like(ray_origins)
101109
ray_directions[..., 2] = -1.0
102110

103-
hit_point_down = raycast_mesh(
104-
ray_origins,
105-
ray_directions,
106-
mesh=sensor.meshes[sensor.cfg.mesh_prim_paths[0]],
107-
max_dist=sensor.cfg.max_distance,
108-
)[0]
111+
if MultiMeshRayCaster is not None and isinstance(sensor, MultiMeshRayCaster):
112+
hit_point_down = raycast_dynamic_meshes(
113+
ray_origins,
114+
ray_directions,
115+
mesh_ids_wp=sensor._mesh_ids_wp, # list with shape num_envs x num_meshes_per_env
116+
max_dist=sensor.cfg.max_distance,
117+
mesh_positions_w=sensor._mesh_positions_w if sensor.cfg.track_mesh_transforms else None,
118+
mesh_orientations_w=sensor._mesh_orientations_w if sensor.cfg.track_mesh_transforms else None,
119+
)[0]
120+
else:
121+
hit_point_down = raycast_mesh(
122+
ray_origins,
123+
ray_directions,
124+
mesh=sensor.meshes[sensor.cfg.mesh_prim_paths[0]],
125+
max_dist=sensor.cfg.max_distance,
126+
)[0]
109127

110128
ray_directions[..., 2] = 1.0
111129

112-
hit_point_up = raycast_mesh(
113-
ray_origins,
114-
ray_directions,
115-
mesh=sensor.meshes[sensor.cfg.mesh_prim_paths[0]],
116-
max_dist=sensor.cfg.max_distance,
117-
)[0]
130+
if MultiMeshRayCaster is not None and isinstance(sensor, MultiMeshRayCaster):
131+
hit_point_up = raycast_dynamic_meshes(
132+
ray_origins,
133+
ray_directions,
134+
mesh_ids_wp=sensor._mesh_ids_wp, # list with shape num_envs x num_meshes_per_env
135+
max_dist=sensor.cfg.max_distance,
136+
mesh_positions_w=sensor._mesh_positions_w if sensor.cfg.track_mesh_transforms else None,
137+
mesh_orientations_w=sensor._mesh_orientations_w if sensor.cfg.track_mesh_transforms else None,
138+
)[0]
139+
else:
140+
hit_point_up = raycast_mesh(
141+
ray_origins,
142+
ray_directions,
143+
mesh=sensor.meshes[sensor.cfg.mesh_prim_paths[0]],
144+
max_dist=sensor.cfg.max_distance,
145+
)[0]
118146

119147
lower_height = (
120148
(hit_point_up[..., 2] < (sensor.data.ray_hits_w[..., 2] - 1e-3))
@@ -230,13 +258,25 @@ def _get_occuled_points(self, robot_position: torch.Tensor) -> torch.Tensor:
230258
ray_directions[torch.isinf(ray_directions)] = 0.0
231259
ray_directions[torch.isnan(ray_directions)] = 0.0
232260

233-
# raycast from the robot to intended hit positions
234-
ray_hits_w = raycast_mesh(
235-
robot_position,
236-
ray_directions,
237-
mesh=self._sensor.meshes[self._sensor.cfg.mesh_prim_paths[0]],
238-
max_dist=self._sensor.cfg.max_distance,
239-
)[0]
261+
if MultiMeshRayCaster is not None and isinstance(self._sensor, MultiMeshRayCaster):
262+
ray_hits_w = raycast_dynamic_meshes(
263+
robot_position,
264+
ray_directions,
265+
mesh_ids_wp=self._sensor._mesh_ids_wp, # list with shape num_envs x num_meshes_per_env
266+
max_dist=self._sensor.cfg.max_distance,
267+
mesh_positions_w=self._sensor._mesh_positions_w if self._sensor.cfg.track_mesh_transforms else None,
268+
mesh_orientations_w=(
269+
self._sensor._mesh_orientations_w if self._sensor.cfg.track_mesh_transforms else None
270+
),
271+
)[0]
272+
else:
273+
# raycast from the robot to intended hit positions
274+
ray_hits_w = raycast_mesh(
275+
robot_position,
276+
ray_directions,
277+
mesh=self._sensor.meshes[self._sensor.cfg.mesh_prim_paths[0]],
278+
max_dist=self._sensor.cfg.max_distance,
279+
)[0]
240280

241281
# get not visible parts of the height-scan
242282
unseen = torch.norm(ray_hits_w - self._sensor.data.ray_hits_w, dim=2) > self.cfg.offset_threshold
@@ -331,12 +371,22 @@ def height_scan_square_exp_occlu(
331371
ray_directions[torch.isnan(ray_directions)] = 0.0
332372

333373
# raycast from the robot to intended hit positions
334-
ray_hits_w = raycast_mesh(
335-
robot_position,
336-
ray_directions,
337-
mesh=sensor.meshes[sensor.cfg.mesh_prim_paths[0]],
338-
max_dist=sensor.cfg.max_distance,
339-
)[0]
374+
if MultiMeshRayCaster is not None and isinstance(sensor, MultiMeshRayCaster):
375+
ray_hits_w = raycast_dynamic_meshes(
376+
robot_position,
377+
ray_directions,
378+
mesh_ids_wp=sensor._mesh_ids_wp, # list with shape num_envs x num_meshes_per_env
379+
max_dist=sensor.cfg.max_distance,
380+
mesh_positions_w=sensor._mesh_positions_w if sensor.cfg.track_mesh_transforms else None,
381+
mesh_orientations_w=sensor._mesh_orientations_w if sensor.cfg.track_mesh_transforms else None,
382+
)[0]
383+
else:
384+
ray_hits_w = raycast_mesh(
385+
robot_position,
386+
ray_directions,
387+
mesh=sensor.meshes[sensor.cfg.mesh_prim_paths[0]],
388+
max_dist=sensor.cfg.max_distance,
389+
)[0]
340390

341391
# get not visible parts of the height-scan
342392
unseen = torch.norm(ray_hits_w - ray_hits, dim=2) > 0.01
@@ -402,6 +452,7 @@ def height_scan_square_exp_occlu_with_door_recognition(
402452
shape,
403453
door_height_thres=door_height_thres,
404454
offset=offset,
455+
clip_height=clip_height,
405456
return_height=False,
406457
)
407458
return height_scan_square_exp_occlu(env, asset_cfg, sensor_cfg, shape, offset, clip_height)

0 commit comments

Comments
 (0)