Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
costmap_2d.cpp
1 /*********************************************************************
2  *
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2008, 2013, Willow Garage, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Willow Garage, Inc. nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  * Author: Eitan Marder-Eppstein
36  * David V. Lu!!
37  *********************************************************************/
38 #include "nav2_costmap_2d/costmap_2d.hpp"
39 
40 #include <algorithm>
41 #include <cstdio>
42 #include <string>
43 #include <vector>
44 #include "nav2_costmap_2d/cost_values.hpp"
45 #include "nav2_util/occ_grid_values.hpp"
46 #include "nav2_util/raytrace_line_2d.hpp"
47 
48 namespace nav2_costmap_2d
49 {
51  unsigned int cells_size_x, unsigned int cells_size_y, double resolution,
52  double origin_x, double origin_y, unsigned char default_value)
53 : resolution_(resolution), origin_x_(origin_x),
54  origin_y_(origin_y), costmap_(NULL), default_value_(default_value)
55 {
56  access_ = new mutex_t();
57 
58  // create the costmap
59  initMaps(cells_size_x, cells_size_y);
60  resetMaps();
61 }
62 
63 Costmap2D::Costmap2D(const nav_msgs::msg::OccupancyGrid & map)
64 : default_value_(FREE_SPACE)
65 {
66  access_ = new mutex_t();
67 
68  // fill local variables
69  size_x_ = map.info.width;
70  size_y_ = map.info.height;
71  resolution_ = map.info.resolution;
72  origin_x_ = map.info.origin.position.x;
73  origin_y_ = map.info.origin.position.y;
74 
75  // create the costmap
76  costmap_ = new unsigned char[size_x_ * size_y_];
77 
78  // fill the costmap with a data
79  int8_t data;
80  for (unsigned int it = 0; it < size_x_ * size_y_; it++) {
81  data = map.data[it];
82  if (data == nav2_util::OCC_GRID_UNKNOWN) {
83  costmap_[it] = NO_INFORMATION;
84  } else {
85  // Linear conversion from OccupancyGrid data range [OCC_GRID_FREE..OCC_GRID_OCCUPIED]
86  // to costmap data range [FREE_SPACE..LETHAL_OBSTACLE]
87  costmap_[it] = std::round(
88  static_cast<double>(data) * (LETHAL_OBSTACLE - FREE_SPACE) /
89  (nav2_util::OCC_GRID_OCCUPIED - nav2_util::OCC_GRID_FREE));
90  }
91  }
92 }
93 
95 {
96  // clean up data
97  std::unique_lock<mutex_t> lock(*access_);
98  delete[] costmap_;
99  costmap_ = NULL;
100 }
101 
102 void Costmap2D::initMaps(unsigned int size_x, unsigned int size_y)
103 {
104  std::unique_lock<mutex_t> lock(*access_);
105  delete[] costmap_;
106  size_x_ = size_x;
107  size_y_ = size_y;
108  costmap_ = new unsigned char[size_x * size_y];
109 }
110 
112  unsigned int size_x, unsigned int size_y, double resolution,
113  double origin_x, double origin_y)
114 {
115  resolution_ = resolution;
116  origin_x_ = origin_x;
117  origin_y_ = origin_y;
118 
119  initMaps(size_x, size_y);
120 
121  // reset our maps to have no information
122  resetMaps();
123 }
124 
126 {
127  std::unique_lock<mutex_t> lock(*access_);
128  memset(costmap_, default_value_, size_x_ * size_y_ * sizeof(unsigned char));
129 }
130 
131 void Costmap2D::resetMap(unsigned int x0, unsigned int y0, unsigned int xn, unsigned int yn)
132 {
133  resetMapToValue(x0, y0, xn, yn, default_value_);
134 }
135 
137  unsigned int x0, unsigned int y0, unsigned int xn, unsigned int yn, unsigned char value)
138 {
139  std::unique_lock<mutex_t> lock(*(access_));
140  unsigned int len = xn - x0;
141  for (unsigned int y = y0 * size_x_ + x0; y < yn * size_x_ + x0; y += size_x_) {
142  memset(costmap_ + y, value, len * sizeof(unsigned char));
143  }
144 }
145 
147  const Costmap2D & map, double win_origin_x, double win_origin_y,
148  double win_size_x,
149  double win_size_y)
150 {
151  // check for self windowing
152  if (this == &map) {
153  // ROS_ERROR("Cannot convert this costmap into a window of itself");
154  return false;
155  }
156 
157  // clean up old data
158  deleteMaps();
159 
160  // compute the bounds of our new map
161  unsigned int lower_left_x, lower_left_y, upper_right_x, upper_right_y;
162  if (!map.worldToMap(win_origin_x, win_origin_y, lower_left_x, lower_left_y) ||
163  !map.worldToMap(
164  win_origin_x + win_size_x, win_origin_y + win_size_y, upper_right_x,
165  upper_right_y))
166  {
167  // ROS_ERROR("Cannot window a map that the window bounds don't fit inside of");
168  return false;
169  }
170  resolution_ = map.resolution_;
171  origin_x_ = win_origin_x;
172  origin_y_ = win_origin_y;
173 
174  // initialize our various maps and reset markers for inflation
175  initMaps(upper_right_x - lower_left_x, upper_right_y - lower_left_y);
176 
177  // copy the window of the static map and the costmap that we're taking
179  map.costmap_, lower_left_x, lower_left_y, map.size_x_, costmap_, 0, 0, size_x_,
180  size_x_,
181  size_y_);
182  return true;
183 }
184 
186  const Costmap2D & source,
187  unsigned int sx0, unsigned int sy0, unsigned int sxn, unsigned int syn,
188  unsigned int dx0, unsigned int dy0)
189 {
190  const unsigned int sz_x = sxn - sx0;
191  const unsigned int sz_y = syn - sy0;
192 
193  if (sxn > source.getSizeInCellsX() || syn > source.getSizeInCellsY()) {
194  return false;
195  }
196 
197  if (dx0 + sz_x > size_x_ || dy0 + sz_y > size_y_) {
198  return false;
199  }
200 
202  source.costmap_, sx0, sy0, source.size_x_,
203  costmap_, dx0, dy0, size_x_,
204  sz_x, sz_y);
205  return true;
206 }
207 
209 {
210  // check for self assignment
211  if (this == &map) {
212  return *this;
213  }
214 
215  // clean up old data
216  deleteMaps();
217 
218  size_x_ = map.size_x_;
219  size_y_ = map.size_y_;
220  resolution_ = map.resolution_;
221  origin_x_ = map.origin_x_;
222  origin_y_ = map.origin_y_;
223  default_value_ = map.default_value_;
224 
225  // initialize our various maps
226  initMaps(size_x_, size_y_);
227 
228  // copy the cost map
229  memcpy(costmap_, map.costmap_, size_x_ * size_y_ * sizeof(unsigned char));
230 
231  return *this;
232 }
233 
235 : costmap_(NULL)
236 {
237  access_ = new mutex_t();
238  *this = map;
239 }
240 
241 // just initialize everything to NULL by default
243 : size_x_(0), size_y_(0), resolution_(0.0), origin_x_(0.0), origin_y_(0.0), costmap_(NULL)
244 {
245  access_ = new mutex_t();
246 }
247 
249 {
250  deleteMaps();
251  delete access_;
252 }
253 
254 unsigned int Costmap2D::cellDistance(double world_dist)
255 {
256  double cells_dist = std::max(0.0, ceil(world_dist / resolution_));
257  return (unsigned int)cells_dist;
258 }
259 
260 unsigned char * Costmap2D::getCharMap() const
261 {
262  return costmap_;
263 }
264 
265 unsigned char Costmap2D::getCost(unsigned int mx, unsigned int my) const
266 {
267  return costmap_[getIndex(mx, my)];
268 }
269 
270 unsigned char Costmap2D::getCost(unsigned int undex) const
271 {
272  return costmap_[undex];
273 }
274 
275 void Costmap2D::setCost(unsigned int mx, unsigned int my, unsigned char cost)
276 {
277  costmap_[getIndex(mx, my)] = cost;
278 }
279 
280 void Costmap2D::mapToWorld(unsigned int mx, unsigned int my, double & wx, double & wy) const
281 {
282  wx = origin_x_ + (mx + 0.5) * resolution_;
283  wy = origin_y_ + (my + 0.5) * resolution_;
284 }
285 
286 void Costmap2D::mapToWorldNoBounds(int mx, int my, double & wx, double & wy) const
287 {
288  wx = origin_x_ + (mx + 0.5) * resolution_;
289  wy = origin_y_ + (my + 0.5) * resolution_;
290 }
291 
292 bool Costmap2D::worldToMap(double wx, double wy, unsigned int & mx, unsigned int & my) const
293 {
294  if (wx < origin_x_ || wy < origin_y_) {
295  return false;
296  }
297 
298  mx = static_cast<unsigned int>((wx - origin_x_) / resolution_);
299  my = static_cast<unsigned int>((wy - origin_y_) / resolution_);
300 
301  if (mx < size_x_ && my < size_y_) {
302  return true;
303  }
304  return false;
305 }
306 
307 bool Costmap2D::worldToMapContinuous(double wx, double wy, float & mx, float & my) const
308 {
309  if (wx < origin_x_ || wy < origin_y_) {
310  return false;
311  }
312 
313  mx = static_cast<float>((wx - origin_x_) / resolution_);
314  my = static_cast<float>((wy - origin_y_) / resolution_);
315 
316  if (mx < size_x_ && my < size_y_) {
317  return true;
318  }
319  return false;
320 }
321 
322 void Costmap2D::worldToMapNoBounds(double wx, double wy, int & mx, int & my) const
323 {
324  mx = static_cast<int>((wx - origin_x_) / resolution_);
325  my = static_cast<int>((wy - origin_y_) / resolution_);
326 }
327 
328 void Costmap2D::worldToMapEnforceBounds(double wx, double wy, int & mx, int & my) const
329 {
330  // Here we avoid doing any math to wx,wy before comparing them to
331  // the bounds, so their values can go out to the max and min values
332  // of double floating point.
333  if (wx < origin_x_) {
334  mx = 0;
335  } else if (wx > resolution_ * size_x_ + origin_x_) {
336  mx = size_x_ - 1;
337  } else {
338  mx = static_cast<int>((wx - origin_x_) / resolution_);
339  }
340 
341  if (wy < origin_y_) {
342  my = 0;
343  } else if (wy > resolution_ * size_y_ + origin_y_) {
344  my = size_y_ - 1;
345  } else {
346  my = static_cast<int>((wy - origin_y_) / resolution_);
347  }
348 }
349 
350 void Costmap2D::updateOrigin(double new_origin_x, double new_origin_y)
351 {
352  // project the new origin into the grid
353  int cell_ox, cell_oy;
354  cell_ox = static_cast<int>((new_origin_x - origin_x_) / resolution_);
355  cell_oy = static_cast<int>((new_origin_y - origin_y_) / resolution_);
356 
357  // compute the associated world coordinates for the origin cell
358  // because we want to keep things grid-aligned
359  double new_grid_ox, new_grid_oy;
360  new_grid_ox = origin_x_ + cell_ox * resolution_;
361  new_grid_oy = origin_y_ + cell_oy * resolution_;
362 
363  // To save casting from unsigned int to int a bunch of times
364  int size_x = size_x_;
365  int size_y = size_y_;
366 
367  // we need to compute the overlap of the new and existing windows
368  int lower_left_x, lower_left_y, upper_right_x, upper_right_y;
369  lower_left_x = std::min(std::max(cell_ox, 0), size_x);
370  lower_left_y = std::min(std::max(cell_oy, 0), size_y);
371  upper_right_x = std::min(std::max(cell_ox + size_x, 0), size_x);
372  upper_right_y = std::min(std::max(cell_oy + size_y, 0), size_y);
373 
374  unsigned int cell_size_x = upper_right_x - lower_left_x;
375  unsigned int cell_size_y = upper_right_y - lower_left_y;
376 
377  // we need a map to store the obstacles in the window temporarily
378  unsigned char * local_map = new unsigned char[cell_size_x * cell_size_y];
379 
380  // copy the local window in the costmap to the local map
382  costmap_, lower_left_x, lower_left_y, size_x_, local_map, 0, 0, cell_size_x,
383  cell_size_x,
384  cell_size_y);
385 
386  // now we'll set the costmap to be completely unknown if we track unknown space
387  resetMaps();
388 
389  // update the origin with the appropriate world coordinates
390  origin_x_ = new_grid_ox;
391  origin_y_ = new_grid_oy;
392 
393  // compute the starting cell location for copying data back in
394  int start_x = lower_left_x - cell_ox;
395  int start_y = lower_left_y - cell_oy;
396 
397  // now we want to copy the overlapping information back into the map, but in its new location
399  local_map, 0, 0, cell_size_x, costmap_, start_x, start_y, size_x_, cell_size_x,
400  cell_size_y);
401 
402  // make sure to clean up
403  delete[] local_map;
404 }
405 
407  const std::vector<geometry_msgs::msg::Point> & polygon,
408  unsigned char cost_value)
409 {
410  std::vector<MapLocation> polygon_map_region;
411  polygon_map_region.reserve(100);
412  if (!getMapRegionOccupiedByPolygon(polygon, polygon_map_region)) {
413  return false;
414  }
415 
416  // set the cost of those cells
417  setMapRegionOccupiedByPolygon(polygon_map_region, cost_value);
418  return true;
419 }
420 
422  const std::vector<MapLocation> & polygon_map_region,
423  unsigned char new_cost_value)
424 {
425  for (const auto & cell : polygon_map_region) {
426  setCost(cell.x, cell.y, new_cost_value);
427  }
428 }
429 
431  const std::vector<MapLocation> & polygon_map_region)
432 {
433  for (const auto & cell : polygon_map_region) {
434  setCost(cell.x, cell.y, cell.cost);
435  }
436 }
437 
439  const std::vector<geometry_msgs::msg::Point> & polygon,
440  std::vector<MapLocation> & polygon_map_region)
441 {
442  // we assume the polygon is given in the global_frame...
443  // we need to transform it to map coordinates
444  std::vector<MapLocation> map_polygon;
445  for (const auto & cell : polygon) {
446  MapLocation loc;
447  if (!worldToMap(cell.x, cell.y, loc.x, loc.y)) {
448  // ("Polygon lies outside map bounds, so we can't fill it");
449  return false;
450  }
451  map_polygon.push_back(loc);
452  }
453 
454  // get the cells that fill the polygon
455  convexFillCells(map_polygon, polygon_map_region);
456 
457  return true;
458 }
459 
461  const std::vector<MapLocation> & polygon,
462  std::vector<MapLocation> & polygon_cells)
463 {
464  PolygonOutlineCells cell_gatherer(*this, costmap_, polygon_cells);
465  for (unsigned int i = 0; i < polygon.size() - 1; ++i) {
466  nav2_util::raytraceLine(
467  cell_gatherer, polygon[i].x, polygon[i].y, polygon[i + 1].x, polygon[i + 1].y, size_x_);
468  }
469  if (!polygon.empty()) {
470  unsigned int last_index = polygon.size() - 1;
471  // we also need to close the polygon by going from the last point to the first
472  nav2_util::raytraceLine(
473  cell_gatherer, polygon[last_index].x, polygon[last_index].y, polygon[0].x,
474  polygon[0].y, size_x_);
475  }
476 }
477 
479  const std::vector<MapLocation> & polygon,
480  std::vector<MapLocation> & polygon_cells)
481 {
482  // we need a minimum polygon of a triangle
483  if (polygon.size() < 3) {
484  return;
485  }
486 
487  // first get the cells that make up the outline of the polygon
488  polygonOutlineCells(polygon, polygon_cells);
489 
490  // quick bubble sort to sort points by x
491  MapLocation swap;
492  unsigned int i = 0;
493  while (i < polygon_cells.size() - 1) {
494  if (polygon_cells[i].x > polygon_cells[i + 1].x) {
495  swap = polygon_cells[i];
496  polygon_cells[i] = polygon_cells[i + 1];
497  polygon_cells[i + 1] = swap;
498 
499  if (i > 0) {
500  --i;
501  }
502  } else {
503  ++i;
504  }
505  }
506 
507  i = 0;
508  MapLocation min_pt;
509  MapLocation max_pt;
510  unsigned int min_x = polygon_cells[0].x;
511  unsigned int max_x = polygon_cells[polygon_cells.size() - 1].x;
512 
513  // walk through each column and mark cells inside the polygon
514  for (unsigned int x = min_x; x <= max_x; ++x) {
515  if (i >= polygon_cells.size() - 1) {
516  break;
517  }
518 
519  if (polygon_cells[i].y < polygon_cells[i + 1].y) {
520  min_pt = polygon_cells[i];
521  max_pt = polygon_cells[i + 1];
522  } else {
523  min_pt = polygon_cells[i + 1];
524  max_pt = polygon_cells[i];
525  }
526 
527  i += 2;
528  while (i < polygon_cells.size() && polygon_cells[i].x == x) {
529  if (polygon_cells[i].y < min_pt.y) {
530  min_pt = polygon_cells[i];
531  } else if (polygon_cells[i].y > max_pt.y) {
532  max_pt = polygon_cells[i];
533  }
534  ++i;
535  }
536 
537  MapLocation pt;
538  // loop though cells in the column
539  for (unsigned int y = min_pt.y; y <= max_pt.y; ++y) {
540  pt.x = x;
541  pt.y = y;
542  pt.cost = getCost(x, y);
543  polygon_cells.push_back(pt);
544  }
545  }
546 }
547 
548 unsigned int Costmap2D::getSizeInCellsX() const
549 {
550  return size_x_;
551 }
552 
553 unsigned int Costmap2D::getSizeInCellsY() const
554 {
555  return size_y_;
556 }
557 
559 {
560  return (size_x_ - 1 + 0.5) * resolution_;
561 }
562 
564 {
565  return (size_y_ - 1 + 0.5) * resolution_;
566 }
567 
568 double Costmap2D::getOriginX() const
569 {
570  return origin_x_;
571 }
572 
573 double Costmap2D::getOriginY() const
574 {
575  return origin_y_;
576 }
577 
579 {
580  return resolution_;
581 }
582 
583 bool Costmap2D::saveMap(std::string file_name)
584 {
585  FILE * fp = fopen(file_name.c_str(), "w");
586 
587  if (!fp) {
588  return false;
589  }
590 
591  fprintf(fp, "P2\n%u\n%u\n%u\n", size_x_, size_y_, 0xff);
592  for (unsigned int iy = 0; iy < size_y_; iy++) {
593  for (unsigned int ix = 0; ix < size_x_; ix++) {
594  unsigned char cost = getCost(ix, iy);
595  fprintf(fp, "%d ", cost);
596  }
597  fprintf(fp, "\n");
598  }
599  fclose(fp);
600  return true;
601 }
602 
603 } // namespace nav2_costmap_2d
A 2D costmap provides a mapping between points in the world and their associated "costs".
Definition: costmap_2d.hpp:69
void mapToWorld(unsigned int mx, unsigned int my, double &wx, double &wy) const
Convert from map coordinates to world coordinates.
Definition: costmap_2d.cpp:280
void resetMap(unsigned int x0, unsigned int y0, unsigned int xn, unsigned int yn)
Reset the costmap in bounds.
Definition: costmap_2d.cpp:131
unsigned int getIndex(unsigned int mx, unsigned int my) const
Given two map coordinates... compute the associated index.
Definition: costmap_2d.hpp:231
void resetMapToValue(unsigned int x0, unsigned int y0, unsigned int xn, unsigned int yn, unsigned char value)
Reset the costmap in bounds to a value.
Definition: costmap_2d.cpp:136
void resizeMap(unsigned int size_x, unsigned int size_y, double resolution, double origin_x, double origin_y)
Resize the costmap.
Definition: costmap_2d.cpp:111
unsigned char getCost(unsigned int mx, unsigned int my) const
Get the cost of a cell in the costmap.
Definition: costmap_2d.cpp:265
virtual ~Costmap2D()
Destructor.
Definition: costmap_2d.cpp:248
void polygonOutlineCells(const std::vector< MapLocation > &polygon, std::vector< MapLocation > &polygon_cells)
Get the map cells that make up the outline of a polygon.
Definition: costmap_2d.cpp:460
void mapToWorldNoBounds(int mx, int my, double &wx, double &wy) const
Convert from map coordinates to world coordinates with no bounds checking.
Definition: costmap_2d.cpp:286
virtual void deleteMaps()
Deletes the costmap, static_map, and markers data structures.
Definition: costmap_2d.cpp:94
bool saveMap(std::string file_name)
Save the costmap out to a pgm file.
Definition: costmap_2d.cpp:583
bool copyWindow(const Costmap2D &source, unsigned int sx0, unsigned int sy0, unsigned int sxn, unsigned int syn, unsigned int dx0, unsigned int dy0)
Copies the (x0,y0)..(xn,yn) window from source costmap into a current costmap.
Definition: costmap_2d.cpp:185
void worldToMapEnforceBounds(double wx, double wy, int &mx, int &my) const
Convert from world coordinates to map coordinates, constraining results to legal bounds.
Definition: costmap_2d.cpp:328
unsigned char * getCharMap() const
Will return a pointer to the underlying unsigned char array used as the costmap.
Definition: costmap_2d.cpp:260
bool worldToMap(double wx, double wy, unsigned int &mx, unsigned int &my) const
Convert from world coordinates to map coordinates.
Definition: costmap_2d.cpp:292
void copyMapRegion(data_type *source_map, unsigned int sm_lower_left_x, unsigned int sm_lower_left_y, unsigned int sm_size_x, data_type *dest_map, unsigned int dm_lower_left_x, unsigned int dm_lower_left_y, unsigned int dm_size_x, unsigned int region_size_x, unsigned int region_size_y)
Copy a region of a source map into a destination map.
Definition: costmap_2d.hpp:428
void convexFillCells(const std::vector< MapLocation > &polygon, std::vector< MapLocation > &polygon_cells)
Get the map cells that fill a convex polygon.
Definition: costmap_2d.cpp:478
double getResolution() const
Accessor for the resolution of the costmap.
Definition: costmap_2d.cpp:578
virtual void updateOrigin(double new_origin_x, double new_origin_y)
Move the origin of the costmap to a new location.... keeping data when it can.
Definition: costmap_2d.cpp:350
Costmap2D()
Default constructor.
Definition: costmap_2d.cpp:242
bool setConvexPolygonCost(const std::vector< geometry_msgs::msg::Point > &polygon, unsigned char cost_value)
Sets the cost of a convex polygon to a desired value.
Definition: costmap_2d.cpp:406
double getSizeInMetersY() const
Accessor for the y size of the costmap in meters.
Definition: costmap_2d.cpp:563
double getSizeInMetersX() const
Accessor for the x size of the costmap in meters.
Definition: costmap_2d.cpp:558
void setMapRegionOccupiedByPolygon(const std::vector< MapLocation > &polygon_map_region, unsigned char new_cost_value)
Sets the given map region to desired value.
Definition: costmap_2d.cpp:421
void restoreMapRegionOccupiedByPolygon(const std::vector< MapLocation > &polygon_map_region)
Restores the corresponding map region using given map region.
Definition: costmap_2d.cpp:430
void worldToMapNoBounds(double wx, double wy, int &mx, int &my) const
Convert from world coordinates to map coordinates without checking for legal bounds.
Definition: costmap_2d.cpp:322
bool worldToMapContinuous(double wx, double wy, float &mx, float &my) const
Convert from world coordinates to map coordinates.
Definition: costmap_2d.cpp:307
virtual void initMaps(unsigned int size_x, unsigned int size_y)
Initializes the costmap, static_map, and markers data structures.
Definition: costmap_2d.cpp:102
bool getMapRegionOccupiedByPolygon(const std::vector< geometry_msgs::msg::Point > &polygon, std::vector< MapLocation > &polygon_map_region)
Gets the map region occupied by polygon.
Definition: costmap_2d.cpp:438
bool copyCostmapWindow(const Costmap2D &map, double win_origin_x, double win_origin_y, double win_size_x, double win_size_y)
Turn this costmap into a copy of a window of a costmap passed in.
Definition: costmap_2d.cpp:146
unsigned int getSizeInCellsX() const
Accessor for the x size of the costmap in cells.
Definition: costmap_2d.cpp:548
virtual void resetMaps()
Resets the costmap and static_map to be unknown space.
Definition: costmap_2d.cpp:125
double getOriginY() const
Accessor for the y origin of the costmap.
Definition: costmap_2d.cpp:573
unsigned int getSizeInCellsY() const
Accessor for the y size of the costmap in cells.
Definition: costmap_2d.cpp:553
double getOriginX() const
Accessor for the x origin of the costmap.
Definition: costmap_2d.cpp:568
void setCost(unsigned int mx, unsigned int my, unsigned char cost)
Set the cost of a cell in the costmap.
Definition: costmap_2d.cpp:275
unsigned int cellDistance(double world_dist)
Given distance in the world... convert it to cells.
Definition: costmap_2d.cpp:254
Costmap2D & operator=(const Costmap2D &map)
Overloaded assignment operator.
Definition: costmap_2d.cpp:208