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 
47 namespace nav2_costmap_2d
48 {
50  unsigned int cells_size_x, unsigned int cells_size_y, double resolution,
51  double origin_x, double origin_y, unsigned char default_value)
52 : resolution_(resolution), origin_x_(origin_x),
53  origin_y_(origin_y), costmap_(NULL), default_value_(default_value)
54 {
55  access_ = new mutex_t();
56 
57  // create the costmap
58  initMaps(cells_size_x, cells_size_y);
59  resetMaps();
60 }
61 
62 Costmap2D::Costmap2D(const nav_msgs::msg::OccupancyGrid & map)
63 : default_value_(FREE_SPACE)
64 {
65  access_ = new mutex_t();
66 
67  // fill local variables
68  size_x_ = map.info.width;
69  size_y_ = map.info.height;
70  resolution_ = map.info.resolution;
71  origin_x_ = map.info.origin.position.x;
72  origin_y_ = map.info.origin.position.y;
73 
74  // create the costmap
75  costmap_ = new unsigned char[size_x_ * size_y_];
76 
77  // fill the costmap with a data
78  int8_t data;
79  for (unsigned int it = 0; it < size_x_ * size_y_; it++) {
80  data = map.data[it];
81  if (data == nav2_util::OCC_GRID_UNKNOWN) {
82  costmap_[it] = NO_INFORMATION;
83  } else {
84  // Linear conversion from OccupancyGrid data range [OCC_GRID_FREE..OCC_GRID_OCCUPIED]
85  // to costmap data range [FREE_SPACE..LETHAL_OBSTACLE]
86  costmap_[it] = std::round(
87  static_cast<double>(data) * (LETHAL_OBSTACLE - FREE_SPACE) /
88  (nav2_util::OCC_GRID_OCCUPIED - nav2_util::OCC_GRID_FREE));
89  }
90  }
91 }
92 
94 {
95  // clean up data
96  std::unique_lock<mutex_t> lock(*access_);
97  delete[] costmap_;
98  costmap_ = NULL;
99 }
100 
101 void Costmap2D::initMaps(unsigned int size_x, unsigned int size_y)
102 {
103  std::unique_lock<mutex_t> lock(*access_);
104  delete[] costmap_;
105  size_x_ = size_x;
106  size_y_ = size_y;
107  costmap_ = new unsigned char[size_x * size_y];
108 }
109 
111  unsigned int size_x, unsigned int size_y, double resolution,
112  double origin_x, double origin_y)
113 {
114  resolution_ = resolution;
115  origin_x_ = origin_x;
116  origin_y_ = origin_y;
117 
118  initMaps(size_x, size_y);
119 
120  // reset our maps to have no information
121  resetMaps();
122 }
123 
125 {
126  std::unique_lock<mutex_t> lock(*access_);
127  memset(costmap_, default_value_, size_x_ * size_y_ * sizeof(unsigned char));
128 }
129 
130 void Costmap2D::resetMap(unsigned int x0, unsigned int y0, unsigned int xn, unsigned int yn)
131 {
132  resetMapToValue(x0, y0, xn, yn, default_value_);
133 }
134 
136  unsigned int x0, unsigned int y0, unsigned int xn, unsigned int yn, unsigned char value)
137 {
138  std::unique_lock<mutex_t> lock(*(access_));
139  unsigned int len = xn - x0;
140  for (unsigned int y = y0 * size_x_ + x0; y < yn * size_x_ + x0; y += size_x_) {
141  memset(costmap_ + y, value, len * sizeof(unsigned char));
142  }
143 }
144 
146  const Costmap2D & map, double win_origin_x, double win_origin_y,
147  double win_size_x,
148  double win_size_y)
149 {
150  // check for self windowing
151  if (this == &map) {
152  // ROS_ERROR("Cannot convert this costmap into a window of itself");
153  return false;
154  }
155 
156  // clean up old data
157  deleteMaps();
158 
159  // compute the bounds of our new map
160  unsigned int lower_left_x, lower_left_y, upper_right_x, upper_right_y;
161  if (!map.worldToMap(win_origin_x, win_origin_y, lower_left_x, lower_left_y) ||
162  !map.worldToMap(
163  win_origin_x + win_size_x, win_origin_y + win_size_y, upper_right_x,
164  upper_right_y))
165  {
166  // ROS_ERROR("Cannot window a map that the window bounds don't fit inside of");
167  return false;
168  }
169  resolution_ = map.resolution_;
170  origin_x_ = win_origin_x;
171  origin_y_ = win_origin_y;
172 
173  // initialize our various maps and reset markers for inflation
174  initMaps(upper_right_x - lower_left_x, upper_right_y - lower_left_y);
175 
176  // copy the window of the static map and the costmap that we're taking
178  map.costmap_, lower_left_x, lower_left_y, map.size_x_, costmap_, 0, 0, size_x_,
179  size_x_,
180  size_y_);
181  return true;
182 }
183 
185  const Costmap2D & source,
186  unsigned int sx0, unsigned int sy0, unsigned int sxn, unsigned int syn,
187  unsigned int dx0, unsigned int dy0)
188 {
189  const unsigned int sz_x = sxn - sx0;
190  const unsigned int sz_y = syn - sy0;
191 
192  if (sxn > source.getSizeInCellsX() || syn > source.getSizeInCellsY()) {
193  return false;
194  }
195 
196  if (dx0 + sz_x > size_x_ || dy0 + sz_y > size_y_) {
197  return false;
198  }
199 
201  source.costmap_, sx0, sy0, source.size_x_,
202  costmap_, dx0, dy0, size_x_,
203  sz_x, sz_y);
204  return true;
205 }
206 
208 {
209  // check for self assignment
210  if (this == &map) {
211  return *this;
212  }
213 
214  // clean up old data
215  deleteMaps();
216 
217  size_x_ = map.size_x_;
218  size_y_ = map.size_y_;
219  resolution_ = map.resolution_;
220  origin_x_ = map.origin_x_;
221  origin_y_ = map.origin_y_;
222  default_value_ = map.default_value_;
223 
224  // initialize our various maps
225  initMaps(size_x_, size_y_);
226 
227  // copy the cost map
228  memcpy(costmap_, map.costmap_, size_x_ * size_y_ * sizeof(unsigned char));
229 
230  return *this;
231 }
232 
234 : costmap_(NULL)
235 {
236  access_ = new mutex_t();
237  *this = map;
238 }
239 
240 // just initialize everything to NULL by default
242 : size_x_(0), size_y_(0), resolution_(0.0), origin_x_(0.0), origin_y_(0.0), costmap_(NULL)
243 {
244  access_ = new mutex_t();
245 }
246 
248 {
249  deleteMaps();
250  delete access_;
251 }
252 
253 unsigned int Costmap2D::cellDistance(double world_dist)
254 {
255  double cells_dist = std::max(0.0, ceil(world_dist / resolution_));
256  return (unsigned int)cells_dist;
257 }
258 
259 unsigned char * Costmap2D::getCharMap() const
260 {
261  return costmap_;
262 }
263 
264 unsigned char Costmap2D::getCost(unsigned int mx, unsigned int my) const
265 {
266  return costmap_[getIndex(mx, my)];
267 }
268 
269 unsigned char Costmap2D::getCost(unsigned int undex) const
270 {
271  return costmap_[undex];
272 }
273 
274 void Costmap2D::setCost(unsigned int mx, unsigned int my, unsigned char cost)
275 {
276  costmap_[getIndex(mx, my)] = cost;
277 }
278 
279 void Costmap2D::mapToWorld(unsigned int mx, unsigned int my, double & wx, double & wy) const
280 {
281  wx = origin_x_ + (mx + 0.5) * resolution_;
282  wy = origin_y_ + (my + 0.5) * resolution_;
283 }
284 
285 void Costmap2D::mapToWorldNoBounds(int mx, int my, double & wx, double & wy) const
286 {
287  wx = origin_x_ + (mx + 0.5) * resolution_;
288  wy = origin_y_ + (my + 0.5) * resolution_;
289 }
290 
291 bool Costmap2D::worldToMap(double wx, double wy, unsigned int & mx, unsigned int & my) const
292 {
293  if (wx < origin_x_ || wy < origin_y_) {
294  return false;
295  }
296 
297  mx = static_cast<unsigned int>((wx - origin_x_) / resolution_);
298  my = static_cast<unsigned int>((wy - origin_y_) / resolution_);
299 
300  if (mx < size_x_ && my < size_y_) {
301  return true;
302  }
303  return false;
304 }
305 
306 bool Costmap2D::worldToMapContinuous(double wx, double wy, float & mx, float & my) const
307 {
308  if (wx < origin_x_ || wy < origin_y_) {
309  return false;
310  }
311 
312  mx = static_cast<float>((wx - origin_x_) / resolution_);
313  my = static_cast<float>((wy - origin_y_) / resolution_);
314 
315  if (mx < size_x_ && my < size_y_) {
316  return true;
317  }
318  return false;
319 }
320 
321 void Costmap2D::worldToMapNoBounds(double wx, double wy, int & mx, int & my) const
322 {
323  mx = static_cast<int>((wx - origin_x_) / resolution_);
324  my = static_cast<int>((wy - origin_y_) / resolution_);
325 }
326 
327 void Costmap2D::worldToMapEnforceBounds(double wx, double wy, int & mx, int & my) const
328 {
329  // Here we avoid doing any math to wx,wy before comparing them to
330  // the bounds, so their values can go out to the max and min values
331  // of double floating point.
332  if (wx < origin_x_) {
333  mx = 0;
334  } else if (wx > resolution_ * size_x_ + origin_x_) {
335  mx = size_x_ - 1;
336  } else {
337  mx = static_cast<int>((wx - origin_x_) / resolution_);
338  }
339 
340  if (wy < origin_y_) {
341  my = 0;
342  } else if (wy > resolution_ * size_y_ + origin_y_) {
343  my = size_y_ - 1;
344  } else {
345  my = static_cast<int>((wy - origin_y_) / resolution_);
346  }
347 }
348 
349 void Costmap2D::updateOrigin(double new_origin_x, double new_origin_y)
350 {
351  // project the new origin into the grid
352  int cell_ox, cell_oy;
353  cell_ox = static_cast<int>((new_origin_x - origin_x_) / resolution_);
354  cell_oy = static_cast<int>((new_origin_y - origin_y_) / resolution_);
355 
356  // compute the associated world coordinates for the origin cell
357  // because we want to keep things grid-aligned
358  double new_grid_ox, new_grid_oy;
359  new_grid_ox = origin_x_ + cell_ox * resolution_;
360  new_grid_oy = origin_y_ + cell_oy * resolution_;
361 
362  // To save casting from unsigned int to int a bunch of times
363  int size_x = size_x_;
364  int size_y = size_y_;
365 
366  // we need to compute the overlap of the new and existing windows
367  int lower_left_x, lower_left_y, upper_right_x, upper_right_y;
368  lower_left_x = std::min(std::max(cell_ox, 0), size_x);
369  lower_left_y = std::min(std::max(cell_oy, 0), size_y);
370  upper_right_x = std::min(std::max(cell_ox + size_x, 0), size_x);
371  upper_right_y = std::min(std::max(cell_oy + size_y, 0), size_y);
372 
373  unsigned int cell_size_x = upper_right_x - lower_left_x;
374  unsigned int cell_size_y = upper_right_y - lower_left_y;
375 
376  // we need a map to store the obstacles in the window temporarily
377  unsigned char * local_map = new unsigned char[cell_size_x * cell_size_y];
378 
379  // copy the local window in the costmap to the local map
381  costmap_, lower_left_x, lower_left_y, size_x_, local_map, 0, 0, cell_size_x,
382  cell_size_x,
383  cell_size_y);
384 
385  // now we'll set the costmap to be completely unknown if we track unknown space
386  resetMaps();
387 
388  // update the origin with the appropriate world coordinates
389  origin_x_ = new_grid_ox;
390  origin_y_ = new_grid_oy;
391 
392  // compute the starting cell location for copying data back in
393  int start_x = lower_left_x - cell_ox;
394  int start_y = lower_left_y - cell_oy;
395 
396  // now we want to copy the overlapping information back into the map, but in its new location
398  local_map, 0, 0, cell_size_x, costmap_, start_x, start_y, size_x_, cell_size_x,
399  cell_size_y);
400 
401  // make sure to clean up
402  delete[] local_map;
403 }
404 
406  const std::vector<geometry_msgs::msg::Point> & polygon,
407  unsigned char cost_value)
408 {
409  std::vector<MapLocation> polygon_map_region;
410  polygon_map_region.reserve(100);
411  if (!getMapRegionOccupiedByPolygon(polygon, polygon_map_region)) {
412  return false;
413  }
414 
415  // set the cost of those cells
416  setMapRegionOccupiedByPolygon(polygon_map_region, cost_value);
417  return true;
418 }
419 
421  const std::vector<MapLocation> & polygon_map_region,
422  unsigned char new_cost_value)
423 {
424  for (const auto & cell : polygon_map_region) {
425  setCost(cell.x, cell.y, new_cost_value);
426  }
427 }
428 
430  const std::vector<MapLocation> & polygon_map_region)
431 {
432  for (const auto & cell : polygon_map_region) {
433  setCost(cell.x, cell.y, cell.cost);
434  }
435 }
436 
438  const std::vector<geometry_msgs::msg::Point> & polygon,
439  std::vector<MapLocation> & polygon_map_region)
440 {
441  // we assume the polygon is given in the global_frame...
442  // we need to transform it to map coordinates
443  std::vector<MapLocation> map_polygon;
444  for (const auto & cell : polygon) {
445  MapLocation loc;
446  if (!worldToMap(cell.x, cell.y, loc.x, loc.y)) {
447  // ("Polygon lies outside map bounds, so we can't fill it");
448  return false;
449  }
450  map_polygon.push_back(loc);
451  }
452 
453  // get the cells that fill the polygon
454  convexFillCells(map_polygon, polygon_map_region);
455 
456  return true;
457 }
458 
460  const std::vector<MapLocation> & polygon,
461  std::vector<MapLocation> & polygon_cells)
462 {
463  PolygonOutlineCells cell_gatherer(*this, costmap_, polygon_cells);
464  for (unsigned int i = 0; i < polygon.size() - 1; ++i) {
465  raytraceLine(cell_gatherer, polygon[i].x, polygon[i].y, polygon[i + 1].x, polygon[i + 1].y);
466  }
467  if (!polygon.empty()) {
468  unsigned int last_index = polygon.size() - 1;
469  // we also need to close the polygon by going from the last point to the first
470  raytraceLine(
471  cell_gatherer, polygon[last_index].x, polygon[last_index].y, polygon[0].x,
472  polygon[0].y);
473  }
474 }
475 
477  const std::vector<MapLocation> & polygon,
478  std::vector<MapLocation> & polygon_cells)
479 {
480  // we need a minimum polygon of a triangle
481  if (polygon.size() < 3) {
482  return;
483  }
484 
485  // first get the cells that make up the outline of the polygon
486  polygonOutlineCells(polygon, polygon_cells);
487 
488  // quick bubble sort to sort points by x
489  MapLocation swap;
490  unsigned int i = 0;
491  while (i < polygon_cells.size() - 1) {
492  if (polygon_cells[i].x > polygon_cells[i + 1].x) {
493  swap = polygon_cells[i];
494  polygon_cells[i] = polygon_cells[i + 1];
495  polygon_cells[i + 1] = swap;
496 
497  if (i > 0) {
498  --i;
499  }
500  } else {
501  ++i;
502  }
503  }
504 
505  i = 0;
506  MapLocation min_pt;
507  MapLocation max_pt;
508  unsigned int min_x = polygon_cells[0].x;
509  unsigned int max_x = polygon_cells[polygon_cells.size() - 1].x;
510 
511  // walk through each column and mark cells inside the polygon
512  for (unsigned int x = min_x; x <= max_x; ++x) {
513  if (i >= polygon_cells.size() - 1) {
514  break;
515  }
516 
517  if (polygon_cells[i].y < polygon_cells[i + 1].y) {
518  min_pt = polygon_cells[i];
519  max_pt = polygon_cells[i + 1];
520  } else {
521  min_pt = polygon_cells[i + 1];
522  max_pt = polygon_cells[i];
523  }
524 
525  i += 2;
526  while (i < polygon_cells.size() && polygon_cells[i].x == x) {
527  if (polygon_cells[i].y < min_pt.y) {
528  min_pt = polygon_cells[i];
529  } else if (polygon_cells[i].y > max_pt.y) {
530  max_pt = polygon_cells[i];
531  }
532  ++i;
533  }
534 
535  MapLocation pt;
536  // loop though cells in the column
537  for (unsigned int y = min_pt.y; y <= max_pt.y; ++y) {
538  pt.x = x;
539  pt.y = y;
540  pt.cost = getCost(x, y);
541  polygon_cells.push_back(pt);
542  }
543  }
544 }
545 
546 unsigned int Costmap2D::getSizeInCellsX() const
547 {
548  return size_x_;
549 }
550 
551 unsigned int Costmap2D::getSizeInCellsY() const
552 {
553  return size_y_;
554 }
555 
557 {
558  return (size_x_ - 1 + 0.5) * resolution_;
559 }
560 
562 {
563  return (size_y_ - 1 + 0.5) * resolution_;
564 }
565 
566 double Costmap2D::getOriginX() const
567 {
568  return origin_x_;
569 }
570 
571 double Costmap2D::getOriginY() const
572 {
573  return origin_y_;
574 }
575 
577 {
578  return resolution_;
579 }
580 
581 bool Costmap2D::saveMap(std::string file_name)
582 {
583  FILE * fp = fopen(file_name.c_str(), "w");
584 
585  if (!fp) {
586  return false;
587  }
588 
589  fprintf(fp, "P2\n%u\n%u\n%u\n", size_x_, size_y_, 0xff);
590  for (unsigned int iy = 0; iy < size_y_; iy++) {
591  for (unsigned int ix = 0; ix < size_x_; ix++) {
592  unsigned char cost = getCost(ix, iy);
593  fprintf(fp, "%d ", cost);
594  }
595  fprintf(fp, "\n");
596  }
597  fclose(fp);
598  return true;
599 }
600 
601 } // 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:279
void resetMap(unsigned int x0, unsigned int y0, unsigned int xn, unsigned int yn)
Reset the costmap in bounds.
Definition: costmap_2d.cpp:130
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:135
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:110
unsigned char getCost(unsigned int mx, unsigned int my) const
Get the cost of a cell in the costmap.
Definition: costmap_2d.cpp:264
virtual ~Costmap2D()
Destructor.
Definition: costmap_2d.cpp:247
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:459
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:285
virtual void deleteMaps()
Deletes the costmap, static_map, and markers data structures.
Definition: costmap_2d.cpp:93
bool saveMap(std::string file_name)
Save the costmap out to a pgm file.
Definition: costmap_2d.cpp:581
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:184
void raytraceLine(ActionType at, unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, unsigned int max_length=UINT_MAX, unsigned int min_length=0)
Raytrace a line and apply some action at each step.
Definition: costmap_2d.hpp:476
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:327
unsigned char * getCharMap() const
Will return a pointer to the underlying unsigned char array used as the costmap.
Definition: costmap_2d.cpp:259
bool worldToMap(double wx, double wy, unsigned int &mx, unsigned int &my) const
Convert from world coordinates to map coordinates.
Definition: costmap_2d.cpp:291
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:476
double getResolution() const
Accessor for the resolution of the costmap.
Definition: costmap_2d.cpp:576
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:349
Costmap2D()
Default constructor.
Definition: costmap_2d.cpp:241
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:405
double getSizeInMetersY() const
Accessor for the y size of the costmap in meters.
Definition: costmap_2d.cpp:561
double getSizeInMetersX() const
Accessor for the x size of the costmap in meters.
Definition: costmap_2d.cpp:556
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:420
void restoreMapRegionOccupiedByPolygon(const std::vector< MapLocation > &polygon_map_region)
Restores the corresponding map region using given map region.
Definition: costmap_2d.cpp:429
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:321
bool worldToMapContinuous(double wx, double wy, float &mx, float &my) const
Convert from world coordinates to map coordinates.
Definition: costmap_2d.cpp:306
virtual void initMaps(unsigned int size_x, unsigned int size_y)
Initializes the costmap, static_map, and markers data structures.
Definition: costmap_2d.cpp:101
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:437
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:145
unsigned int getSizeInCellsX() const
Accessor for the x size of the costmap in cells.
Definition: costmap_2d.cpp:546
virtual void resetMaps()
Resets the costmap and static_map to be unknown space.
Definition: costmap_2d.cpp:124
double getOriginY() const
Accessor for the y origin of the costmap.
Definition: costmap_2d.cpp:571
unsigned int getSizeInCellsY() const
Accessor for the y size of the costmap in cells.
Definition: costmap_2d.cpp:551
double getOriginX() const
Accessor for the x origin of the costmap.
Definition: costmap_2d.cpp:566
void setCost(unsigned int mx, unsigned int my, unsigned char cost)
Set the cost of a cell in the costmap.
Definition: costmap_2d.cpp:274
unsigned int cellDistance(double world_dist)
Given distance in the world... convert it to cells.
Definition: costmap_2d.cpp:253
Costmap2D & operator=(const Costmap2D &map)
Overloaded assignment operator.
Definition: costmap_2d.cpp:207