39 #include <nav2_costmap_2d/costmap_layer.hpp>
47 double x,
double y,
double * min_x,
double * min_y,
double * max_x,
50 *min_x = std::min(x, *min_x);
51 *min_y = std::min(y, *min_y);
52 *max_x = std::max(x, *max_x);
53 *max_y = std::max(y, *max_y);
58 std::lock_guard<Costmap2D::mutex_t> guard(*getMutex());
62 rclcpp::get_logger(
"nav2_costmap_2d"),
63 "Cannot match size for layer, master costmap is not initialized yet.");
76 bool xrange = x > start_x && x < end_x;
79 if ((xrange && y > start_y && y < end_y) == invert) {
83 if (grid[index] != NO_INFORMATION) {
84 grid[index] = NO_INFORMATION;
92 extra_min_x_ = std::min(mx0, extra_min_x_);
93 extra_max_x_ = std::max(mx1, extra_max_x_);
94 extra_min_y_ = std::min(my0, extra_min_y_);
95 extra_max_y_ = std::max(my1, extra_max_y_);
96 has_extra_bounds_ =
true;
99 void CostmapLayer::useExtraBounds(
double * min_x,
double * min_y,
double * max_x,
double * max_y)
101 if (!has_extra_bounds_) {
105 *min_x = std::min(extra_min_x_, *min_x);
106 *min_y = std::min(extra_min_y_, *min_y);
107 *max_x = std::max(extra_max_x_, *max_x);
108 *max_y = std::max(extra_max_y_, *max_y);
113 has_extra_bounds_ =
false;
116 void CostmapLayer::updateWithMax(
125 unsigned char * master_array = master_grid.
getCharMap();
128 for (
int j = min_j; j < max_j; j++) {
129 unsigned int it = j * span + min_i;
130 for (
int i = min_i; i < max_i; i++) {
131 if (costmap_[it] == NO_INFORMATION) {
136 unsigned char old_cost = master_array[it];
137 if (old_cost == NO_INFORMATION || old_cost < costmap_[it]) {
138 master_array[it] = costmap_[it];
145 void CostmapLayer::updateWithMaxWithoutUnknownOverwrite(
154 unsigned char * master_array = master_grid.
getCharMap();
157 for (
int j = min_j; j < max_j; j++) {
158 unsigned int it = j * span + min_i;
159 for (
int i = min_i; i < max_i; i++) {
160 if (costmap_[it] == NO_INFORMATION) {
165 unsigned char old_cost = master_array[it];
166 if (old_cost != NO_INFORMATION && old_cost < costmap_[it]) {
167 master_array[it] = costmap_[it];
174 void CostmapLayer::updateWithTrueOverwrite(
184 if (costmap_ ==
nullptr) {
185 throw std::runtime_error(
"Can't update costmap layer: It has't been initialized yet!");
188 unsigned char * master = master_grid.
getCharMap();
191 for (
int j = min_j; j < max_j; j++) {
192 unsigned int it = span * j + min_i;
193 for (
int i = min_i; i < max_i; i++) {
194 master[it] = costmap_[it];
200 void CostmapLayer::updateWithOverwrite(
202 int min_i,
int min_j,
int max_i,
int max_j)
207 unsigned char * master = master_grid.
getCharMap();
210 for (
int j = min_j; j < max_j; j++) {
211 unsigned int it = span * j + min_i;
212 for (
int i = min_i; i < max_i; i++) {
213 if (costmap_[it] != NO_INFORMATION) {
214 master[it] = costmap_[it];
221 void CostmapLayer::updateWithAddition(
223 int min_i,
int min_j,
int max_i,
int max_j)
228 unsigned char * master_array = master_grid.
getCharMap();
231 for (
int j = min_j; j < max_j; j++) {
232 unsigned int it = j * span + min_i;
233 for (
int i = min_i; i < max_i; i++) {
234 if (costmap_[it] == NO_INFORMATION) {
239 unsigned char old_cost = master_array[it];
240 if (old_cost == NO_INFORMATION) {
241 master_array[it] = costmap_[it];
243 int sum = old_cost + costmap_[it];
244 if (sum >= nav2_costmap_2d::INSCRIBED_INFLATED_OBSTACLE) {
245 master_array[it] = nav2_costmap_2d::INSCRIBED_INFLATED_OBSTACLE - 1;
247 master_array[it] = sum;
267 "Param combination_method: %i. Possible values are 0 (Overwrite) or 1 (Maximum) or "
268 "2 (Maximum without overwriting the master's NO_INFORMATION values)."
269 "The default value 1 will be used", value);
A 2D costmap provides a mapping between points in the world and their associated "costs".
unsigned int getIndex(unsigned int mx, unsigned int my) const
Given two map coordinates... compute the associated index.
void resizeMap(unsigned int size_x, unsigned int size_y, double resolution, double origin_x, double origin_y)
Resize the costmap.
unsigned char * getCharMap() const
Will return a pointer to the underlying unsigned char array used as the costmap.
double getResolution() const
Accessor for the resolution of the costmap.
unsigned int getSizeInCellsX() const
Accessor for the x size of the costmap in cells.
double getOriginY() const
Accessor for the y origin of the costmap.
unsigned int getSizeInCellsY() const
Accessor for the y size of the costmap in cells.
double getOriginX() const
Accessor for the x origin of the costmap.
void addExtraBounds(double mx0, double my0, double mx1, double my1)
void touch(double x, double y, double *min_x, double *min_y, double *max_x, double *max_y)
virtual void clearArea(int start_x, int start_y, int end_x, int end_y, bool invert)
Clear an are in the costmap with the given dimension if invert, then clear everything except these di...
virtual void matchSize()
Match the size of the master costmap.
CombinationMethod combination_method_from_int(const int value)
Converts an integer to a CombinationMethod enum and logs on failure.
Costmap2D * getCostmap()
Get the costmap pointer to the master costmap.
@ MaxWithoutUnknownOverwrite