Skip to content

[Proposal] Add ray_distances for RayCasterData #2946

Open

Description

@taceris

Proposal

Add a ray_distances field to the RayCasterData output to directly provide Euclidean distances for all rays.

Motivation

Current implementation forces users to manually calculate distances using ray_hits_w and pos_w (e.g., torch.norm(ray_hits_w - pos_w, axis=-1)). This requires redundant boilerplate code in every RL environment implementation and introduces unnecessary complexity and potential errors for common tasks like collision avoidance.

Alternatives

Considered providing a helper function, but direct integration offers better API consistency and eliminates redundant user-side calculations.

Implementation

Simple interface modification using existing raycast data. Requires minimal changes to compute distances from ray_hits_w and pos_w. For unhit rays, returns max-distance to match existing convention.

Additional context

Fundamental for RL tasks like navigation and object avoidance. Eliminates common pain point reported by users.

Checklist

  • I have checked that there is no similar issue in the repo

Acceptance Criteria

  • ray_distances field added to RayCasterData output
  • Documentation updated across relevant files

Activity

  1. ducmngx commented on Jul 16, 2025

    @ducmngx

    Can I ask how you use LiDAR for RL training? I can't figure out how my robot can use RTX LiDAR to scan environment. I don't really understand how to get a environement /laser_scan if I can only have one prim_path_mesh

  2. taceris commented on Jul 17, 2025

    @taceris
    Author

    Can I ask how you use LiDAR for RL training? I can't figure out how my robot can use RTX LiDAR to scan environment. I don't really understand how to get a environement /laser_scan if I can only have one prim_path_mesh

    Hello, I didn't use RTX LiDAR in isaacsim, I just used Ray Caster to detect the distance information from the robot to the obstacle, just like the official document example https://Isaac-sim.github.io/Isaacslab/main/source/overview/core-concepts/sensors/ray_caster.html. For multiple mesh, the Ray Caster class corresponding to isaacsim5.0 branch seems to have realized this function. In the current version, a simplified method is to use terrain-geneater to realize a terrain with random columns as a large mesh.

  3. RandomOakForest commented on Jul 17, 2025

    @RandomOakForest
    Collaborator

    Thank you for posting this proposal. The team will review it.

  4. added
    enhancement
    on Jul 17, 2025
  5. pedestrian6 commented on Oct 21, 2026

    @pedestrian6
    Contributor

    Hi, I’d like to work on this issue as my first contribution to Isaac Lab.

    I noticed that #2947 was closed without merging, while the current Newton-specific sensor data class already exposes ray_distances. I’d like to explore adding consistent distance output to the general ray casters, with focused tests and documentation.

    Is anyone actively working on this? Would a new PR be welcome? I’d also appreciate guidance on whether missed rays should return inf or max_distance.

  6. ooctipus commented on Oct 22, 2026

    @ooctipus
    Collaborator

    I narrowed #8781 to the mesh triangulation and ray-input validation fixes, removing the proposed shared RayCasterData.ray_distances output. The existing options below are worth trying before adding another always-stored sensor field:

    1. If you own the mesh query, request distances from that same query. The existing raycast_mesh wrapper already supports this:

      from isaaclab.utils.warp.ops import raycast_mesh
      
      hits_w, ranges, _, _ = raycast_mesh(
          ray_starts_w, ray_directions_w, mesh, return_distance=True
      )

      Here starts/directions are Torch tensors in the same frame, directions are unit vectors, and mesh is a Warp mesh. This does not require a second query.

    2. Newton's existing BVH sensor (NewtonRaycastSensor) already exposes sensor.data.ray_distances.torch.

    3. For cached sensor hits, distance can be derived from the hit point and the actual origin of each ray. In the common case where every ray starts at data.pos_w and no artificial post-hit bias is applied:

      import torch
      
      data = sensor.data
      ranges = torch.linalg.vector_norm(
          data.ray_hits_w.torch - data.pos_w.torch[:, None, :], dim=-1
      )

      For grid patterns, offsets, or drift that move ray origins away from data.pos_w, use the corresponding world-frame per-ray origins instead. sensor.ray_starts is local-frame data, so it cannot be subtracted directly from world-frame hits. Post-hit Z bias also changes the published hit points; use the query's distance output when you need the geometric range before that bias.

    The existing query/Newton outputs use inf for misses. If an observation requires a finite maximum, clamp the resulting ranges explicitly, e.g. ranges.clamp(max=max_distance).

    A uniform high-level field remains a separate API proposal here; it is not required to fix the mesh/input bugs in #8781.

  7. ooctipus commented on Oct 22, 2026

    @ooctipus
    Collaborator

    @pedestrian6
    Feature is definitely welcomed if they are genuily missing.
    Before introducing another output field, could you try the existing options described above? raycast_mesh(..., return_distance=True) already returns distances when you control the query, and Newton exposes them directly.

  8. taceris commented on Nov 5, 2026

    @taceris
    Author

    I narrowed #8781 to the mesh triangulation and ray-input validation fixes, removing the proposed shared RayCasterData.ray_distances output. The existing options below are worth trying before adding another always-stored sensor field:

    1. If you own the mesh query, request distances from that same query. The existing raycast_mesh wrapper already supports this:
      from isaaclab.utils.warp.ops import raycast_mesh

      hits_w, ranges, _, _ = raycast_mesh(
      ray_starts_w, ray_directions_w, mesh, return_distance=True
      )

      Here starts/directions are Torch tensors in the same frame, directions are unit vectors, and mesh is a Warp mesh. This does not require a second query.

    2. Newton's existing BVH sensor (NewtonRaycastSensor) already exposes sensor.data.ray_distances.torch.

    3. For cached sensor hits, distance can be derived from the hit point and the actual origin of each ray. In the common case where every ray starts at data.pos_w and no artificial post-hit bias is applied:
      import torch

      data = sensor.data
      ranges = torch.linalg.vector_norm(
      data.ray_hits_w.torch - data.pos_w.torch[:, None, :], dim=-1
      )

      For grid patterns, offsets, or drift that move ray origins away from data.pos_w, use the corresponding world-frame per-ray origins instead. sensor.ray_starts is local-frame data, so it cannot be subtracted directly from world-frame hits. Post-hit Z bias also changes the published hit points; use the query's distance output when you need the geometric range before that bias.

    The existing query/Newton outputs use inf for misses. If an observation requires a finite maximum, clamp the resulting ranges explicitly, e.g. ranges.clamp(max=max_distance).

    A uniform high-level field remains a separate API proposal here; it is not required to fix the mesh/input bugs in #8781.

    Hi @ooctipus, thanks for outlining the existing options. I looked into the current implementation, and I think there is still a useful, narrowly scoped case for exposing ray_distances on MultiMeshRayCasterData.

    For users of the existing MultiMeshRayCaster, the sensor owns the ray query. Although raycast_mesh(..., return_distance=True) is useful when calling the query directly, it does not expose the result of the query already performed by the sensor through sensor.data.

    More importantly, the multi-mesh implementation already computes and stores the closest-hit distances:

    Could MultiMeshRayCasterData.ray_distances expose a ProxyArray view of that existing buffer, following the public interface used by NewtonRaycastSensorData? This would not require another ray query, another distance buffer, or recomputing distances from the hit points. It would be an additive API change, preserving existing outputs and behavior. Keeping inf for misses would also match the existing query and Newton conventions; applications could clamp distances explicitly when needed.

    There is also a practical limitation to deriving distances from the currently exposed data. As you noted, ray_hits_w - pos_w[:, None, :] is valid only when each ray actually starts at pos_w.

    In the current implementation, cfg.offset.pos is applied to the local ray starts, while data.pos_w is written before those local starts are transformed into world space. Thus, data.pos_w represents the tracked frame position, including the frame-to-body transform and position drift, but does not include the configured ray-pattern translation cfg.offset.pos.

    For example, my LiDAR uses a nonzero mounting offset. Subtracting data.pos_w gives the distance to the tracked frame origin rather than the actual ray origin. Reconstructing the correct origins requires handling the local pattern, offset, alignment mode, and relevant drift semantics.

    If exposing distances is still not preferred, could the sensor at least expose the actual world-frame per-ray origins, for example as data.ray_starts_w, backed by the existing _ray_starts_w buffer? That would make the suggested manual calculation possible through the public API:

    data = sensor.data
    ranges = torch.linalg.vector_norm(
        data.ray_hits_w.torch - data.ray_starts_w.torch,
        dim=-1,
    )

    This would still require care for any post-hit bias, as you mentioned. For MultiMeshRayCaster, exposing the already-computed query distances seems the simpler and less error-prone interface.

    Would a small PR limited to exposing that existing multi-mesh distance buffer, with focused tests and documentation, be welcome?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions