Go to the documentation of this file.00001 #include <ros/ros.h>
00002 #include <tf/transform_broadcaster.h>
00003 #include <turtlesim/Pose.h>
00004
00005 std::string turtle_name;
00006
00007 void poseCallback(const turtlesim::PoseConstPtr& msg){
00008 static tf::TransformBroadcaster br;
00009 tf::Transform transform;
00010 transform.setOrigin( tf::Vector3(msg->x, msg->y, 0.0) );
00011 tf::Quaternion q;
00012 q.setRPY(0, 0, msg->theta);
00013 transform.setRotation(q);
00014 br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "world", turtle_name));
00015 }
00016
00017 int main(int argc, char** argv){
00018 ros::init(argc, argv, "my_tf_broadcaster");
00019 if (argc != 2){ROS_ERROR("need turtle name as argument"); return -1;};
00020 turtle_name = argv[1];
00021
00022 ros::NodeHandle node;
00023 ros::Subscriber sub = node.subscribe(turtle_name+"/pose", 10, &poseCallback);
00024
00025 ros::spin();
00026 return 0;
00027 }