June 2018
Intermediate to advanced
484 pages
11h 36m
English
First, we will create a ros package in our workspace or copy the chapter3_tutorials/tf_tutorials file from GitHub:
$ catkin_create_pkg tf_tutorials tf roscpp rospy turtlesim
Next, we will create the tf_tutorials/src/turtle_tf_broadcaster.cpp file and add the source code:
#include <ros/ros.h> #include <tf/transform_broadcaster.h> #include <turtlesim/Pose.h> std::string turtle_name; void poseCallback(const turtlesim::PoseConstPtr& msg){ static tf::TransformBroadcaster br; tf::Transform transform; transform.setOrigin( tf::Vector3(msg->x, msg->y, 0.0) ); tf::Quaternion q; q.setRPY(0, 0, msg->theta); transform.setRotation(q); br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "world", turtle_name)); } ...