0
$\begingroup$

I'm trying to transform frames using tf2 using ros2 rolling but I'm getting this error:

/usr/bin/ld: CMakeFiles/reading_laser.dir/src/reading_laser.cpp.o: in function `geometry_msgs::msg::PoseStamped_<std::allocator<void> >& tf2_ros::BufferInterface::transform<geometry_msgs::msg::PoseStamped_<std::allocator<void> > >(geometry_msgs::msg::PoseStamped_<std::allocator<void> > const&, geometry_msgs::msg::PoseStamped_<std::allocator<void> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::chrono::duration<long, std::ratio<1l, 1000000000l> >) const':
reading_laser.cpp:(.text._ZNK7tf2_ros15BufferInterface9transformIN13geometry_msgs3msg12PoseStamped_ISaIvEEEEERT_RKS7_S8_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENSt6chrono8durationIlSt5ratioILl1ELl1000000000EEEE[_ZNK7tf2_ros15BufferInterface9transformIN13geometry_msgs3msg12PoseStamped_ISaIvEEEEERT_RKS7_S8_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENSt6chrono8durationIlSt5ratioILl1ELl1000000000EEEE]+0x5a): undefined reference to `std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > > tf2::getTimestamp<geometry_msgs::msg::PoseStamped_<std::allocator<void> > >(geometry_msgs::msg::PoseStamped_<std::allocator<void> > const&)'
/usr/bin/ld: reading_laser.cpp:(.text._ZNK7tf2_ros15BufferInterface9transformIN13geometry_msgs3msg12PoseStamped_ISaIvEEEEERT_RKS7_S8_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENSt6chrono8durationIlSt5ratioILl1ELl1000000000EEEE[_ZNK7tf2_ros15BufferInterface9transformIN13geometry_msgs3msg12PoseStamped_ISaIvEEEEERT_RKS7_S8_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENSt6chrono8durationIlSt5ratioILl1ELl1000000000EEEE]+0x7a): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > tf2::getFrameId<geometry_msgs::msg::PoseStamped_<std::allocator<void> > >(geometry_msgs::msg::PoseStamped_<std::allocator<void> > const&)'
/usr/bin/ld: reading_laser.cpp:(.text._ZNK7tf2_ros15BufferInterface9transformIN13geometry_msgs3msg12PoseStamped_ISaIvEEEEERT_RKS7_S8_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENSt6chrono8durationIlSt5ratioILl1ELl1000000000EEEE[_ZNK7tf2_ros15BufferInterface9transformIN13geometry_msgs3msg12PoseStamped_ISaIvEEEEERT_RKS7_S8_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENSt6chrono8durationIlSt5ratioILl1ELl1000000000EEEE]+0xcf): undefined reference to `void tf2::doTransform<geometry_msgs::msg::PoseStamped_<std::allocator<void> > >(geometry_msgs::msg::PoseStamped_<std::allocator<void> > const&, geometry_msgs::msg::PoseStamped_<std::allocator<void> >&, geometry_msgs::msg::TransformStamped_<std::allocator<void> > const&)'

Here's my callback function

 void transform() {

        std::vector<Eigen::Vector2d> temp_pose;
        for (const auto & input_pose : poses_) {
            // transform vector poses into PoseStamped to be compatible with transform function
            geometry_msgs::msg::PoseStamped input_pose_;
            input_pose_.header.frame_id = "robot_frame";
            input_pose_.pose.position.x = input_pose(0);
            input_pose_.pose.position.y = input_pose(1);
            geometry_msgs::msg::PoseStamped output_pose;
            try {
            tf_buffer_->transform(input_pose_, output_pose, "world");
            } catch (tf2::TransformException &ex) {
            RCLCPP_ERROR(this->get_logger(), "%s",ex.what());
            }
            //transform output poses back into vector 
            temp_pose.push_back({output_pose.pose.position.x, output_pose.pose.position.y});
        }
        poses_ = temp_pose;
}

The error happens in this line

tf_buffer_->transform(input_pose_, output_pose, "world");

Here's how it's defined in the node

tf_buffer_ = std::make_unique<tf2_ros::Buffer>(this->get_clock());
subscription2_ = std::make_shared<tf2_ros::TransformListener>(*tf_buffer_);

This is how the file is configured in my CMakeLists.txt

find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(std_msgs REQUIRED)
find_package(grid_map_core REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(grid_map_cv REQUIRED)
find_package(OpenCV REQUIRED)
find_package(geometry_msgs REQUIRED)

add_executable(reading_laser src/reading_laser.cpp 
src/ShaftGrid.cpp)
    ament_target_dependencies(reading_laser rclcpp std_msgs sensor_msgs grid_map_core tf2 tf2_ros geometry_msgs grid_map_cv OpenCV)
set(targets_list
  reading_laser)

install(
  TARGETS ${targets_list}
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION lib/${PROJECT_NAME}
)

Any idea why this is happening? It doesn't happen when I use other functions such as

 tf_buffer_->lookupTransform("world", "robot_frame", rclcpp::Time(0));
$\endgroup$
2
  • $\begingroup$ Undefined reference sounds like a linker problem. How is your CMakeLists.txt file configured? Please edit your question to include it. $\endgroup$
    – Chuck
    Commented Jan 26, 2023 at 7:42
  • $\begingroup$ Done. But when i use a different function such as lookupTransform instead of Transform with the same configuration, it works fine so I'm not sure why the latter function is causing linking problems $\endgroup$
    – mh1309
    Commented Jan 26, 2023 at 8:36

1 Answer 1

1
$\begingroup$

To use type transforms you need to include the appropriate packages + link against them. When you call doTransform against a geometry_msgs, you have to include the tf2_geometry_msgs package headers and link against them to get the implementation. This allows users to create their own toTransform functions for various custom types. There's an analog as well for eigen and sensor_msgs types you should also be aware of.

https://github.com/ros2/geometry2/blob/49d4be4e8dd08282fc3bf5238459ce41d6befe6f/tf2_geometry_msgs/include/tf2_geometry_msgs/tf2_geometry_msgs.hpp

$\endgroup$
3
  • $\begingroup$ Thanks for the comment. I did that and I still get a similar error $\endgroup$
    – mh1309
    Commented Jan 30, 2023 at 8:46
  • $\begingroup$ Did you link against it too? $\endgroup$ Commented Jan 30, 2023 at 19:37
  • $\begingroup$ yes I linked it as well $\endgroup$
    – mh1309
    Commented Feb 2, 2023 at 15:53

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.