00001 /* 00002 * rosserial_embeddedlinux subscriber example 00003 * 00004 * Prints a string sent on a subscribed ros topic. 00005 * The string can be sent with e.g. 00006 * $ rostopic pub chatter std_msgs/String -- "Hello Embedded Linux" 00007 */ 00008 00009 #include <ros.h> 00010 #include <std_msgs/String.h> 00011 #include <stdio.h> 00012 00013 ros::NodeHandle nh; 00014 char *rosSrvrIp = "192.168.15.149"; 00015 00016 void messageCb(const std_msgs::String& received_msg){ 00017 printf("Received subscribed chatter message: %s\n", received_msg.data); 00018 } 00019 ros::Subscriber<std_msgs::String> sub("chatter", messageCb ); 00020 00021 int main() 00022 { 00023 //nh.initNode(); 00024 nh.initNode(rosSrvrIp); 00025 nh.subscribe(sub); 00026 00027 while(1) { 00028 sleep(1); 00029 nh.spinOnce(); 00030 } 00031 }