The solution to the ROS compilation error "error: 'tf2_buffer_' was not declared in this scope"

written in front

The environment tested by the author:
Ubuntu18.04, ROS-melodic

1. Problem description

When I tested the amcl program, I encountered the following problems (the tested amcl program was normal on Ubuntu16.04 ROS-kinetic, but I got Ubuntu18.04, ROS-melodic for testing, but the following problems occurred):

/home/ubuntu/***_ws/src/amcl_icp/amcl/src/amcl_node.cpp: In member function ‘tf2_ros::Buffer& AmclNode::TransformListenerWrapper::getBuffer()’:
/home/ubuntu/***_ws/src/amcl_icp/amcl/src/amcl_node.cpp:140:50: error: ‘tf2_buffer_’ was not declared in this scope
     inline tf2_ros::Buffer &getBuffer() {
    
     return tf2_buffer_; }

Two, the solution

tf2_buffer_ 修改成了 tf2_buffer_ptr_After consulting the data, it is found that this part has been modified in the ROS-melodic version, and the amcl program that needs to be modified is included in the melodic .
2 locations need to be modified:
location 1:

// 原来的程序:
inline tf2_ros::Buffer &getBuffer() {
    
     return tf2_buffer_; }
// 修改为:
inline std::shared_ptr<tf2_ros::Buffer> &getBuffer() {
    
    return tf2_buffer_ptr_;}

position 2:

// 原来的程序:
tf_->getBuffer().setTransform(tf_msg->transforms[ii], "rosbag_authority");
// 修改为:
tf_->getBuffer()->setTransform(tf_msg->transforms[ii], "rosbag_authority");

Then compile again, you can compile successfully.

reference link

[1] moriarty. Compile Error Melodic due to tf change #717 [EB/OL]. https://github.com/ros-planning/navigation/issues/717, 2018-05-15/2023-04-12.
[1] 向阳花开. ROS- 解决error “tf2_buffer_’ was not declared in this scope” [EB/OL]. https://blog.csdn.net/Draonly/article/details/111885161, 2020-12-29/2023-04-12.

Guess you like

Origin blog.csdn.net/qq_39779233/article/details/130106870