00001 #include <ros/ros.h> 00002 #include <tf/transform_broadcaster.h> 00003 #include <turtlesim/Pose.h> 00004 00005 std::string turtle_name; 00006 00007 00008 00009 void poseCallback(const turtlesim::PoseConstPtr& msg){ 00010 static tf::TransformBroadcaster br; 00011 tf::Transform transform; 00012 transform.setOrigin( tf::Vector3(msg->x, msg->y, 0.0) ); 00013 transform.setRotation( tf::Quaternion(msg->theta, 0, 0) ); 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 }; 00028