Go to the documentation of this file.00001
00002 import rospy
00003 import actionlib
00004 from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
00005 from math import radians, degrees
00006 from actionlib_msgs.msg import *
00007 from geometry_msgs.msg import Point
00008 from sound_play.libsoundplay import SoundClient
00009
00010 class map_navigation():
00011
00012 def choose(self):
00013
00014 choice='q'
00015
00016 rospy.loginfo("|-------------------------------|")
00017 rospy.loginfo("|PRESSE A KEY:")
00018 rospy.loginfo("|'0': Cafe ")
00019 rospy.loginfo("|'1': Office 1 ")
00020 rospy.loginfo("|'2': Office 2 ")
00021 rospy.loginfo("|'3': Office 3 ")
00022 rospy.loginfo("|'q': Quit ")
00023 rospy.loginfo("|-------------------------------|")
00024 rospy.loginfo("|WHERE TO GO?")
00025 choice = input()
00026 return choice
00027
00028 def __init__(self):
00029
00030 sc = SoundClient()
00031 path_to_sounds = "/home/ros/catkin_ws/src/gaitech_edu/src/sounds/"
00032
00033
00034 self.xCafe = 7.31
00035 self.yCafe = 1.46
00036 self.xOffice1 = 5.10
00037 self.yOffice1 = -3.82
00038 self.xOffice2 = -2.35
00039 self.yOffice2 = -0.95
00040 self.xOffice3 = 35.20
00041 self.yOffice3 = 13.50
00042 self.goalReached = False
00043
00044 rospy.init_node('map_navigation', anonymous=False)
00045 choice = self.choose()
00046
00047 if (choice == 0):
00048
00049 self.goalReached = self.moveToGoal(self.xCafe, self.yCafe)
00050
00051 elif (choice == 1):
00052
00053 self.goalReached = self.moveToGoal(self.xOffice1, self.yOffice1)
00054
00055 elif (choice == 2):
00056
00057 self.goalReached = self.moveToGoal(self.xOffice2, self.yOffice2)
00058
00059 elif (choice == 3):
00060
00061 self.goalReached = self.moveToGoal(self.xOffice3, self.yOffice3)
00062
00063 if (choice!='q'):
00064
00065 if (self.goalReached):
00066 rospy.loginfo("Congratulations!")
00067
00068
00069 sc.playWave(path_to_sounds+"ship_bell.wav")
00070
00071
00072
00073 else:
00074 rospy.loginfo("Hard Luck!")
00075 sc.playWave(path_to_sounds+"short_buzzer.wav")
00076
00077 while choice != 'q':
00078 choice = self.choose()
00079 if (choice == 0):
00080
00081 self.goalReached = self.moveToGoal(self.xCafe, self.yCafe)
00082
00083 elif (choice == 1):
00084
00085 self.goalReached = self.moveToGoal(self.xOffice1, self.yOffice1)
00086
00087 elif (choice == 2):
00088
00089 self.goalReached = self.moveToGoal(self.xOffice2, self.yOffice2)
00090
00091 elif (choice == 3):
00092
00093 self.goalReached = self.moveToGoal(self.xOffice3, self.yOffice3)
00094
00095 if (choice!='q'):
00096
00097 if (self.goalReached):
00098 rospy.loginfo("Congratulations!")
00099
00100
00101 sc.playWave(path_to_sounds+"ship_bell.wav")
00102
00103 else:
00104 rospy.loginfo("Hard Luck!")
00105 sc.playWave(path_to_sounds+"short_buzzer.wav")
00106
00107
00108 def shutdown(self):
00109
00110 rospy.loginfo("Quit program")
00111 rospy.sleep()
00112
00113 def moveToGoal(self,xGoal,yGoal):
00114
00115
00116 ac = actionlib.SimpleActionClient("move_base", MoveBaseAction)
00117
00118
00119 while(not ac.wait_for_server(rospy.Duration.from_sec(5.0))):
00120 rospy.loginfo("Waiting for the move_base action server to come up")
00121
00122
00123 goal = MoveBaseGoal()
00124
00125
00126 goal.target_pose.header.frame_id = "map"
00127 goal.target_pose.header.stamp = rospy.Time.now()
00128
00129
00130
00131 goal.target_pose.pose.position = Point(xGoal,yGoal,0)
00132 goal.target_pose.pose.orientation.x = 0.0
00133 goal.target_pose.pose.orientation.y = 0.0
00134 goal.target_pose.pose.orientation.z = 0.0
00135 goal.target_pose.pose.orientation.w = 1.0
00136
00137 rospy.loginfo("Sending goal location ...")
00138 ac.send_goal(goal)
00139
00140 ac.wait_for_result(rospy.Duration(60))
00141
00142 if(ac.get_state() == GoalStatus.SUCCEEDED):
00143 rospy.loginfo("You have reached the destination")
00144 return True
00145
00146 else:
00147 rospy.loginfo("The robot failed to reach the destination")
00148 return False
00149
00150 if __name__ == '__main__':
00151 try:
00152
00153 rospy.loginfo("You have reached the destination")
00154 map_navigation()
00155 rospy.spin()
00156 except rospy.ROSInterruptException:
00157 rospy.loginfo("map_navigation node terminated.")