ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Thanks to Photon, after consulting the official documentation (Learning about tf and time (C++)) I found where my problem was.

First of all I had a (wrong) preconception that Time(0) and Time::now() refer to the very same thing and are interchangeable. I couldn't have been more wrong about this. They are not the same.
The Time(0) means "the latest available transform in the buffer" while Time::now(), literally fetches the frame at the exact moment, and since there is a delay between this command being issued and the frame being fetched, we will have some latencies in milliseconds and this will cause the lookup failure if its not accounted for.

In order to fix this I either had to use Time(0) and get the latest available transform in the queue or if I wanted the frame at roughly now, I had to use waitForTransform()

So to cut a long story short, I either had to do :

 transform_listener.lookupTransform("base_footprint", "odom",ros::Time(0), transform);

or:

ros::Time now = ros::Time::now();
transform_listener.waitForTransform("base_footprint", 
                                    "odom", 
                                     now, 
                                     // the wait duration in seconds
                                     ros::Duration(2));
//note that we used 'now' here as well. if we don't, we will still face lookup error
//as if nothing has changed
transform_listener.lookupTransform("base_footprint", "odom", now, transform);

Thanks to Photon, after consulting the official documentation (Learning about tf and time (C++)) I found where my problem was.

First of all I had a (wrong) preconception that Time(0) and Time::now() refer to the very same thing and are interchangeable. I couldn't have been more wrong about this. They are not the same.
The Time(0) means "the latest available transform in the buffer" while Time::now(), literally fetches the frame at the exact moment, and since there is a delay between this command being issued and the frame being fetched, we will have some latencies in milliseconds and this will cause the lookup failure if its not accounted for.
Why is that?(based on tf2 docs which I believe also applies to tf) :

Each listener has a buffer where it stores all the coordinate transforms coming from the different tf broadcasters. When a broadcaster sends out a transform, it takes some time before that transform gets into the buffer (usually a couple of milliseconds). So, when you request a frame transform at time "now", you should wait a few milliseconds for that information to arrive.

In order to fix this I either had to use Time(0) and get the latest available transform in the queue or if I wanted the frame at roughly now, I had to use waitForTransform()

So to cut a long story short, I either had to do :

 transform_listener.lookupTransform("base_footprint", "odom",ros::Time(0), transform);

or:

ros::Time now = ros::Time::now();
transform_listener.waitForTransform("base_footprint", 
                                    "odom", 
                                     now, 
                                     // the wait duration in seconds
                                     ros::Duration(2));
//note that we used 'now' here as well. if we don't, we will still face lookup error
//as if nothing has changed
transform_listener.lookupTransform("base_footprint", "odom", now, transform);