Go to the documentation of this file.00001
00002 import roslib; roslib.load_manifest('move_base_rfn')
00003 import rospy
00004 from rfnserver import RFNServer
00005 from geometry_msgs.msg import Pose
00006 from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
00007 from location_memorizer.srv import GetLocation, GetLocationRequest
00008
00009 from tf.transformations import quaternion_from_euler
00010
00011 from actionlib import SimpleActionClient, SimpleGoalState
00012
00013 class TNavRFN:
00014 def __init__(self):
00015 self.navclient = SimpleActionClient("move_base", MoveBaseAction)
00016 self.rfnserver = RFNServer("navigation", self.cb_rfn_start)
00017 self.rfnserver.register_with_frame("navigating_to_location")
00018 self.rfnserver.start()
00019
00020
00021 def location_to_pose(self, location):
00022 position = False
00023 orientation = False
00024 if location == "room":
00025 position = (17.590, 21.611, 0.000)
00026 orientation = (0.000, 0.000, -0.232, 0.973)
00027 elif location == "office":
00028 position = (19.243, 26.436, 0.000)
00029 orientation = (0.000, 0.000, 0.534, 0.846)
00030 elif location == "fridge":
00031 position = (21.458, 37.838, 0.000)
00032 orientation = (0.000, 0.000, -0.198, 0.980)
00033 elif location == "hangout":
00034 position = (15.828, 17.155, 0.000)
00035 orientation = (0.000, 0.000, -0.072, 0.997)
00036
00037
00038
00039 else:
00040 return False
00041 goal_pose = Pose()
00042 goal_pose.position.x = position[0]
00043 goal_pose.position.y = position[1]
00044 goal_pose.position.z = position[2]
00045 goal_pose.orientation.x = orientation[0]
00046 goal_pose.orientation.y = orientation[1]
00047 goal_pose.orientation.z = orientation[2]
00048 goal_pose.orientation.w = orientation[3]
00049 return goal_pose
00050
00051
00052 def cb_rfn_start(self, filled_semantic_frame):
00053
00054 if not self.navclient.wait_for_server(timeout=rospy.Duration(5.0)):
00055 rospy.logwarn("Nav client unavailable!")
00056 self.rfnserver.set_aborted()
00057 return
00058
00059
00060 goal_location = RFNServer.frame_argument(filled_semantic_frame,
00061 "location")
00062 goal_pose = self.location_to_pose(goal_location)
00063 if goal_pose:
00064 goal = MoveBaseGoal()
00065 goal.target_pose.pose = goal_pose
00066 goal.target_pose.header.frame_id = "/map"
00067 rospy.loginfo("Sending goal:\n" + str(goal))
00068 self.navclient.send_goal(goal)
00069 else:
00070 rospy.logerr("I don't know the location " + goal_location)
00071 self.rfnserver.set_aborted()
00072 return
00073
00074 r = rospy.Rate(10)
00075 while(not self.rfnserver.is_preempt_requested() and
00076
00077 not self.navclient.simple_state == SimpleGoalState.DONE and
00078 not rospy.is_shutdown()):
00079 r.sleep()
00080 if self.rfnserver.is_preempt_requested():
00081 self.navclient.cancel_all_goals()
00082 self.rfnserver.set_preempted()
00083 return
00084 if self.navclient.simple_state == SimpleGoalState.DONE:
00085 self.rfnserver.set_succeeded()
00086 return
00087 if rospy.is_shutdown():
00088 self.rfnserver.set_aborted()
00089 return
00090 self.rfnserver.set_aborted()
00091 return
00092
00093
00094 def cb_rfn_preempt(self):
00095
00096 rospy.loginfo("move_base_rfn: Cancelling goals.")
00097 navclient.cancel_all_goals()
00098 self.rfnserver.set_preempted()
00099 return
00100
00101
00102
00103 def main():
00104 rospy.init_node('move_base_rfn')
00105 t = TNavRFN()
00106 rospy.spin()
00107
00108
00109 if __name__ == '__main__':
00110 main()
00111
00112
00113