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

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

asked 2022-01-09 11:06:43 -0500

zkytony gravatar image

updated 2022-01-09 11:07:41 -0500

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.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2022-01-09 16:37:24 -0500

ijnek gravatar image

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.

edit flag offensive delete link more

Comments

@zkytony If this answered your question correctly, would you be able to mark as correct and close-off the question? Thanks!

ijnek gravatar image ijnek  ( 2022-02-01 03:46:27 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2022-01-09 11:06:43 -0500

Seen: 595 times

Last updated: Jan 09 '22