Fix RayCastSensor frame offset alignment for site/geom frames#778
Merged
kevinzakka merged 1 commit intomainfrom Mar 11, 2026
Merged
Fix RayCastSensor frame offset alignment for site/geom frames#778kevinzakka merged 1 commit intomainfrom
kevinzakka merged 1 commit intomainfrom
Conversation
When a RayCastSensor is attached to a site or geom with a local offset, ray_alignment="yaw" and "world" only aligned ray directions and pattern offsets. The frame position was read directly from MuJoCo's site_xpos, which bakes in the full body rotation on the offset. This caused the ray origin to swing with body pitch/roll. The fix decomposes the frame position for site/geom frames: instead of reading site_xpos, recompute it as body_pos + alignment(body_mat) @ frame_local_pos. For "base" alignment this is identical to the previous behavior. For "yaw" and "world", the offset now respects the alignment mode. The same decomposition is applied in debug_vis() so visualization matches the actual ray computation. Fixes #775
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a RayCastSensor is attached to a site or geom with a local offset from its parent body,
ray_alignment="yaw"and"world"only aligned ray directions and pattern offsets. The frame position itself was read directly from MuJoCo'ssite_xpos, which bakes in the full body rotation on the offset. This caused the ray origin to swing with body pitch/roll, defeating the purpose of alignment.The fix decomposes the frame position for site/geom frames: instead of reading the pre-baked
site_xpos, recompute it asbody_pos + alignment(body_mat) @ frame_local_pos. For"base"alignment this is identical to the previous behavior. For"yaw"and"world", the offset now respects the alignment mode. The same decomposition is applied indebug_vis()so visualization matches the actual ray computation.Before.
raycast_before_fix.mp4
After.
raycast_after_fix.mp4
--frame site --alignment yaw --pitchin the raycast sensor demo. The body oscillates in pitch with the site 2m above. Before: ray origin swings with pitch. After: ray origin stays directly above the body.Fixes #775