location_memorizer.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import roslib; roslib.load_manifest('location_memorizer')
00003 import rospy
00004 import RFNServer
00005 from geometry_msgs.msg import PoseStamped, PoseWithCovarianceStamped
00006 from location_memorizer.srv import GetLocation, GetLocationResponse
00007 
00008 pose = False # PoseStamped
00009 locations = dict() # key: string ; element: PoseStamped
00010 server = False # RFNServer
00011 
00012 
00013 def cb_pose(msg):
00014     global pose
00015     # Make msg a PoseStamped
00016     pose = PoseStamped()
00017     pose.header.frame_id = msg.goal.target_pose.header.frame_id
00018     pose.pose = msg.goal.target_pose.pose.pose
00019 
00020 
00021 def cb_get_location(srv_req):
00022     global locations, pose
00023     name = srv_req.name
00024     srv_resp = GetLocationResponse()
00025     if name in locations:
00026         loc = locations[name]
00027         srv_resp.success = True
00028         srv_resp.pose.header.frame_id = loc.header.frame_ide
00029         srv_resp.pose = loc.pose
00030     else:
00031         srv_resp.success = False
00032         # Do the least harm by returning a point close to where the user is.
00033         srv_resp.pose.header.frame_id = pose.header.frame_id
00034         srv_resp.pose = pose.pose
00035     return srv_resp
00036 
00037 
00038 def cb_remember(filled_semantic_frame):
00039     global server, pose, locations
00040     if not pose:
00041         server.set_aborted()
00042         return
00043     name = RFNServer.frame_argument("location_name")
00044     if name in locations:
00045         rospy.logwarn("The location '" + name + "' already existed.  Overwriting.")
00046     locations[name] = pose
00047     rospy.loginfo("Storing pose for location '" + name + "':\n" + pose)
00048     server.set_succeeded()
00049 
00050 
00051 
00052 def main():
00053     global server
00054     rospy.init_node('location_memorizer')
00055     rospy.Subscriber('amcl_pose', PoseWithCovarianceStamped, cb_pose)
00056     rospy.Service('get_location', GetLocation, cb_get_location)
00057 
00058     server = RFNServer("location_memorizer_rfn", cb_remember)
00059     server.register_with_frame("remembering_location")
00060 
00061     rospy.spin()
00062 
00063 
00064 if __name__ == '__main__':
00065     main()
00066 
00067 
00068 


location_memorizer
Author(s): Brian Thomas
autogenerated on Fri Dec 6 2013 20:36:24