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

PointStamped from tf2_ros::Buffer

asked 2020-04-19 11:47:36 -0500

connor.p gravatar image

I'm currently attempting to complete the following TF tutorial, however using TF2 instead of TF.

The part I'm struggling with is transforming the PointStamped. In standard TF the following would suffice

listener.transformPoint("base_link", laser_point, base_point);

However, from TF2 (as far as I am aware) transformPoint no longer exists and has been replaced by transform from the tf2_ros::Buffer library.

The final resulting function looks like so:

//void transformPoint(const tf::TransformListener& listener){ - TF version
    void transformPoint(const tf2_ros::Buffer& tfBuffer){
            geometry_msgs::PointStamped laser_point;

            laser_point.header.frame_id = "base_laser";

            laser_point.header.stamp = ros::Time();

            laser_point.point.x = 1.0;
            laser_point.point.y = 0.2;
            laser_point.point.z = 0.0;

            try{
                geometry_msgs::PointStamped base_point;

                //listener.transformPoint("base_link", laser_point, base_point); - TF version
                base_point = tfBuffer.transform(laser_point, "base_link");

                ROS_INFO("base_laser: (%.2f, %.2f. %.2f) -> base_link: (%.2f, %.2f, %.2f) at time %.2f",
                        laser_point.point.x, laser_point.point.y, laser_point.point.z,
                        base_point.point.x, base_point.point.y, base_point.point.z, 
                        base_point.header.stamp.toSec());

            }catch(tf2::TransformException& ex){
                 ROS_ERROR("Received ... from \"base_laser\" to \"base_link\": %s", ex.what());
            }
     }

Whilst the above code appears to pass the build stages, I receive a compile error which I'm struggling to dissect (apologies for posting such a large error message):

  CMakeFiles/tf2_listener.dir/src/tf2_listener.cpp.o: In function `geometry_msgs::PointStamped_<std::allocator<void> >& tf2_ros::BufferInterface::transform<geometry_msgs::PointStamped_<std::allocator<void> > >(geometry_msgs::PointStamped_<std::allocator<void> > const&, geometry_msgs::PointStamped_<std::allocator<void> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ros::Duration) const':
tf2_listener.cpp:(.text._ZNK7tf2_ros15BufferInterface9transformIN13geometry_msgs13PointStamped_ISaIvEEEEERT_RKS6_S7_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEN3ros8DurationE[_ZNK7tf2_ros15BufferInterface9transformIN13geometry_msgs13PointStamped_ISaIvEEEEERT_RKS6_S7_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEN3ros8DurationE]+0x69): undefined reference to `ros::Time const& tf2::getTimestamp<geometry_msgs::PointStamped_<std::allocator<void> > >(geometry_msgs::PointStamped_<std::allocator<void> > const&)'
tf2_listener.cpp:(.text._ZNK7tf2_ros15BufferInterface9transformIN13geometry_msgs13PointStamped_ISaIvEEEEERT_RKS6_S7_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEN3ros8DurationE[_ZNK7tf2_ros15BufferInterface9transformIN13geometry_msgs13PointStamped_ISaIvEEEEERT_RKS6_S7_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEN3ros8DurationE]+0x7b): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const& tf2::getFrameId<geometry_msgs::PointStamped_<std::allocator<void> > >(geometry_msgs::PointStamped_<std::allocator<void> > const&)'
tf2_listener.cpp:(.text._ZNK7tf2_ros15BufferInterface9transformIN13geometry_msgs13PointStamped_ISaIvEEEEERT_RKS6_S7_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEN3ros8DurationE[_ZNK7tf2_ros15BufferInterface9transformIN13geometry_msgs13PointStamped_ISaIvEEEEERT_RKS6_S7_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEN3ros8DurationE]+0xc8): undefined reference to `void tf2::doTransform<geometry_msgs::PointStamped_<std::allocator<void> > >(geometry_msgs::PointStamped_<std::allocator<void> > const&, geometry_msgs::PointStamped_<std::allocator<void> >&, geometry_msgs::TransformStamped_<std::allocator<void> > const&)'
collect2: error: ld returned 1 exit status
robot_setup_tf2/CMakeFiles/tf2_listener.dir/build.make:118: recipe for target '/home/connor/catkin_ws/devel/lib/robot_setup_tf2/tf2_listener' failed
make[2]: *** [/home/connor/catkin_ws/devel/lib/robot_setup_tf2/tf2_listener] Error 1
CMakeFiles/Makefile2:1469: recipe for target 'robot_setup_tf2/CMakeFiles/tf2_listener.dir/all' failed
make[1]: *** [robot_setup_tf2/CMakeFiles/tf2_listener.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j24 -l24" failed
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-04-19 11:51:56 -0500

connor.p gravatar image

-- Answering my own question --

Whilst reviewing my error message I noticed the following extract:

undefined reference to void tf2::doTransform ...

Following some research I concluded that I need to include the tf2_geometry_msgs library to allow for converting between various geometry_msgs data types.

Added code:

#include "tf2_geometry_msgs/tf2_geometry_msgs.h"

With this library now included the problem as been resolved.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-04-19 11:47:36 -0500

Seen: 543 times

Last updated: Apr 19 '20