I am trying to transform points from the camera coordinate frame to the base coordinate frame in ROS 2. Here’s my code:

import tf2_ros
import rclpy
from tf2_geometry_msgs import do_transform_point
from geometry_msgs.msg import Point

node = rclpy.create_node('transform_debug')

tf_buffer = tf2_ros.Buffer(rclpy.duration.Duration(seconds=1.0))
tf2_ros.TransformListener(tf_buffer, node)

# Transform point coordinates to the target frame.
source_frame = 'camera_depth_frame'
target_frame = 'base_link'

# get the transformation from source_frame to target_frame.
transformation = tf_buffer.lookup_transform(target_frame,
            source_frame, rclpy.time.Time(), rclpy.duration.Duration(seconds=0.1))

point_source = Point(x=0.1, y=1.2, z=2.3)
point_target = do_transform_point(transformation, point_source)

When I run this with:

ros2 launch stretch_core stretch_driver.launch.py

The code results in the following error:

transformation = tf_buffer.lookup_transform(target_frame,source_frame, rclpy.time.Time(), rclpy.duration.Duration(seconds=3.0))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/ros/humble/lib/python3.10/site-packages/tf2_ros/buffer.py", line 136, in lookup_transform
    return self.lookup_transform_core(target_frame, source_frame, time)
tf2.LookupException: "base_link" passed to lookupTransform argument target_frame does not exist

Any idea why ROS 2 cannot seem to find “base_link”, when this worked perfectly fine in ROS 1?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.