TF2 cannot find the transform

asked 2019-09-28 12:11:49 -0500

EdwardNur gravatar image

updated 2019-09-29 00:21:51 -0500

ahendrix gravatar image


I have a problem and I searched for the answer but could not find one anyway. So my problem is that tf2 cannot find a tf even though it exists.

Here is my code:

bool GeniusLocalization::getTransform(geometry_msgs::TransformStamped& trans, std::string& parent_frame, std::string& child_frame,const ros::Time& stamp)

        this->buffer_.canTransform(parent_frame, child_frame, stamp, ros::Duration(3.0));
        trans = this->buffer_.lookupTransform(parent_frame, child_frame, stamp, ros::Duration(3.0));
        return true;
    } catch (tf2::TransformException &e)
        ROS_ERROR("GeniusLocalization::getTransform: Cannot find TF between %s and %s, exception: %s", parent_frame.c_str(), child_frame.c_str(), e.what());
        return false;


buffer_ is a member class

edit retag flag offensive close merge delete


The code you show us prints out the exception message when the lookup fails. Can you add this error message to your question, it would be very helpful. Also how long before this method is called is the buffer_ (I assume tf2_ros::Buffer) object created?

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-09-29 08:00:53 -0500 )edit

@PeteBlackerThe3rd It does not bring any errors, only warnings that the TF does not exist (target frame id does not exist to be more specific). The object is created in my header file (under private members) .

EdwardNur gravatar image EdwardNur  ( 2019-09-30 02:43:45 -0500 )edit

It sounds like this problem is being caused because the listener object is being created then you're querying the buffer object for a transformation to quickly afterwards. It generally takes a second or so for the listener object to create a large enough buffer of transformations for lookups to be possible. It's hard to tell without seeing more of your code. But the rule of thumb is that you should create a single buffer and listener object when you node starts, then use that single buffer for all lookups for the lifetime of the node.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-09-30 05:04:29 -0500 )edit

@PeteBlackerThe3rd But how can I create a single buffer inside my class as a member? I tried to create buffer in main then passing to my class constructor but it is incorrect as the copy constructor of tf2::Buffer is deleted.

EdwardNur gravatar image EdwardNur  ( 2019-10-01 05:37:56 -0500 )edit

Pass a shared_ptr or a reference?

gvdhoorn gravatar image gvdhoorn  ( 2019-10-01 05:40:08 -0500 )edit