Undefined reference to "tf2::fromMsg()"
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