$search
00001 #! /usr/bin/python 00002 #*********************************************************** 00003 #* Software License Agreement (BSD License) 00004 #* 00005 #* Copyright (c) 2009, Willow Garage, Inc. 00006 #* All rights reserved. 00007 #* 00008 #* Redistribution and use in source and binary forms, with or without 00009 #* modification, are permitted provided that the following conditions 00010 #* are met: 00011 #* 00012 #* * Redistributions of source code must retain the above copyright 00013 #* notice, this list of conditions and the following disclaimer. 00014 #* * Redistributions in binary form must reproduce the above 00015 #* copyright notice, this list of conditions and the following 00016 #* disclaimer in the documentation and/or other materials provided 00017 #* with the distribution. 00018 #* * Neither the name of Willow Garage, Inc. nor the names of its 00019 #* contributors may be used to endorse or promote products derived 00020 #* from this software without specific prior written permission. 00021 #* 00022 #* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 #* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 #* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00025 #* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00026 #* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00027 #* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00028 #* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00029 #* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 #* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 #* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00032 #* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00033 #* POSSIBILITY OF SUCH DAMAGE. 00034 #* 00035 #* Author: Eitan Marder-Eppstein 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]], # Green room 00051 [[20.4999046326, 38.2641105652, 0.0], [0.0, 0.0, 0.89201005183, 0.452015561053]], # Pool room 00052 [[5.93969917297, 23.8362388611, 0.0], [0.0, 0.0, 0.553747800533, 0.83268443807]], # Vision area 00053 [[17.3893508911, 55.273021698, 0.0], [0.0, 0.0, 0.0, 1.0]], # Near bike racks 00054 [[51.1425704956, 44.7499580383, 0.0], [0.0, 0.0, 0.947195067571, 0.320657923604]] # Outside white lab 00055 ] 00056 00057 class Navigator: 00058 def __init__(self): 00059 #start playing a sound 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 #self.sound_client.stopWave(self.sound_file) 00094 #rospy.sleep(rospy.Duration(1.0)) 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