March 2018
Intermediate to advanced
1396 pages
42h 14m
English
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 ...