00001 import ros.*; 00002 import ros.communication.*; 00003 00004 public class Talker { 00005 public static void main(String args[]) 00006 throws InterruptedException, RosException { 00007 Ros ros = Ros.getInstance(); 00008 ros.init("Talker"); 00009 00010 ros.pkg.std_msgs.msg.String msg = new ros.pkg.std_msgs.msg.String(); 00011 00012 NodeHandle n = ros.createNodeHandle(); 00013 Publisher<ros.pkg.std_msgs.msg.String> pub = 00014 n.advertise("chatter", msg, 100); 00015 00016 int count = 0; 00017 while(pub.isValid()) { 00018 msg.data = "Hello there! This is message [" + count + "]"; 00019 pub.publish(msg); 00020 ros.logInfo("I published [" + msg.data + "]"); 00021 n.spinOnce(); 00022 Thread.sleep(200); 00023 count++; 00024 } 00025 } 00026 }