Skip to content

Pass map-to-camera transform to input_image in the ROS 2 image callback - #148

Open
mktk1117 wants to merge 1 commit into
leggedrobotics:ros2from
mktk1117:fix/image-callback-tf-direction
Open

mktk1117 wants to merge 1 commit into
leggedrobotics:ros2from
mktk1117:fix/image-callback-tf-direction

Conversation

@mktk1117

Copy link
Copy Markdown
Contributor

Problem

ElevationMap.input_image() expects R, t that take map coordinates into the camera frame: it projects map points with K @ (R @ p + t) and puts the camera at -R.T @ t.

The ROS 2 node's image_callback looks up (map_frame, camera_frame), which is the camera pose in the map (camera → map). As a result, image layers are projected from the wrong position and orientation. The ROS 1 node passes lookupTransform(sensorFrame, mapFrame), which is map → camera.

Fix

  • image_callback now looks up (camera_frame, map_frame).
  • New regression test tests/test_image_callback_transform.py builds a real tf2_ros.Buffer holding a rotated, offset camera pose and checks that the R, t handed to input_image:
    • map a point 1 m in front of the camera to (0, 0, 1);
    • put the camera at its TF position.

Testing

Run in a ros:jazzy container with a GPU:

  • The new test fails on ros2 HEAD (that point lands at (4, 1.5, -1.5) in camera coordinates) and passes with the fix.
  • All 136 tests in elevation_mapping_cupy/tests pass.

End to end: I replayed a 30 s hiking clip (lidar, TF, camera frames) into elevation_mapping_node, fed by a node that publishes 3-channel semantic images (risk / steppable / preferred_area).

Semantic cells in the published map Robot path with semantics Mean preferred_area on the path
Without the fix 347 5% 0.19
With the fix 18,187 77% 0.78

With the fix, the trail lands under the robot's path.

Note: on ros2 HEAD, image fusion itself is still disabled. input_image() raises AttributeError: 'ElevationMap' object has no attribute 'uv_correspondence' because the image buffers are never allocated. The end-to-end run above therefore used pascal-roth/b2w-wild-navigation-semantic-layers (e9722d1, which restores them) with this commit cherry-picked; it applies cleanly there. The unit test runs on ros2 because it mocks the map.

Fork PRs skip the self-hosted CI, so the results above are from local runs.

ElevationMap.input_image() projects map points with K @ (R @ p + t) and
places the camera at -R.T @ t, so R, t must map map coordinates into the
camera frame. The callback looked up (map_frame, camera) instead, which is
the camera pose in the map (camera -> map), so semantic images were
projected from the wrong place and orientation. The ROS 1 node passes
lookupTransform(sensorFrame, mapFrame), i.e. map -> camera.

Adds a regression test with a real tf2 buffer.

This branch has not been deployed

No deployments
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.

1 participant