2 #include <geometry_msgs/Pose2D.h> 3 #include <nav_msgs/GridCells.h> 5 typedef std::multimap<double,unsigned int>
Queue;
6 typedef std::pair<double,unsigned int>
Entry;
13 robotNode.
param(
"robot_id", mRobotID, 1);
14 robotNode.
param(
"map_frame", mMapFrame, std::string(
"map"));
21 mWaitForOthers =
false;
24 mWavefrontPublisher = navigatorNode.
advertise<nav_msgs::GridCells>(
"wave", 1);
25 mOtherWavefrontPublisher = navigatorNode.
advertise<nav_msgs::GridCells>(
"others", 1);
36 unsigned int mapSize = map->
getSize();
37 int* searchMap =
new int[mapSize];
38 for(
unsigned int i = 0; i < mapSize; i++)
45 Entry startPoint(0.0, start);
46 queue.insert(startPoint);
47 searchMap[
start] = mRobotID;
54 for(PoseList::iterator p = l.begin(); p != l.end(); p++)
56 if((
int)p->first == mRobotID)
continue;
59 unsigned int robot = 0;
60 if(map->
getIndex(robot_x, robot_y, robot))
62 queue.insert(
Entry(0.0, robot));
63 searchMap[robot] = p->first;
66 ROS_WARN(
"Couldn't place robot %d in search map!", p->first);
72 bool foundFrontier =
false;
73 bool hasFrontiers =
false;
76 std::vector<std::pair<double, double> > points;
77 std::vector<std::pair<double, double> > others;
80 while(!foundFrontier && !queue.empty())
86 unsigned int index = next->second;
88 int currentBot = searchMap[index];
94 if(currentBot == mRobotID)
102 for(
unsigned int i = 0; i < neighbors.size(); i++)
106 if(searchMap[neighbors[i]] == 0)
108 queue.insert(
Entry(distance+linear, neighbors[i]));
109 searchMap[neighbors[i]] = currentBot;
110 if(currentBot == mRobotID)
117 }
else if(searchMap[neighbors[i]] != mRobotID && currentBot == mRobotID)
120 buffer.insert(
Entry(distance+linear, neighbors[i]));
129 while(!foundFrontier && !buffer.empty())
133 next = buffer.begin();
135 unsigned int index = next->second;
141 foundFrontier =
true;
146 for(
unsigned int i = 0; i < neighbors.size(); i++)
148 if(map->
isFree(neighbors[i]) && searchMap[neighbors[i]] != mRobotID)
152 buffer.insert(
Entry(distance+linear, neighbors[i]));
153 searchMap[neighbors[i]] = mRobotID;
162 ROS_DEBUG(
"Checked %d cells.", cellCount);
165 nav_msgs::GridCells wave_msg;
166 wave_msg.header.frame_id = mMapFrame.c_str();
170 wave_msg.cells.resize(points.size());
171 for(
unsigned int i = 0; i < points.size(); i++)
173 wave_msg.cells[i].x = points[i].first;
174 wave_msg.cells[i].y = points[i].second;
175 wave_msg.cells[i].z = 0.0;
177 mWavefrontPublisher.publish(wave_msg);
179 wave_msg.cells.resize(others.size());
180 for(
unsigned int i = 0; i < others.size(); i++)
182 wave_msg.cells[i].x = others[i].first;
183 wave_msg.cells[i].y = others[i].second;
184 wave_msg.cells[i].z = 0.0;
186 mOtherWavefrontPublisher.publish(wave_msg);
191 }
else if(hasFrontiers)
193 if(buffer.size() > 0)
197 ROS_WARN(
"[MultiWave] Frontiers present, but not reachable.");
206 ROS_WARN(
"[MultiWave] No Frontiers present, but robot seems locked.");
std::pair< double, unsigned int > Entry
TFSIMD_FORCE_INLINE const tfScalar & y() const
std::multimap< double, unsigned int > Queue
std::string resolve(const std::string &prefix, const std::string &frame_name)
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::multimap< double, unsigned int > Queue
TFSIMD_FORCE_INLINE const tfScalar & x() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
std::pair< double, unsigned int > Entry
std::map< unsigned int, geometry_msgs::Pose2D > PoseList
bool isFrontier(unsigned int index)
bool getIndex(unsigned int x, unsigned int y, unsigned int &i)
int findExplorationTarget(GridMap *map, unsigned int start, unsigned int &goal)
std::vector< unsigned int > getFreeNeighbors(unsigned int index, int offset=1)
bool getCoordinates(unsigned int &x, unsigned int &y, unsigned int i)