|
18 | 18 | from isaaclab.utils import configclass
|
19 | 19 | from isaaclab.utils.warp import raycast_mesh
|
20 | 20 |
|
| 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 | + |
21 | 29 | if TYPE_CHECKING:
|
22 | 30 | from isaaclab.envs import ManagerBasedEnv, ManagerBasedRLEnv
|
23 | 31 |
|
@@ -100,21 +108,41 @@ def height_scan_door_recognition(
|
100 | 108 | ray_directions = torch.zeros_like(ray_origins)
|
101 | 109 | ray_directions[..., 2] = -1.0
|
102 | 110 |
|
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] |
109 | 127 |
|
110 | 128 | ray_directions[..., 2] = 1.0
|
111 | 129 |
|
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] |
118 | 146 |
|
119 | 147 | lower_height = (
|
120 | 148 | (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:
|
230 | 258 | ray_directions[torch.isinf(ray_directions)] = 0.0
|
231 | 259 | ray_directions[torch.isnan(ray_directions)] = 0.0
|
232 | 260 |
|
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] |
240 | 280 |
|
241 | 281 | # get not visible parts of the height-scan
|
242 | 282 | 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(
|
331 | 371 | ray_directions[torch.isnan(ray_directions)] = 0.0
|
332 | 372 |
|
333 | 373 | # 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] |
340 | 390 |
|
341 | 391 | # get not visible parts of the height-scan
|
342 | 392 | 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(
|
402 | 452 | shape,
|
403 | 453 | door_height_thres=door_height_thres,
|
404 | 454 | offset=offset,
|
| 455 | + clip_height=clip_height, |
405 | 456 | return_height=False,
|
406 | 457 | )
|
407 | 458 | return height_scan_square_exp_occlu(env, asset_cfg, sensor_cfg, shape, offset, clip_height)
|
0 commit comments