Skip to content

Add optional ray_distances property to RayCasterData - #2947

Closed
taceris wants to merge 0 commit into
isaac-sim:mainfrom
taceris:main
Closed

taceris wants to merge 0 commit into
isaac-sim:mainfrom
taceris:main

Conversation

@taceris

@taceris taceris commented Jul 15, 2025 •

Copy link
Copy Markdown

Description

This PR adds an optional ray_distances property to RayCasterData to directly provide Euclidean distances for all rays. This eliminates the need for users to manually calculate distances in every implementation, reducing boilerplate code and potential errors in RL environments.

Key changes:

  1. Added ray_distances property from existing raycast data
  2. For unhit rays, returns cfg.max_distance to match existing conventions

Fixes #2946

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Checklist

  • I have run the pre-commit checks with ./isaaclab.sh --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have added my name to the CONTRIBUTORS.md

@taceris
taceris requested a review from pascal-roth as a code owner July 15, 2025 15:18
@taceris
taceris requested a review from Mayankm96 July 17, 2025 07:59
@Mayankm96
Mayankm96 requested a review from ooctipus July 26, 2025 10:16
@Mayankm96

Copy link
Copy Markdown
Contributor

@raidenLight I think we are missing a test for this feature. Could we have that too in the MR? Also need to update the CHANGELOG and extension.toml file.

Thanks again!

@ooctipus

Copy link
Copy Markdown
Collaborator

Hi, thanks @raidenLight for the PR, Are you willing add test case for this new feature? Let me know if you need help : ))

@taceris

taceris commented Jul 30, 2025 •

Copy link
Copy Markdown
Author

@raidenLight I think we are missing a test for this feature. Could we have that too in the MR? Also need to update the CHANGELOG and extension.toml file.

Thanks again!

Hi, thanks @raidenLight for the PR, Are you willing add test case for this new feature? Let me know if you need help : ))

@Mayankm96 @ooctipus Thank you for your suggestions! This is my first time using git-pull, and I'm not entirely sure how to add tests (is it something like source/isaaclab/test/sensors/check_ray_caster.py?), or how to update the CHANGELOG and extension.toml file. I'll be very glad if you could give me a brief explanation :)

@ooctipus

ooctipus commented Aug 4, 2025 •

Copy link
Copy Markdown
Collaborator

@raidenLight
Congratulation on your first PR!

Ahh, I just check, since we don't have ray_caster test yet, and this is your first time starting pull request, I think it is a bit too much to ask you to come with tests on your own. I think what will be nice instead will be printing the ray_distances in

scripts/tutorials/04_sensors/run_ray_caster.py
after you configured your ray caster to report ray distance
in below block add the printing, (please verify that the value makes sense to you):

with Timer(
            f"Ray-caster update with {4} x {ray_caster.num_rays} rays with max height of"
            f" {torch.max(ray_caster.data.pos_w).item():.2f}"  #  ---------- Add your ray_distance print
        ):
        

For the changelog, since raycaster.py is isaaclab.sensor.RayCaster, you would want to add a new entry in source/isaaclab/docs/CHANGELOG.rst, following the pattern of other entries.

Then increment the package version in source/isaaclab/config/extension.toml to the number you put in CHANGELOG

: ))
Let me know if you have any questions.

@taceris

taceris commented Aug 6, 2025 •

Copy link
Copy Markdown
Author

@raidenLight Congratulation on your first PR!恭喜您提交了第一个 PR!

Ahh, I just check, since we don't have ray_caster test yet, and this is your first time starting pull request, I think it is a bit too much to ask you to come with tests on your own. I think what will be nice instead will be printing the ray_distances in啊,我刚检查了一下,由于我们还没有 ray_caster 测试,而且这是你第一次提交 pull request,我认为让你自己写测试有点太多了。我觉得更好的做法是在你配置了 ray caster 以报告 ray distance 后,在

scripts/tutorials/04_sensors/run_ray_caster.py after you configured your ray caster to report ray distance中打印 ray_distances。 in below block add the printing, (please verify that the value makes sense to you):在下面的代码块中添加打印功能,请确认这些值对你来说是有意义的:

with Timer(
            f"Ray-caster update with {4} x {ray_caster.num_rays} rays with max height of"
            f" {torch.max(ray_caster.data.pos_w).item():.2f}"  #  ---------- Add your ray_distance print
        ):
        

For the changelog, since raycaster.py is isaaclab.sensor.RayCaster, you would want to add a new entry in source/isaaclab/docs/CHANGELOG.rst, following the pattern of other entries.对于 changelog,由于 raycaster.py 是 isaaclab.sensor.RayCaster,你需要在 source/isaaclab/docs/CHANGELOG.rst, 中按照其他条目的模式添加一个新条目。

Then increment the package version in source/isaaclab/config/extension.toml to the number you put in CHANGELOG然后,将 source/isaaclab/config/extension.toml 中的包版本增加到你在 CHANGELOG 中填写的数字

: )) Let me know if you have any questions.如果你有任何问题,请告诉我。

@ooctipus Thank you very much for your patient help!

