00001 #!/usr/bin/env python 00002 import rospy 00003 from std_msgs.msg import String 00004 00005 def callback(data): 00006 rospy.loginfo(rospy.get_caller_id() + "I heard %s", data.data) 00007 00008 def listener(): 00009 00010 # In ROS, nodes are uniquely named. If two nodes with the same 00011 # node are launched, the previous one is kicked off. The 00012 # anonymous=True flag means that rospy will choose a unique 00013 # name for our 'listener' node so that multiple listeners can 00014 # run simultaneously. 00015 rospy.init_node('listener', anonymous=True) 00016 00017 rospy.Subscriber("chatter", String, callback) 00018 00019 # spin() simply keeps python from exiting until this node is stopped 00020 rospy.spin() 00021 00022 if __name__ == '__main__': 00023 listener()