MilanMichael / robot_pose_publisher_ros2

A Simple Node to Publish the Robot's Position Relative to the Map using TFs
2 stars 4 forks source link

error: ‘Buffer’ is not a member of ‘tf2_ros’ #1

Open mounteverset opened 1 year ago

mounteverset commented 1 year ago

Hey,

I can't build the package with colcon build. This is the error msg:

/home/levers/ros2-rosbot-workspace-galactic/ros2-rosbot-workspace/src/underlay/robot_pose_publisher_ros2/src/robot_pose_publisher.cpp:89:27: error: ‘Buffer’ is not a member of ‘tf2_ros’
   89 |  std::shared_ptr<tf2_ros::Buffer> tf_buffer_;
      |                           ^~~~~~

/home/levers/ros2-rosbot-workspace-galactic/ros2-rosbot-workspace/src/underlay/robot_pose_publisher_ros2/src/robot_pose_publisher.cpp:89:33: error: template argument 1 is invalid
   89 |  std::shared_ptr<tf2_ros::Buffer> tf_buffer_;
      |                                 ^

/home/levers/ros2-rosbot-workspace-galactic/ros2-rosbot-workspace/src/underlay/robot_pose_publisher_ros2/src/robot_pose_publisher.cpp: In constructor ‘RobotPosePublisher::RobotPosePublisher()’:
/home/levers/ros2-rosbot-workspace-galactic/ros2-rosbot-workspace/src/underlay/robot_pose_publisher_ros2/src/robot_pose_publisher.cpp:31:42: error: ‘Buffer’ is not a member of ‘tf2_ros’
   31 |   tf_buffer_ = std::make_shared<tf2_ros::Buffer>(this->get_clock());
      |                                          ^~~~~~

/home/levers/ros2-rosbot-workspace-galactic/ros2-rosbot-workspace/src/underlay/robot_pose_publisher_ros2/src/robot_pose_publisher.cpp:31:67: error: no matching function for call to ‘make_shared<<expression error> >(rclcpp::Clock::SharedPtr)’
   31 |   tf_buffer_ = std::make_shared<tf2_ros::Buffer>(this->get_clock());
      |                                                                   ^

In file included from /usr/include/c++/9/memory:81,
                 from /home/levers/ros2-rosbot-workspace-galactic/ros2-rosbot-workspace/src/underlay/robot_pose_publisher_ros2/src/robot_pose_publisher.cpp:13:
/usr/include/c++/9/bits/shared_ptr.h:714:5: note: candidate: ‘template<class _Tp, class ... _Args> std::shared_ptr<_Tp> std::make_shared(_Args&& ...)’
  714 |     make_shared(_Args&&... __args)
      |     ^~~~~~~~~~~

/usr/include/c++/9/bits/shared_ptr.h:714:5: note:   template argument deduction/substitution failed:
/home/levers/ros2-rosbot-workspace-galactic/ros2-rosbot-workspace/src/underlay/robot_pose_publisher_ros2/src/robot_pose_publisher.cpp:31:67: error: template argument 1 is invalid
   31 |   tf_buffer_ = std::make_shared<tf2_ros::Buffer>(this->get_clock());
      |                                                                   ^

/home/levers/ros2-rosbot-workspace-galactic/ros2-rosbot-workspace/src/underlay/robot_pose_publisher_ros2/src/robot_pose_publisher.cpp:32:64: error: invalid type argument of unary ‘*’ (have ‘int’)
   32 |   tf_listener_ = std::make_shared<tf2_ros::TransformListener>(*tf_buffer_);
      |                                                                ^~~~~~~~~~

/home/levers/ros2-rosbot-workspace-galactic/ros2-rosbot-workspace/src/underlay/robot_pose_publisher_ros2/src/robot_pose_publisher.cpp: In member function ‘void RobotPosePublisher::timer_callback()’:
/home/levers/ros2-rosbot-workspace-galactic/ros2-rosbot-workspace/src/underlay/robot_pose_publisher_ros2/src/robot_pose_publisher.cpp:56:33: error: base operand of ‘->’ is not a pointer
   56 |    transformStamped = tf_buffer_->lookupTransform(map_frame, base_frame,
      |                                 ^~

i found this stackoverflow comment regarding copy constructors: stackoverflow

I am using Ubuntu 20.04 and ROS Galactic

Best Regards

mounteverset commented 1 year ago

I don't really know why but the pointer to the tf buffer has to be a unique pointer as written here: Writing a TF2 Listener

I changed it and had no build problems. Best Regards

ZaBy10 commented 8 months ago

Here the compiler cannot find the tf2_ros::Buffer class. Ensure that your include statements look like this:

include <tf2_ros/buffer.h>

include <tf2_ros/transform_listener.h>

include the above two header files in robot_pose_publisher.cpp ......It worked for me!!!!!