How to get a specific latest transform from lookupTransform
I'm using tf2_ros::TransformListener
listening on /tf
topic, which contains various target_frame
and source_frame
pairs. I want to extract only a specific pair, say IMU
and TURTLE
. That pair is published at 250Hz according to rqt.
When I call: buffer.lookupTransform("IMU", "TURTLE", ros::Time(0))
I get "IMU" passed to lookupTransform argument target_frame does not exist
exception most of the time, but occasionally a good result.
When I call: buffer.lookupTransform("IMU", "TURTLE", ros::Time::now())
or buffer.lookupTransform("IMU", "TURTLE", ros::Time::now()-ros::Duration(0.1))
I get Lookup would require extrapolation into the future...
or Lookup would require extrapolation into the past...
What is a reliable way to retrieve the most current transform with given target_frame
and source_frame
?
EDIT
The issue was caused by simulation startup delay. waitForTransform()
as suggested in the answer below is the solution to my problem. Even better is its newer incarnation: tf2_ros::Buffer::canTransform()
.
Please edit your question provide more information about how to reproduce your problem. If the query with time zero is failing it likely means that you are not setting up your
TransformListener
with the right lifecycle to allow it to build up it's cache.Glad to hear that worked. Please accept the answer below with the checkbox to let other know this solved your problem.