Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
costmap_layer.hpp
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 #ifndef NAV2_COSTMAP_2D__COSTMAP_LAYER_HPP_
39 #define NAV2_COSTMAP_2D__COSTMAP_LAYER_HPP_
40 
41 #include <string>
42 
43 #include <rclcpp/rclcpp.hpp>
44 #include <nav2_costmap_2d/layer.hpp>
45 #include <nav2_costmap_2d/layered_costmap.hpp>
46 
47 namespace nav2_costmap_2d
48 {
49 
56 class CostmapLayer : public Layer, public Costmap2D
57 {
58 public:
63  : has_extra_bounds_(false),
64  extra_min_x_(1e6), extra_max_x_(-1e6),
65  extra_min_y_(1e6), extra_max_y_(-1e6) {}
66 
71  {
72  return true;
73  }
74 
78  virtual void matchSize();
79 
84  virtual void clearArea(int start_x, int start_y, int end_x, int end_y, bool invert);
85 
95  void addExtraBounds(double mx0, double my0, double mx1, double my1);
96 
97 protected:
98  /*
99  * Updates the master_grid within the specified
100  * bounding box using this layer's values.
101  *
102  * TrueOverwrite means every value from this layer
103  * is written into the master grid.
104  */
105  void updateWithTrueOverwrite(
106  nav2_costmap_2d::Costmap2D & master_grid,
107  int min_i, int min_j, int max_i, int max_j);
108 
109  /*
110  * Updates the master_grid within the specified
111  * bounding box using this layer's values.
112  *
113  * Overwrite means every valid value from this layer
114  * is written into the master grid (does not copy NO_INFORMATION)
115  */
116  void updateWithOverwrite(
117  nav2_costmap_2d::Costmap2D & master_grid,
118  int min_i, int min_j, int max_i, int max_j);
119 
120  /*
121  * Updates the master_grid within the specified
122  * bounding box using this layer's values.
123  *
124  * Sets the new value to the maximum of the master_grid's value
125  * and this layer's value. If the master value is NO_INFORMATION,
126  * it is overwritten. If the layer's value is NO_INFORMATION,
127  * the master value does not change.
128  */
129  void updateWithMax(
130  nav2_costmap_2d::Costmap2D & master_grid, int min_i, int min_j, int max_i,
131  int max_j);
132 
133  /*
134  * Updates the master_grid within the specified
135  * bounding box using this layer's values.
136  *
137  * Sets the new value to the maximum of the master_grid's value
138  * and this layer's value. If the master value is NO_INFORMATION,
139  * it is NOT overwritten. If the layer's value is NO_INFORMATION,
140  * the master value does not change.
141  */
142  void updateWithMaxWithoutUnknownOverwrite(
143  nav2_costmap_2d::Costmap2D & master_grid, int min_i, int min_j, int max_i,
144  int max_j);
145 
146  /*
147  * Updates the master_grid within the specified
148  * bounding box using this layer's values.
149  *
150  * Sets the new value to the sum of the master grid's value
151  * and this layer's value. If the master value is NO_INFORMATION,
152  * it is overwritten with the layer's value. If the layer's value
153  * is NO_INFORMATION, then the master value does not change.
154  *
155  * If the sum value is larger than INSCRIBED_INFLATED_OBSTACLE,
156  * the master value is set to (INSCRIBED_INFLATED_OBSTACLE - 1).
157  */
158  void updateWithAddition(
159  nav2_costmap_2d::Costmap2D & master_grid, int min_i, int min_j, int max_i,
160  int max_j);
161 
173  void touch(double x, double y, double * min_x, double * min_y, double * max_x, double * max_y);
174 
175  /*
176  * Updates the bounding box specified in the parameters
177  * to include the bounding box from the addExtraBounds
178  * call. If addExtraBounds was not called, the method will do nothing.
179  *
180  * Should be called at the beginning of the updateBounds method
181  *
182  * @param min_x bounding box (input and output)
183  * @param min_y bounding box (input and output)
184  * @param max_x bounding box (input and output)
185  * @param max_y bounding box (input and output)
186  */
187  void useExtraBounds(double * min_x, double * min_y, double * max_x, double * max_y);
188  bool has_extra_bounds_;
189 
196 
197 private:
198  double extra_min_x_, extra_max_x_, extra_min_y_, extra_max_y_;
199 };
200 
201 } // namespace nav2_costmap_2d
202 #endif // NAV2_COSTMAP_2D__COSTMAP_LAYER_HPP_
A 2D costmap provides a mapping between points in the world and their associated "costs".
Definition: costmap_2d.hpp:69
A costmap layer base class for costmap plugin layers. Rather than just a layer, this object also cont...
CostmapLayer()
CostmapLayer constructor.
bool isDiscretized()
If layer is discrete.
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.
Abstract class for layered costmap plugin implementations.
Definition: layer.hpp:59