49 CostmapProhibitionLayer::CostmapProhibitionLayer() : _dsrv(NULL)
64 _dsrv =
new dynamic_reconfigure::Server<CostmapProhibitionLayerConfig>(nh);
65 dynamic_reconfigure::Server<CostmapProhibitionLayerConfig>::CallbackType cb =
67 _dsrv->setCallback(cb);
78 std::string params =
"prohibition_areas";
83 nh.
param(
"fill_polygons", _fill_polygons, _fill_polygons);
88 ROS_INFO(
"CostmapProhibitionLayer initialized.");
99 double *min_x,
double *min_y,
double *max_x,
double *max_y)
109 *min_x = std::min(*min_x,
_min_x);
110 *min_y = std::min(*min_y,
_min_y);
111 *max_x = std::max(*max_x,
_max_x);
112 *max_y = std::max(*max_y,
_max_y);
136 master_grid.
setCost(mx, my, LETHAL_OBSTACLE);
176 int min_i,
int min_j,
int max_i,
int max_j,
bool fill_polygon)
178 std::vector<PointInt> map_polygon;
179 for (
unsigned int i = 0; i < polygon.size(); ++i)
183 map_polygon.push_back(loc);
186 std::vector<PointInt> polygon_cells;
192 for (
unsigned int i = 0; i < polygon_cells.size(); ++i)
194 int mx = polygon_cells[i].x;
195 int my = polygon_cells[i].y;
197 if (mx < min_i || mx >= max_i)
199 if (my < min_j || my >= max_j)
201 master_grid.
setCost(mx, my, cost);
208 for (
unsigned int i = 0; i < polygon.size() - 1; ++i)
210 raytrace(polygon[i].
x, polygon[i].
y, polygon[i + 1].x, polygon[i + 1].y, polygon_cells);
212 if (!polygon.empty())
214 unsigned int last_index = polygon.size() - 1;
216 raytrace(polygon[last_index].
x, polygon[last_index].
y, polygon[0].x, polygon[0].y, polygon_cells);
222 int dx = abs(x1 - x0);
223 int dy = abs(y1 - y0);
228 int x_inc = (x1 > x0) ? 1 : -1;
229 int y_inc = (y1 > y0) ? 1 : -1;
257 if(polygon.size() < 3)
269 while(i < polygon_cells.size() - 1)
271 if(polygon_cells[i].
x > polygon_cells[i + 1].
x)
273 swap = polygon_cells[i];
274 polygon_cells[i] = polygon_cells[i + 1];
275 polygon_cells[i + 1] = swap;
287 int min_x = polygon_cells[0].
x;
288 int max_x = polygon_cells[(int)polygon_cells.size() -1].x;
291 for(
int x = min_x;
x <= max_x; ++
x)
293 if(i >= (
int)polygon_cells.size() - 1)
296 if(polygon_cells[i].
y < polygon_cells[i + 1].
y)
298 min_pt = polygon_cells[i];
299 max_pt = polygon_cells[i + 1];
303 min_pt = polygon_cells[i + 1];
304 max_pt = polygon_cells[i];
308 while(i < polygon_cells.size() && polygon_cells[i].x ==
x)
310 if(polygon_cells[i].
y < min_pt.
y)
311 min_pt = polygon_cells[i];
312 else if(polygon_cells[i].
y > max_pt.
y)
313 max_pt = polygon_cells[i];
319 for(
int y = min_pt.
y;
y < max_pt.
y; ++
y)
323 polygon_cells.push_back(pt);
332 std::unordered_map<std::string, geometry_msgs::Pose> map_out;
338 if (nhandle->
getParam(param, param_yaml))
342 for (
int i = 0; i < param_yaml.
size(); ++i)
346 std::vector<geometry_msgs::Point> vector_to_add;
355 if (param_yaml[i].size() == 1)
357 geometry_msgs::Point point;
358 ret_val =
getPoint(param_yaml[i][0], point);
362 else if (param_yaml[i].size() == 2)
368 geometry_msgs::Point point;
369 ret_val =
getPoint(param_yaml[i], point);
375 geometry_msgs::Point point_A;
376 ret_val =
getPoint(param_yaml[i][0], point_A);
377 vector_to_add.push_back(point_A);
379 geometry_msgs::Point point_B;
380 ret_val =
getPoint(param_yaml[i][1], point_B);
381 vector_to_add.push_back(point_B);
384 geometry_msgs::Point point_N;
385 point_N.x = point_B.y - point_A.y;
386 point_N.y = point_A.x - point_B.x;
390 double abs_N = sqrt(pow(point_N.x, 2) + pow(point_N.y, 2));
395 geometry_msgs::Point point;
396 point.x = point_A.x + point_N.x;
397 point.y = point_A.y + point_N.y;
398 vector_to_add.push_back(point);
400 point.x = point_B.x + point_N.x;
401 point.y = point_B.y + point_N.y;
402 vector_to_add.push_back(point);
408 else if (param_yaml[i].size() >= 3)
411 for (
int j = 0; j < param_yaml[i].
size(); ++j)
413 geometry_msgs::Point point;
414 ret_val =
getPoint(param_yaml[i][j], point);
415 vector_to_add.push_back(point);
422 ROS_ERROR_STREAM(
"Prohibition Layer:" << param <<
" with index " << i <<
" is not correct.");
429 ROS_ERROR_STREAM(
"Prohibition Layer: " << param <<
"struct is not correct.");
435 ROS_ERROR_STREAM(
"Prohibition Layer: Cannot read " << param <<
" from parameter server");
456 point.x = convDouble(val[0]);
457 point.y = convDouble(val[1]);
void setCost(unsigned int mx, unsigned int my, unsigned char cost)
const std::string & getMessage() const
bool parseProhibitionListFromYaml(ros::NodeHandle *nhandle, const std::string ¶m)
LayeredCostmap * layered_costmap_
virtual void updateBounds(double robot_x, double robot_y, double robot_yaw, double *min_x, double *min_y, double *max_x, double *max_y)
virtual void updateCosts(costmap_2d::Costmap2D &master_grid, int min_i, int min_j, int max_i, int max_j)
virtual ~CostmapProhibitionLayer()
virtual void onInitialize()
PLUGINLIB_EXPORT_CLASS(BAGReader, nodelet::Nodelet)
std::vector< geometry_msgs::Point > _prohibition_points
vector to save the lonely points in source coordinates
Type const & getType() const
TFSIMD_FORCE_INLINE const tfScalar & y() const
void reconfigureCB(CostmapProhibitionLayerConfig &config, uint32_t level)
void rasterizePolygon(const std::vector< PointInt > &polygon, std::vector< PointInt > &polygon_cells, bool fill)
bool getPoint(XmlRpc::XmlRpcValue &val, geometry_msgs::Point &point)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
bool _fill_polygons
if true, all cells that are located in the interior of polygons are marked as obstacle as well ...
std::mutex _data_mutex
mutex for the accessing _prohibition_points and _prohibition_polygons
const std::string & getNamespace() const
void raytrace(int x0, int y0, int x1, int y1, std::vector< PointInt > &cells)
TFSIMD_FORCE_INLINE const tfScalar & x() const
void worldToMapNoBounds(double wx, double wy, int &mx, int &my) const
double _max_y
cached map bounds
bool getParam(const std::string &key, std::string &s) const
dynamic_reconfigure::Server< CostmapProhibitionLayerConfig > * _dsrv
dynamic_reconfigure server for the costmap
double getResolution() const
#define ROS_ERROR_STREAM(args)
double _costmap_resolution
resolution of the overlayed costmap to create the thinnest line out of two points ...
void polygonOutlineCells(const std::vector< PointInt > &polygon, std::vector< PointInt > &polygon_cells)
std::vector< std::vector< geometry_msgs::Point > > _prohibition_polygons
vector to save the polygons (including lines) in source coordinates
bool worldToMap(double wx, double wy, unsigned int &mx, unsigned int &my) const
void setPolygonCost(costmap_2d::Costmap2D &master_grid, const std::vector< geometry_msgs::Point > &polygon, unsigned char cost, int min_i, int min_j, int max_i, int max_j, bool fill_polygon)