6 #include <visualization_msgs/Marker.h> 31 typedef std::multimap<double,unsigned int>
Queue;
32 typedef std::pair<double,unsigned int>
Entry;
37 unsigned int mapSize = map->
getSize();
40 mPlan =
new double[mapSize];
41 for(
unsigned int i = 0; i < mapSize; i++)
62 Entry startPoint(0.0, start);
63 queue.insert(startPoint);
67 unsigned int x,
y, index;
83 for(
unsigned int it = 0; it < 4; it++)
85 unsigned int i = index +
mOffset[it];
94 queue.insert(
Entry(distance+linear, i));
96 mPlan[i] = distance+linear;
109 ROS_WARN(
"[MinPos] No Frontiers found after checking %d cells!", cellCount);
117 visualization_msgs::Marker marker;
118 marker.header.frame_id =
"/map";
121 marker.type = visualization_msgs::Marker::CUBE_LIST;
122 marker.action = visualization_msgs::Marker::ADD;
126 marker.pose.orientation.x = 0.0;
127 marker.pose.orientation.y = 0.0;
128 marker.pose.orientation.z = 0.0;
129 marker.pose.orientation.w = 1.0;
133 marker.color.a = 0.5;
134 marker.color.r = 1.0;
135 marker.color.g = 1.0;
136 marker.color.b = 1.0;
142 for(
unsigned int i = 0; i <
mFrontiers.size(); i++)
144 char r = rand() % 256;
145 char g = rand() % 256;
146 char b = rand() % 256;
147 for(
unsigned int j = 0; j <
mFrontiers[i].size(); j++)
153 ROS_ERROR(
"[MinPos] getCoordinates failed!");
158 marker.points[p].z = 0;
160 marker.colors[p].r = r;
161 marker.colors[p].g = g;
162 marker.colors[p].b = b;
163 marker.colors[p].a = 0.5;
175 unsigned int bestRank = 9999;
176 unsigned int bestFrontier = 0;
177 double bestDistance = 9999;
180 std::set<unsigned int> indices;
182 for(PoseList::iterator p = l.begin(); p != l.end(); p++)
184 if((
int)p->first ==
mRobotID)
continue;
187 unsigned int robot = 0;
188 if(map->
getIndex(robot_x, robot_y, robot))
190 indices.insert(robot);
191 ROS_DEBUG(
"[MinPos] Inserted robot at index %d.", robot);
194 ROS_WARN(
"[MinPos] Couldn't get index of robot %d!", p->first);
197 ROS_DEBUG(
"[MinPos] Using known positions of %d other robots.", (
int)indices.size());
199 for(
unsigned int frontier = 0; frontier <
mFrontiers.size(); frontier++)
202 double* plan =
new double[mapSize];
203 for(
unsigned int i = 0; i < mapSize; i++) plan[i] = -1;
205 unsigned int rank = 0;
206 double distanceToRobot = -1;
209 for(
unsigned int cell = 0; cell <
mFrontiers[frontier].size(); cell++)
212 frontQueue.insert(
Entry(0.0, mFrontiers[frontier][cell]));
216 while(!frontQueue.empty())
219 Queue::iterator next = frontQueue.begin();
221 unsigned int index = next->second;
222 frontQueue.erase(next);
226 distanceToRobot = distance;
229 if(indices.find(index) != indices.end()) rank++;
231 for(
unsigned int it = 0; it < 4; it++)
234 if(ind >= 0 && ind < (
int)map->
getSize() && map->
getData(ind) == 0 && plan[ind] == -1)
241 ROS_DEBUG(
"[MinPos] Frontier %d has rank %d and distance %.2f.", frontier, rank, distanceToRobot);
242 if(distanceToRobot > 0 && (rank < bestRank || (rank == bestRank && distanceToRobot < bestDistance)))
245 bestFrontier = frontier;
246 bestDistance = distanceToRobot;
250 if(bestRank == 0)
break;
254 ROS_DEBUG(
"[MinPos] Best frontier is %d.", bestFrontier);
258 ROS_ERROR(
"[MinPos] Could not determine a best frontier. (Best: %d, Available: %d)", bestFrontier+1, (
int)
mFrontiers.size());
277 frontQueue.insert(
Entry(0.0, startCell));
278 bool isBoundary =
false;
283 while(!frontQueue.empty())
286 Queue::iterator next = frontQueue.begin();
288 unsigned int index = next->second;
290 frontQueue.erase(next);
296 front.push_back(index);
300 for(
unsigned int it = 0; it < 4; it++)
void publish(const boost::shared_ptr< M > &message) const
ros::Publisher mFrontierPublisher
std::pair< double, unsigned int > Entry
TFSIMD_FORCE_INLINE const tfScalar & y() const
void findCluster(GridMap *map, unsigned int startCell)
unsigned int mFrontierCells
signed char getData(unsigned int index)
std::multimap< double, unsigned int > Queue
bool isFree(unsigned int index)
double distance(double x0, double y0, double x1, double y1)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
std::vector< unsigned int > Frontier
int findExplorationTarget(GridMap *map, unsigned int start, unsigned int &goal)
TFSIMD_FORCE_INLINE const tfScalar & x() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
std::map< unsigned int, geometry_msgs::Pose2D > PoseList
bool isFrontier(unsigned int index)
std::multimap< double, unsigned int > Queue
bool getIndex(unsigned int x, unsigned int y, unsigned int &i)
double mMinTargetAreaSize
std::pair< double, unsigned int > Entry
bool getCoordinates(unsigned int &x, unsigned int &y, unsigned int i)