TF2 cannot find the transform
Hi,
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)
{
try
{
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
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 assumetf2_ros::Buffer
) object created?@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) .
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 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.
Pass a
shared_ptr
or a reference?