listener.cpp
Go to the documentation of this file.
00001 /*
00002  * Author: Anis Koubaa for Gaitech EDU
00003  * Year: 2016
00004  *
00005  */
00006 
00007 #include "ros/ros.h"
00008 #include "std_msgs/String.h"
00009 
00010 // Topic messages callback
00011 void chatterCallback(const std_msgs::String::ConstPtr& msg)
00012 {
00013     ROS_INFO("[Listener] I heard: [%s]\n", msg->data.c_str());
00014 }
00015 
00016 int main(int argc, char **argv)
00017 {
00018     // Initiate a new ROS node named "listener"
00019         ros::init(argc, argv, "listener_node");
00020         //create a node handle: it is reference assigned to a new node
00021         ros::NodeHandle node;
00022 
00023     // Subscribe to a given topic, in this case "chatter".
00024         //chatterCallback: is the name of the callback function that will be executed each time a message is received.
00025     ros::Subscriber sub = node.subscribe("chatter", 1000, chatterCallback);
00026 
00027     // Enter a loop, pumping callbacks
00028     ros::spin();
00029 
00030     return 0;
00031 }


gapter
Author(s):
autogenerated on Thu Jun 6 2019 22:05:13