Skip to content

Fix RayCastSensor frame offset alignment for site/geom frames#778

Merged
kevinzakka merged 1 commit intomainfrom
fix/raycast-site-offset-alignment
Mar 11, 2026
Merged

Fix RayCastSensor frame offset alignment for site/geom frames#778
kevinzakka merged 1 commit intomainfrom
fix/raycast-site-offset-alignment

Conversation

@kevinzakka
Copy link
Collaborator

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's site_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 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.

Before.

raycast_before_fix.mp4

After.

raycast_after_fix.mp4

--frame site --alignment yaw --pitch in 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

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
@kevinzakka kevinzakka merged commit 8b8410b into main Mar 11, 2026
15 checks passed
@kevinzakka kevinzakka deleted the fix/raycast-site-offset-alignment branch March 11, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ray caster (height scanner) for terrains higher than the robot

1 participant