adding a frame, error during compiling
I was following this link, tf2/tutorials/adding a frame(c++), but after i put the frame_broadcaster.cpp file and compile it using catkin_make
im getting this error:
Building CXX object learning_tf2/CMakeFiles/frame_tf2_broadcaster.dir/src/frame_tf2_broadcaster.cpp.o
/home/dinesh/tf/src/learning_tf2/src/frame_tf2_broadcaster.cpp: In function ‘int main(int, char**)’:
/home/dinesh/tf/src/learning_tf2/src/frame_tf2_broadcaster.cpp:17:6: error: ‘tf2’ has not been declared
tf2::Quaternion q;
^
/home/dinesh/tf/src/learning_tf2/src/frame_tf2_broadcaster.cpp:17:22: error: expected ‘;’ before ‘q’
tf2::Quaternion q;
^
/home/dinesh/tf/src/learning_tf2/src/frame_tf2_broadcaster.cpp:18:12: error: ‘q’ was not declared in this scope
q.setRPY(0, 0, 0);
^
make[2]: *** [learning_tf2/CMake
Files/frame_tf2_broadcaster.dir/src/frame_tf2_broadcaster.cpp.o] Error 1
make[1]: *** [learning_tf2/CMakeFiles/frame_tf2_broadcaster.dir/all] Error 2
make: *** [all] Error 2
Invoking "make -j4 -l4" failed
I'm using ROS indigo 64 bit cpu.
This is the CMakeLists.txt file:
cmake_minimum_required(VERSION 2.8.3)
project(learning_tf2)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
tf2
tf2_ros
turtlesim
)
catkin_package()
include_directories(
${catkin_INCLUDE_DIRS}
)
add_executable(turtle_tf2_broadcaster src/turtle_tf2_broadcaster.cpp)
target_link_libraries(turtle_tf2_broadcaster
${catkin_LIBRARIES}
)
add_executable(turtle_tf2_listener src/turtle_tf2_listener.cpp)
target_link_libraries(turtle_tf2_listener
${catkin_LIBRARIES}
)
add_executable(frame_tf2_broadcaster src/frame_tf2_broadcaster.cpp)
target_link_libraries(frame_tf2_broadcaster
${catkin_LIBRARIES}
)
and this is frame_tf2_broadcaster.cpp file:
#include <ros/ros.h>
#include <tf2_ros/transform_broadcaster.h>
int main(int argc, char** argv){
ros::init(argc, argv, "my_tf2_broadcaster");
ros::NodeHandle node;
tf2_ros::TransformBroadcaster tfb;
geometry_msgs::TransformStamped transformStamped;
transformStamped.header.stamp = ros::Time::now();
transformStamped.header.frame_id = "turtle1";
transformStamped.child_frame_id = "carrot1";
transformStamped.transform.translation.x = 0.0;
transformStamped.transform.translation.y = 2.0;
transformStamped.transform.translation.z = 0.0;
tf2::Quaternion q;
q.setRPY(0, 0, 0);
transformStamped.transform.rotation.x = q.x();
transformStamped.transform.rotation.y = q.y();
transformStamped.transform.rotation.z = q.z();
transformStamped.transform.rotation.w = q.w();
ros::Rate rate(10.0);
while (node.ok()){
tfb.sendTransform(transformStamped);
rate.sleep();
printf("sending\n");
}
};
Looks like it's a syntax error or a dependency issue. Can you please share the
frame_tf2_broadcaster.cpp
and your CMake file? The issue will be in one of those filesI wanted to use tree frame to show point cloud in rviz and than show some markers in the same frame to visualize how the codes are analizing the points, i can do that with tf right?
ok, i hot the error, i have to change the name of ros node
my_tf2_broadcaster to
frame_tf2_broadcaster, before this also the tutorial says the launch file is in bin folder, but i found it inside lib. ok error solved.