announcer.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # License: BSD
00004 #   https://raw.github.com/robotics-in-concert/rocon_tutorials/master/turtle_race_concert/LICENSE
00005 #
00006 ##############################################################################
00007 # Imports
00008 ##############################################################################
00009 
00010 import rospy
00011 from std_msgs.msg import Empty
00012 
00013 
00014 ##############################################################################
00015 # Callbacks
00016 ##############################################################################
00017 
00018 class Announcer(object):
00019 
00020     def __init__(self):
00021         self._race_finished = False
00022         self._winner_publishers = {}
00023         self._winner_publishers['race_winner_one']   = rospy.Publisher("race_winner_one", Empty)
00024         self._winner_publishers['race_winner_two']   = rospy.Publisher("race_winner_two", Empty)
00025         self._winner_publishers['race_winner_three'] = rospy.Publisher("race_winner_three", Empty)
00026         self._start_publisher = rospy.Publisher("race_start", Empty)
00027         self._finished_subscribers = {}
00028         self._finished_subscribers['race_finished_one']   = rospy.Subscriber("race_finished_one",   Empty, self._race_finished_one_callback)
00029         self._finished_subscribers['race_finished_two']   = rospy.Subscriber("race_finished_two",   Empty, self._race_finished_two_callback)
00030         self._finished_subscribers['race_finished_three'] = rospy.Subscriber("race_finished_three", Empty, self._race_finished_three_callback)
00031 
00032     def start(self):
00033         self._race_finished = False
00034         self._start_publisher.publish(Empty())
00035 
00036     ##################################
00037     # Callbacks
00038     ##################################
00039     # These should be merged and use something smart to distinguish - either 
00040     # msg data or resolved namespace or something
00041 
00042     def _race_finished_one_callback(self, data):
00043         if self._race_finished:
00044             rospy.loginfo("Turtle Race Announcer : turtle one has won!")
00045             self._winner_publishers['race_winner_one'].publish(Empty())
00046     
00047     def _race_finished_two_callback(self, data):
00048         if self._race_finished:
00049             rospy.loginfo("Turtle Race Announcer : turtle two has won!")
00050             self._winner_publishers['race_winner_two'].publish(Empty())
00051     
00052     def _race_finished_three_callback(self, data):
00053         if self._race_finished:
00054             rospy.loginfo("Turtle Race Announcer : turtle three has won!")
00055             self._winner_publishers['race_winner_three'].publish(Empty())
00056 
00057 ##############################################################################
00058 # Main
00059 ##############################################################################
00060 
00061 if __name__ == '__main__':
00062     rospy.init_node('turtle_race_announcer')
00063     announcer = Announcer()
00064     for num in range(5):
00065         rospy.loginfo("Turtle Race Announcer : start in %s" % (20 - num))
00066         rospy.sleep(1)
00067     announcer.start()
00068     rospy.spin()
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends


turtle_race_concert
Author(s): Daniel Stonier , Jihoon Lee
autogenerated on Sun May 26 2013 16:45:13