June 2018
Intermediate to advanced
484 pages
11h 36m
English
In the previous subsection, we created a TF broadcaster to publish the pose of a turtle to TF. In this subsection, we will create a TF listener that will use that TF.
We will create a tf_tutorials/src/ turtle_tf_listener.cpp file and add the following source code to it:
#include <ros/ros.h> #include <tf/transform_listener.h> #include <geometry_msgs/Twist.h> #include <turtlesim/Spawn.h> int main(int argc, char** argv){ ros::init(argc, argv, "tf_listener"); ros::NodeHandle node; ros::service::waitForService("spawn"); ros::ServiceClient add_turtle = node.serviceClient<turtlesim::Spawn>("spawn"); turtlesim::Spawn srv; add_turtle.call(srv); ros::Publisher turtle_vel = node.advertise<geometry_msgs::Twist>("turtle2/cmd_vel", ...