Let's test this with a simple code. Create a new file in chapter5_tutorials/src with the name tf_broadcaster.cpp, and put the following code inside it:
#include <ros/ros.h> #include <tf/transform_broadcaster.h> int main(int argc, char** argv){ ros::init(argc, argv, "robot_tf_publisher"); ros::NodeHandle n; ros::Rate r(100); tf::TransformBroadcaster broadcaster; while(n.ok()){ broadcaster.sendTransform( tf::StampedTransform( tf::Transform(tf::Quaternion(0, 0, 0, 1), tf::Vector3(0.1,
0.0, 0.2)), ros::Time::now(),"base_link", "base_laser")); r.sleep(); } }
Remember to add the following line in your CMakelist.txt file to create the new executable:
add_executable(tf_broadcaster src/tf_broadcaster.cpp) target_link_libraries(tf_broadcaster ${catkin_LIBRARIES})
We also create another node that will use the transform, and which will give us the position of a point on the sensor with reference to the center of base_link (our robot).