tf2 lookup_transform target_frame does not exist
I'm having troubles getting the static transform between two links which is broadcasted by the robot_state_publisher
node.
The simple example below shows my problem. I expected tf_buffer.lookup_transform()
to return the static transform between the base link and the gps antenna but I always get an exception "gps_antenna" passed to lookupTransform argument target_frame does not exist
.
I read somewhere that this might be because the tf_buffer
needs time to "fill up", but I haven't found a way to give it that time. The only way I could get things to work is by creating a timer and setting the get_dist()
method as a callback. However, since I'm just looking up a static transform once, that approach doesn't seem right.
Can anybody help me out? Thanks a lot!
class Example(Node):
def __init__(self):
super().__init__("example_node")
self.tf_buffer = Buffer()
self.tf_listener = TransformListener(self.tf_buffer, self)
self.dist_gps = self.get_dist()
def get_dist(self):
source_frame = "base_link"
target_frame = "gps_antenna"
dist = 0
try:
now = rclpy.time.Time()
trans = self.tf_buffer.lookup_transform(
target_frame,
source_frame,
now)
except TransformException as ex:
self.get_logger().error(ex)
else:
dist = trans.transform.translation.x
return dist
def main(args=None):
rclpy.init(args=args)
example = Example()
rclpy.spin(example)
example.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
Note: I'm running ROS2 Galactic in a docker container (osrf/ros:galactic-desktop)
can you confirm that the transform does exist as you would expect through other means? what does your tf tree look like (
ros2 run tf2_tools view_frames
)? Can you query tf directly and get a response (ros2 run tf2_ros tf2_echo base_link gps_antenna
)?Yes, the transform exists. The tf tree looks correct and I get a response with
ros2 run tf2_ros tf2_echo base_link gps_antenna
. I also tried theasync_wait_for_transform.py
example from the geometry2 examples, which works fine as well (https://github.com/ros2/geometry2/blo...). The only issue is that I don't need this to run regularly but only once.Hi, have you solved this issue?
Unfortunately not, but I also haven't tried much since I posted the issue.
I have the same issue in ROS2 Humble. I suspect this is a threading issue.