Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
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
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
00040 frame = pose.header.frame_id;
00041 change_map(frame)
00042
00043 rospy.sleep(1)
00044
00045
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()