Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 PKG = 'soccer_application'
00038 import roslib; roslib.load_manifest(PKG)
00039 
00040 import rospy
00041 import actionlib
00042 import random
00043 
00044 from move_base_msgs.msg import *
00045 from geometry_msgs.msg import * 
00046 
00047 from sound_play.libsoundplay import SoundClient
00048 
00049 goal_locations = [
00050  [[17.3892879486, 17.4826889038, 0.0], [0.0, 0.0, 0.565245940316, 0.824922436934]], 
00051  [[20.4999046326, 38.2641105652, 0.0], [0.0, 0.0, 0.89201005183, 0.452015561053]], 
00052  [[5.93969917297, 23.8362388611, 0.0], [0.0, 0.0, 0.553747800533, 0.83268443807]], 
00053  [[17.3893508911, 55.273021698, 0.0], [0.0, 0.0, 0.0, 1.0]], 
00054  [[51.1425704956, 44.7499580383, 0.0], [0.0, 0.0, 0.947195067571, 0.320657923604]] 
00055 ]
00056 
00057 class Navigator:
00058   def __init__(self):
00059     
00060     self.sound_client = SoundClient()
00061     self.sound_file = rospy.get_param('~file')
00062     if not self.sound_file:
00063       rospy.logerr("You didn't speicfy a sound. I'm not going to play anything... boring.")
00064     else:
00065       rospy.sleep(rospy.Duration(1.0))
00066       self.sound_client.startWave(self.sound_file)
00067 
00068     self.pose_pub = rospy.Publisher('initialpose', PoseWithCovarianceStamped)
00069     self.mb_client = actionlib.SimpleActionClient('move_base', MoveBaseAction)
00070     self.mb_client.wait_for_server()
00071     self.current_goal = None
00072 
00073   def send_goal(self, goal):
00074     goal_msg = MoveBaseGoal()
00075     goal_msg.target_pose.header.frame_id = '/map'
00076     goal_msg.target_pose.header.stamp = rospy.Time.now()
00077     goal_msg.target_pose.pose.position.x = goal[0][0]
00078     goal_msg.target_pose.pose.position.y = goal[0][1]
00079     goal_msg.target_pose.pose.position.z = goal[0][2]
00080     goal_msg.target_pose.pose.orientation.x = goal[1][0]
00081     goal_msg.target_pose.pose.orientation.y = goal[1][1]
00082     goal_msg.target_pose.pose.orientation.z = goal[1][2]
00083     goal_msg.target_pose.pose.orientation.w = goal[1][3]
00084 
00085     self.mb_client.send_goal(goal_msg, self.done_cb)
00086     self.current_goal = goal
00087 
00088   def done_cb(self, terminal_state, result):
00089     self.send_goal(goal_locations[random.randint(0, len(goal_locations) - 1)])
00090 
00091   def stop_sound(self):
00092     rospy.logerr("Can't stop sound until a bug is fixed")
00093 
00094 
00095 
00096 
00097 if __name__ == '__main__':
00098   rospy.init_node('soccer_executive')
00099   nav = Navigator()
00100   nav.send_goal(goal_locations[0])
00101 
00102   rospy.on_shutdown(nav.stop_sound)
00103 
00104   try:
00105     rospy.spin()
00106   except rospy.ROSInterruptException: pass
00107