00001
00002
00003 from map_mux.srv import *
00004 import rospy
00005 import time
00006 import rosparam
00007 import rospkg
00008 import os
00009 from std_msgs.msg import String
00010 from std_msgs.msg import Int16
00011 from nav_msgs.msg import OccupancyGrid
00012 from nav_msgs.srv import GetMap
00013 from nav_msgs.msg import MapMetaData
00014 from geometry_msgs.msg import PoseWithCovarianceStamped
00015
00016 map1 = None
00017 map2 = None
00018 map3 = None
00019 change_map = None
00020 flag = None
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 initalPositionFloor2 = PoseWithCovarianceStamped()
00034 initalPositionFloor2.header.seq = 0
00035
00036
00037 initalPositionFloor2.header.frame_id = "map"
00038 initalPositionFloor2.pose.pose.position.x = 24.46
00039 initalPositionFloor2.pose.pose.position.y = 29.62
00040 initalPositionFloor2.pose.pose.position.z = 0
00041 initalPositionFloor2.pose.pose.orientation.x = 0
00042 initalPositionFloor2.pose.pose.orientation.y = 0
00043 initalPositionFloor2.pose.pose.orientation.z = 0.76631578005
00044 initalPositionFloor2.pose.pose.orientation.w = 0.642464104247
00045 initalPositionFloor2.pose.covariance = [0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.06853891945200942]
00046
00047 initalPositionFloor3 = PoseWithCovarianceStamped()
00048 initalPositionFloor3.header.seq = 0
00049 initalPositionFloor3.header.frame_id = "map"
00050 initalPositionFloor3.pose.pose.position.x = 32.85366
00051 initalPositionFloor3.pose.pose.position.y = 7.262574
00052 initalPositionFloor3.pose.pose.position.z = 0
00053 initalPositionFloor3.pose.pose.orientation.x = 0
00054 initalPositionFloor3.pose.pose.orientation.y = 0
00055
00056
00057 initalPositionFloor3.pose.pose.orientation.z = 0.6154
00058 initalPositionFloor3.pose.pose.orientation.w = 0.78819
00059 initalPositionFloor3.pose.covariance = [0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.06853891945200942]
00060
00061
00062 def map_mux():
00063
00064 rospy.init_node("map_mux", anonymous=True)
00065
00066 rospy.Subscriber("map1", OccupancyGrid, addMap1)
00067 rospy.Subscriber("map2", OccupancyGrid, addMap2)
00068 rospy.Subscriber("map3", OccupancyGrid, addMap3)
00069
00070 topic = rospy.resolve_name("map")
00071 pub = rospy.Publisher("map", OccupancyGrid)
00072 topic = rospy.resolve_name("map_metadata")
00073 pub_metadata = rospy.Publisher("map_metadata", MapMetaData)
00074 initialPosePub = rospy.Publisher("initialpose", PoseWithCovarianceStamped)
00075 global change_map
00076 global flag
00077
00078 s = rospy.Service('change_map', ChangeMap, changeMapfunc)
00079 s = rospy.Service('static_map', GetMap, staticMapfunc)
00080
00081 service_floor_switch = rospy.ServiceProxy("floor_switch", ChangeMap)
00082 rp = rospkg.RosPack()
00083 try:
00084 path = rp.get_path("map_mux") + "/src"
00085 except rospkg.ResourceNotFound:
00086 print "package not found"
00087 print path
00088 print "waiting for floor_switch to come up"
00089
00090
00091
00092 r = rospy.Rate(.1)
00093 old_change_map = 0
00094
00095 while not rospy.is_shutdown():
00096 if( map1 == None and map2 == None and map3 == None):
00097 print "you need to provide 3 maps on topics map1 map2 map3 from a launch file."
00098
00099 if (1):
00100 if (change_map == 1 and map1 != None):
00101 rospy.loginfo("changing to 1")
00102 pub.publish(map1)
00103 pub_metadata.publish(map1.info)
00104 if (change_map == 2 and map2 != None and flag ==1 ):
00105 rospy.loginfo("changing to 2")
00106 pub.publish(map2)
00107 pub_metadata.publish(map2.info)
00108
00109 try:
00110 initialPosePub.publish(initalPositionFloor2)
00111 rosparam.set_param("/segbot_logical_navigator/door_file",
00112 rp.get_path("bwi_kr") + "/config/multi_map/atrium_doors.yaml")
00113 rosparam.set_param("/segbot_logical_navigator/location_file",
00114 rp.get_path("bwi_kr") + "/config/multi_map/atrium_locations.yaml")
00115 rosparam.set_param("/segbot_logical_navigator/object_file",
00116 rp.get_path("bwi_kr") + "/config/multi_map/atrium_objects.yaml")
00117 rosparam.set_param("/segbot_logical_navigator/map_file",
00118 rp.get_path("map_mux") + "/maps/atrium_with_elevators.yaml")
00119
00120 resp_floor_switch = service_floor_switch(change_map)
00121 except rospy.ServiceException:
00122 print "floor switch service call failed"
00123 print "done with floor 2"
00124 flag = 0
00125 if (change_map == 3 and map3 != None and flag ==1 ):
00126 rospy.loginfo("changing to 3")
00127 pub.publish(map3)
00128 pub_metadata.publish(map3.info)
00129 try:
00130 initialPosePub.publish(initalPositionFloor3)
00131 rosparam.set_param("/segbot_logical_navigator/door_file",
00132 rp.get_path("bwi_kr") + "/config/multi_map/3ne_doors.yaml")
00133 rosparam.set_param("/segbot_logical_navigator/location_file",
00134 rp.get_path("bwi_kr") + "/config/multi_map/3ne_locations.yaml")
00135 rosparam.set_param("/segbot_logical_navigator/object_file",
00136 rp.get_path("bwi_kr") + "/config/multi_map/3ne_objects.yaml")
00137 rosparam.set_param("/segbot_logical_navigator/map_file",
00138 rp.get_path("map_mux") + "/maps/map_whole2_with_elevators.yaml")
00139
00140 resp_floor_switch = service_floor_switch(change_map)
00141 except rospy.ServiceException:
00142 print "floor switch service call failed"
00143 print "done with floor 3"
00144 flag = 0
00145 old_change_map = change_map
00146
00147
00148
00149
00150
00151
00152 def addMap1(data):
00153
00154 global map1
00155 map1 = data
00156 def addMap2(data):
00157 global map2
00158 map2 = data
00159 def addMap3(data):
00160 global map3
00161 map3 = data
00162 def changeMapfunc( data):
00163 print "the service made it here"
00164 global change_map
00165 global flag
00166 flag = 1
00167 change_map = data.data
00168 while(1):
00169 if (flag == 0): break
00170 return 1
00171 def staticMapfunc( data):
00172 global change_map
00173 return change_map
00174
00175 if __name__ == '__main__':
00176 try:
00177 map_mux()
00178 except rospy.ROSInterruptException: pass
00179 rospy.spin()
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192