7 #include <geometry_msgs/Point.h> 18 double potential_scale,
double gain_scale,
19 double min_frontier_size)
21 , potential_scale_(potential_scale)
22 , gain_scale_(gain_scale)
23 , min_frontier_size_(min_frontier_size)
29 std::vector<Frontier> frontier_list;
34 ROS_ERROR(
"Robot out of costmap bounds, cannot search for frontiers");
39 std::lock_guard<costmap_2d::Costmap2D::mutex_t> lock(*(
costmap_->
getMutex()));
47 std::vector<bool> visited_flag(
size_x_ * size_y_,
false);
50 std::queue<unsigned int> bfs;
58 ROS_WARN(
"Could not find nearby clear cell to start search");
60 visited_flag[bfs.front()] =
true;
62 while (!bfs.empty()) {
63 unsigned int idx = bfs.front();
70 if (
map_[nbr] <=
map_[idx] && !visited_flag[nbr]) {
71 visited_flag[nbr] =
true;
76 frontier_flag[nbr] =
true;
80 frontier_list.push_back(new_frontier);
87 for (
auto& frontier : frontier_list) {
91 frontier_list.begin(), frontier_list.end(),
98 unsigned int reference,
99 std::vector<bool>& frontier_flag)
106 output.
min_distance = std::numeric_limits<double>::infinity();
114 std::queue<unsigned int> bfs;
115 bfs.push(initial_cell);
119 double reference_x, reference_y;
123 while (!bfs.empty()) {
124 unsigned int idx = bfs.front();
132 frontier_flag[nbr] =
true;
138 geometry_msgs::Point point;
141 output.
points.push_back(point);
152 double distance = sqrt(pow((
double(reference_x) -
double(wx)), 2.0) +
153 pow((
double(reference_y) -
double(wy)), 2.0));
173 const std::vector<bool>& frontier_flag)
176 if (
map_[idx] != NO_INFORMATION || frontier_flag[idx]) {
183 if (
map_[nbr] == FREE_SPACE) {
geometry_msgs::Point centroid
geometry_msgs::Point initial
void mapToWorld(unsigned int mx, unsigned int my, double &wx, double &wy) const
std::vector< unsigned int > nhood4(unsigned int idx, const costmap_2d::Costmap2D &costmap)
Determine 4-connected neighbourhood of an input cell, checking for map edges.
bool isNewFrontierCell(unsigned int idx, const std::vector< bool > &frontier_flag)
isNewFrontierCell Evaluate if candidate cell is a valid candidate for a new frontier.
static const unsigned char FREE_SPACE
bool nearestCell(unsigned int &result, unsigned int start, unsigned char val, const costmap_2d::Costmap2D &costmap)
Find nearest cell of a specified value.
unsigned char * getCharMap() const
double frontierCost(const Frontier &frontier)
computes frontier cost
Frontier buildNewFrontier(unsigned int initial_cell, unsigned int reference, std::vector< bool > &frontier_flag)
Starting from an initial cell, build a frontier from valid adjacent cells.
double distance(double x0, double y0, double x1, double y1)
double min_frontier_size_
std::vector< unsigned int > nhood8(unsigned int idx, const costmap_2d::Costmap2D &costmap)
Determine 8-connected neighbourhood of an input cell, checking for map edges.
unsigned int getSizeInCellsY() const
std::vector< geometry_msgs::Point > points
unsigned int getSizeInCellsX() const
static const unsigned char LETHAL_OBSTACLE
costmap_2d::Costmap2D * costmap_
static const unsigned char NO_INFORMATION
void indexToCells(unsigned int index, unsigned int &mx, unsigned int &my) const
std::vector< Frontier > searchFrom(geometry_msgs::Point position)
Runs search implementation, outward from the start position.
double getResolution() const
geometry_msgs::Point middle
bool worldToMap(double wx, double wy, unsigned int &mx, unsigned int &my) const
unsigned int getIndex(unsigned int mx, unsigned int my) const