initialpose3d.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # amcl and move_base use "/map" topic and "/map" frame_id.
00004 # visualization tools use other maps.
00005 
00006 # USAGE (rviz)
00007 # Select target floor frame_id as "Fixed Frame",
00008 # Set "initialpose3d" as Estimate Topic in "Tool Propertied" Tab
00009 # then set initialpose
00010 
00011 PKG = 'tf'
00012 import roslib; roslib.load_manifest(PKG)
00013 import rospy
00014 
00015 from std_msgs.msg import String
00016 from geometry_msgs.msg import PoseWithCovarianceStamped
00017 from topic_tools.srv import MuxSelect
00018 
00019 
00020 def change_map(frame):
00021     global tf_select, map_select
00022 
00023     if frame != '/map':
00024         map_select.publish(frame)
00025 
00026     # call /mux/select "tf"
00027     try:
00028         if frame != '/map':
00029             resp = tf_select(frame+"_tf")
00030     except rospy.ServiceException, e:
00031         print "Service call failed: %s"%e
00032 
00033     rospy.set_param('/amcl/initial_map', frame)
00034 
00035 
00036 def callback(pose):
00037     global pub
00038 
00039     # change the map
00040     frame = pose.header.frame_id;
00041     change_map(frame)
00042 
00043     rospy.sleep(1) # this is bad
00044 
00045     # set initialpose
00046     pose.header.frame_id = '/map'
00047     pub.publish(pose)
00048 
00049 
00050 def listener():
00051     global pub, tf_select, map_select
00052 
00053     rospy.init_node('initialpose', anonymous=True)
00054 
00055     pub = rospy.Publisher('initialpose_out', PoseWithCovarianceStamped)
00056     tf_select = rospy.ServiceProxy('map_tf_mux/select', MuxSelect)
00057     map_select = rospy.Publisher('map_reload', String)
00058     rospy.Subscriber("initialpose_in", PoseWithCovarianceStamped, callback)
00059 
00060     initial_map = rospy.get_param('/amcl/initial_map', None)
00061 
00062     if initial_map:
00063         change_map(initial_map)
00064 
00065     rospy.spin()
00066 
00067 if __name__ == '__main__':
00068     listener()
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


jsk_maps
Author(s): Manabu Saito, Haseru Chen
autogenerated on Sat Mar 23 2013 15:46:46