I have added a simple output of ray_distance in scripts/tutorials/04_sensors/run_ray_caster.py.
Snipaste_2025-08-07_02-20-33

Additionally, I created a new simple example scripts/tutorials/04_sensors/run_ray_caster_on_crazyfile.py to more clearly demonstrate how the newly added property can assist with robot navigation tasks.
Snipaste_2025-08-07_02-17-06

I'm not sure if it's necessary, but I hope it can be helpful.

: ))

@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label Dec 29, 2025
@taceris
taceris marked this pull request as draft December 29, 2025 16:26
@taceris
taceris marked this pull request as ready for review December 29, 2025 16:26
@greptile-apps

greptile-apps Bot commented Dec 29, 2025

Copy link
Copy Markdown
Contributor

Greptile Summary

  • Adds an optional ray_distances property to RayCasterData that provides Euclidean distances for all rays, controlled by a new track_ray_distance configuration flag in RayCasterCfg
  • Eliminates the need for users to manually calculate distances using torch.norm(ray_hits_w - pos_w, axis=-1) in RL environments and other applications
  • Updates ray casting implementations in both single-mesh and multi-mesh ray casters to capture distance data from raycast operations and clip to max_distance for unhit rays

Important Files Changed

Filename Overview
source/isaaclab/isaaclab/sensors/ray_caster/ray_caster_data.py Adds new optional ray_distance property to provide Euclidean distances for all rays
source/isaaclab/isaaclab/sensors/ray_caster/ray_caster.py Modifies ray casting implementation to compute and store distances when tracking is enabled
source/isaaclab/isaaclab/sensors/ray_caster/multi_mesh_ray_caster.py Updates multi-mesh ray caster to capture and store distance data from raycast operations
source/isaaclab/isaaclab/sensors/ray_caster/ray_caster_cfg.py Adds track_ray_distance boolean configuration option to control distance tracking

Confidence score: 4/5

  • This PR is generally safe to merge with only minor review needed due to well-structured implementation and thorough testing
  • Score reflects solid implementation across multiple components with proper initialization, clipping, and error handling, though the tutorial script has a minor typo that should be fixed
  • Pay close attention to scripts/tutorials/04_sensors/run_ray_caster_on_crazyfile.py which has a typo in the filename ("crazyfile" instead of "crazyflie")

Sequence Diagram

sequenceDiagram
    participant User
    participant RayCaster
    participant RayCasterData
    participant WarPUtils
    participant PhysicsEngine
    
    User->>RayCaster: "Create RayCaster with track_ray_distance=True"
    RayCaster->>RayCaster: "__init__(cfg)"
    RayCaster->>RayCaster: "_initialize_impl()"
    RayCaster->>RayCaster: "_initialize_warp_meshes()"
    RayCaster->>WarPUtils: "convert_to_warp_mesh(vertices, faces)"
    WarPUtils-->>RayCaster: "wp_mesh"
    RayCaster->>RayCaster: "_initialize_rays_impl()"
    RayCaster->>RayCasterData: "Initialize ray_distance buffer"
    RayCaster-->>User: "RayCaster instance"
    
    User->>RayCaster: "sensor.data (access ray distances)"
    RayCaster->>RayCaster: "_update_outdated_buffers()"
    RayCaster->>RayCaster: "_update_buffers_impl(env_ids)"
    RayCaster->>RayCaster: "_update_ray_infos(env_ids)"
    RayCaster->>PhysicsEngine: "obtain_world_pose_from_view()"
    PhysicsEngine-->>RayCaster: "pos_w, quat_w"
    RayCaster->>WarPUtils: "raycast_mesh(ray_starts, ray_directions, max_dist, return_distance=True)"
    WarPUtils-->>RayCaster: "ray_hits_w, ray_distance"
    RayCaster->>RayCasterData: "Update ray_distance buffer"
    RayCaster-->>User: "RayCasterData with ray distances"
Loading

@greptile-apps greptile-apps Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Comments (4)

  1. scripts/tutorials/04_sensors/run_ray_caster.py, line 126 (link)

    logic: Accessing ray_caster.data.ray_distance before calling ray_caster.update() may return stale or uninitialized data. Should this line be moved after the ray_caster.update() call to ensure fresh data?

  2. source/isaaclab/docs/CHANGELOG.rst, line 10-11 (link)

    syntax: Missing space after 'property' before :attr: directive. Should be 'property :attr:~isaaclab.sensors.RayCasterCfg.track_ray_distance.'

  3. source/isaaclab/isaaclab/sensors/ray_caster/ray_caster_data.py, line 30 (link)

    style: Property name ray_distance should be plural ray_distances to match the existing pattern used in ray_hits_w (plural) and the documentation that mentions "distances for all rays"

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

  4. source/isaaclab/isaaclab/sensors/ray_caster/ray_caster.py, line 238-240 (link)

    syntax: Uses self._device instead of self.device - should be consistent with the pattern used elsewhere in the file

8 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

This branch was previously deployed

1 inactive deployment
postmerge-production — 37ddf626 Deployed Jan 29, 2026 by kellyguo11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Proposal] Add ray_distances for RayCasterData

3 participants