Rosanswers logo

I am trying to upgrade some existing code that use tf with kinetic to use instead tf2 with noetic.

In the following line of code, planner_ is of type base_local_planner::TrajectoryPlannerROS and the code wants to call its initialize function.

planner_.initialize("TrajectoryPlannerROS", &tf_, &costmap_ros_);

The function signature for "initialize" is:

void base_local_planner::TrajectoryPlannerROS::initialize   (   
  std::string   name,
  tf2_ros::Buffer *     tf,
  costmap_2d::Costmap2DROS *    costmap_ros 

and the documentation says that tf is "a pointer to a transform listener", despite its type being tf2_ros::Buffer.

In the line of code above, tf_ is of type tf2_ros::TransformListener, which seems to match the documentation. However, the compiler throws an error that:

error: cannot convert ‘tf2_ros::TransformListener’ to ‘tf2_ros::Buffer’**

I am very confused. How should one pass in a tf2_ros::TransformListener as a parameter of type tf2_ros::Buffer? The documentation is very confusing.

Originally posted by zkytony on ROS Answers with karma: 178 on 2022-01-09

Post score: 0


1 Answer 1


Rosanswers logo

It seems like they forgot to update the documentation when porting from tf to tf2_ros, and hence the confusing docs.

You should trust the function signature, tf2_ros::Buffer *tf over the documentation. You cannot convert a tf2_ros::TransformListener to a tf2_ros::Buffer.

A reference to an existing tf2_ros::Buffer is passed as an argument to the constructor of tf2_ros::TransformListener. That same tf2_ros::Buffer is what you have to pass to base_local_planner::TrajectoryPlannerROS::initialize() as an argument.

There seems to be no way of obtaining a reference to the buffer from the transformListener.

So, if you've constructed tf_ locally, then you'll have access to the buffer that you used in constructing it already. If you've passed tf_ in as a reference, consider passing the buffer in as a reference and use it to call initialize.

Originally posted by ijnek with karma: 460 on 2022-01-09

This answer was ACCEPTED on the original site

Post score: 1

Original comments

Comment by ijnek on 2022-02-01:
@zkytony If this answered your question correctly, would you be able to mark as correct and close-off the question? Thanks!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.