6 from visualization_msgs.msg
import Marker
7 from geometry_msgs.msg
import Point
8 from nav_msgs.msg
import OccupancyGrid
10 from rrt_exploration.msg
import PointArray
12 from numpy
import array
13 from numpy
import linalg
as LA
14 from numpy
import all
as All
16 from functions
import robot,informationGain,discount
17 from numpy.linalg
import norm
20 mapData=OccupancyGrid()
22 global1=OccupancyGrid()
23 global2=OccupancyGrid()
24 global3=OccupancyGrid()
29 for point
in data.points:
30 frontiers.append(array([point.x,point.y]))
38 global frontiers,mapData,global1,global2,global3,globalmaps
39 rospy.init_node(
'assigner', anonymous=
False)
42 map_topic= rospy.get_param(
'~map_topic',
'/map')
43 info_radius= rospy.get_param(
'~info_radius',1.0)
44 info_multiplier=rospy.get_param(
'~info_multiplier',3.0)
45 hysteresis_radius=rospy.get_param(
'~hysteresis_radius',3.0)
46 hysteresis_gain=rospy.get_param(
'~hysteresis_gain',2.0)
47 frontiers_topic= rospy.get_param(
'~frontiers_topic',
'/filtered_points')
48 n_robots = rospy.get_param(
'~n_robots',1)
49 namespace = rospy.get_param(
'~namespace',
'')
50 namespace_init_count = rospy.get_param(
'namespace_init_count',1)
51 delay_after_assignement=rospy.get_param(
'~delay_after_assignement',0.5)
52 rateHz = rospy.get_param(
'~rate',100)
54 rate = rospy.Rate(rateHz)
56 rospy.Subscriber(map_topic, OccupancyGrid, mapCallBack)
57 rospy.Subscriber(frontiers_topic, PointArray, callBack)
61 while len(frontiers)<1:
63 centroids=copy(frontiers)
65 while (len(mapData.data)<1):
70 for i
in range(0,n_robots):
71 robots.append(
robot(namespace+str(i+namespace_init_count)))
72 elif len(namespace)==0:
73 robots.append(
robot(namespace))
74 for i
in range(0,n_robots):
75 robots[i].sendGoal(robots[i].getPosition())
79 while not rospy.is_shutdown():
80 centroids=copy(frontiers)
84 for ip
in range(0,len(centroids)):
85 infoGain.append(
informationGain(mapData,[centroids[ip][0],centroids[ip][1]],info_radius))
90 for i
in range(0,n_robots):
91 if (robots[i].getState()==1):
95 rospy.loginfo(
"available robots: "+str(na))
99 infoGain=
discount(mapData,robots[i].assigned_point,centroids,infoGain,info_radius)
106 for ip
in range(0,len(centroids)):
107 cost=norm(robots[ir].getPosition()-centroids[ip])
109 information_gain=infoGain[ip]
110 if (norm(robots[ir].getPosition()-centroids[ip])<=hysteresis_radius):
112 information_gain*=hysteresis_gain
113 revenue=information_gain*info_multiplier-cost
114 revenue_record.append(revenue)
115 centroid_record.append(centroids[ip])
123 for ip
in range(0,len(centroids)):
124 cost=norm(robots[ir].getPosition()-centroids[ip])
126 information_gain=infoGain[ip]
127 if (norm(robots[ir].getPosition()-centroids[ip])<=hysteresis_radius):
128 information_gain*=hysteresis_gain
130 if ((norm(centroids[ip]-robots[ir].assigned_point))<hysteresis_radius):
131 information_gain=
informationGain(mapData,[centroids[ip][0],centroids[ip][1]],info_radius)*hysteresis_gain
133 revenue=information_gain*info_multiplier-cost
134 revenue_record.append(revenue)
135 centroid_record.append(centroids[ip])
138 rospy.loginfo(
"revenue record: "+str(revenue_record))
139 rospy.loginfo(
"centroid record: "+str(centroid_record))
140 rospy.loginfo(
"robot IDs record: "+str(id_record))
143 if (len(id_record)>0):
144 winner_id=revenue_record.index(max(revenue_record))
145 robots[id_record[winner_id]].sendGoal(centroid_record[winner_id])
146 rospy.loginfo(namespace+str(namespace_init_count+id_record[winner_id])+
" assigned to "+str(centroid_record[winner_id]))
147 rospy.sleep(delay_after_assignement)
152 if __name__ ==
'__main__':
155 except rospy.ROSInterruptException:
def discount(mapData, assigned_pt, centroids, infoGain, r)
def informationGain(mapData, point, r)