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

Undefined reference to "tf2::fromMsg()"

asked 2022-04-22 05:53:18 -0500

Heho gravatar image

updated 2022-04-22 05:58:40 -0500

I have saw link and link text , but both cant solve my problem.

The error msg is follow

e(geometry_msgs::Pose_<std::allocator<void> >)': /home/bot/chh_ros_ws/src/car_navigation/navigation/car_motion_ctrl/src/ctrl_node.cpp:31: undefined reference to `void tf2::fromMsg<geometry_msgs::pose_<std::allocator<void> >, tf2::Quaternion>(geometry_msgs::Pose_<std::allocator<void> > const&, tf2::Quaternion&)' collect2: error: ld returned 1 exit status make[2]: * [car_navigation/navigation/car_motion_ctrl/CMakeFiles/ctrlNode.dir/build.make:107: /home/bot/chh_ros_ws/devel/lib/car_motion_ctrl/ctrlNode] Error 1 make[1]: [CMakeFiles/Makefile2:2583: car_navigation/navigation/car_motion_ctrl/CMakeFiles/ctrlNode.dir/all] Error 2 make: ** [Makefile:141: all] Error 2 Invoking "make -j8 -l8" failed

I has follow Tutorials to do and include correct file.

Here is my code

#include "motion_controller.h"
#include <nav_msgs/Path.h>
#include "dwa_planner.h"
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>

    bool rec_flag = 0;
    Pose_t cur_pose;

    void path_pubRECV(const nav_msgs::Path::ConstPtr msg, std::vector<Pose_t> *path)
    {
            rec_flag = true;
            Pose_t pt;
            for(int i=0; i<msg->poses.size()-1; ++i) {
                pt.x = msg->poses[i].pose.position.x;
                pt.y = msg->poses[i].pose.position.y;
                pt.yaw = atan((pt.y - msg->poses[i+1].pose.position.y)/
                            (pt.x - msg->poses[i+1].pose.position.x));
                path->push_back(pt);
            }

            pt.x = msg->poses.back().pose.position.x;
            pt.y = msg->poses.back().pose.position.y;
            pt.yaw = cur_pose.yaw;
            path->push_back(pt);
    }

    void UpdatePose(const geometry_msgs::Pose msg) {
            tf2::Quaternion quat_tf;
            tf2::fromMsg(msg, quat_tf);
            cur_pose.x = msg.position.x;
            cur_pose.y = msg.position.y;
            cur_pose.yaw = quat_tf.getAngleShortestPath();
    }



    int main(int argc, char** argv)
    {
            ros::init(argc, argv, "ctrl_node");
            ros::NodeHandle n;

            string PathName = argv[1]; 

            std::vector<Pose_t> global_path;
            ros::Subscriber path_sub = n.subscribe<nav_msgs::Path>(PathName, 1, boost::bind(&path_pubRECV, _1, &global_path));
            ros::Subscriber pos_sub = n.subscribe("car_position", 1, UpdatePose);

        .......and so on

cmake_list is cmake_minimum_required(VERSION 3.0.2) project(car_motion_ctrl) # SET(CMAKE_BUILD_TYPE Debug)

find_package(catkin REQUIRED COMPONENTS
    geometry_msgs
    nav_msgs
    roscpp
    rospy
    std_msgs
    tf2
    tf2_ros
    tf2_geometry_msgs
)

catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES car_motion_ctrl
 CATKIN_DEPENDS geometry_msgs nav_msgs roscpp rospy tf2 tf2_ros
#  DEPENDS system_lib
)

include_directories(
# include
    include/car_motionCtrl
    include/local_planner
    ${catkin_INCLUDE_DIRS}
)

add_executable(ctrlNode src/ctrl_node.cpp)
target_link_libraries(ctrlNode ${catkin_LIBRARIES})

package.xml is here

<package format="2"> <name>car_motion_ctrl</name> <version>0.0.0</version> <description>The car_motion_ctrl package</description>

    <maintainer email="heho@todo.todo">heho</maintainer>

    <license>TODO</license>

    <buildtool_depend>catkin</buildtool_depend>
    <build_depend>geometry_msgs</build_depend>
    <build_export_depend>geometry_msgs</build_export_depend>
    <exec_depend>geometry_msgs</exec_depend>
    <build_depend>tf2_geometry_msgs</build_depend>
    <build_export_depend>tf2_geometry_msgs</build_export_depend>
    <exec_depend>tf2_geometry_msgs</exec_depend>
    <build_depend>nav_msgs</build_depend>
    <build_depend>roscpp</build_depend>
    <build_depend>rospy</build_depend>
    <build_export_depend>nav_msgs</build_export_depend>
    <build_export_depend>roscpp</build_export_depend>
    <build_export_depend>rospy</build_export_depend>
    <exec_depend>nav_msgs</exec_depend>
    <exec_depend>roscpp</exec_depend>
    <exec_depend>rospy</exec_depend>
    <build_depend>tf2</build_depend>
    <build_export_depend>tf2</build_export_depend>
    <exec_depend>tf2</exec_depend>
    <build_depend>tf2_ros</build_depend>
    <build_export_depend>tf2_ros</build_export_depend>
    <exec_depend>tf2_ros</exec_depend>

    <export>
    </export>
</package>

And I should have install tf2 package, when I enter 'ls /opt/ros/noetic/lib/ | grep tf2', I got

libtf2_ros.so libtf2.so tf2_kdl tf2_ros turtle_tf2

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2022-04-23 11:10:00 -0500

Mike Scheutzow gravatar image

You have to pass just the orientation object, not the entire Pose message.

The c++ prototype in tf2_geometry_msgs.h is:

void fromMsg(const geometry_msgs::Quaternion& in, tf2::Quaternion& out)
edit flag offensive delete link more

Comments

It works! But, why? I can find another overload in tf2_geometry_msgs.h in line 440 --- void fromMsg(const geometry_msgs::Pose& in, tf2::Transform& out).

Heho gravatar image Heho  ( 2022-04-23 20:50:24 -0500 )edit

That doesn't work because a tf2:Quaternion is not a tf2:Transform.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2022-04-23 21:07:26 -0500 )edit

Oh! The editor didn't report this unmatch parameter and I ignore this... Thanks!

Heho gravatar image Heho  ( 2022-04-23 21:23:37 -0500 )edit
0

answered 2022-04-22 06:36:57 -0500

Joe28965 gravatar image

Might it have to do something with the fact that the msg is a pointer and in the example it's not?

In line 3 it creates the quat_msg, but it's not a pointer.

In callback messages you're always dealing with a pointer, have you tried sending it as a reference?

edit flag offensive delete link more

Comments

I have try that make a other_msg = msg then tf2::fromMsg() but it won't works.

Heho gravatar image Heho  ( 2022-04-22 06:51:38 -0500 )edit

Do you get the same error? Also, do you have an editor that checks your code, does it give you any errors?

Joe28965 gravatar image Joe28965  ( 2022-04-22 06:55:27 -0500 )edit

Yes, I got the same error and editor shows everything goes well.

Heho gravatar image Heho  ( 2022-04-22 06:57:31 -0500 )edit

Did you run rosdep from your workspace folder btw? (rosdep install --from-paths src --ignore-src -r -y)

Joe28965 gravatar image Joe28965  ( 2022-04-22 07:08:40 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-04-22 05:53:18 -0500

Seen: 797 times

Last updated: Apr 23 '22