Nav2 Navigation Stack - lyrical  lyrical
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 <nav2_costmap_2d/layer.hpp>
44 #include <nav2_costmap_2d/layered_costmap.hpp>
45 
46 namespace nav2_costmap_2d
47 {
48 
55 class CostmapLayer : public Layer, public Costmap2D
56 {
57 public:
62  : has_extra_bounds_(false),
63  extra_min_x_(1e6), extra_max_x_(-1e6),
64  extra_min_y_(1e6), extra_max_y_(-1e6) {}
65 
70  {
71  return true;
72  }
73 
77  virtual void matchSize();
78 
83  virtual void clearArea(int start_x, int start_y, int end_x, int end_y, bool invert);
84 
94  void addExtraBounds(double mx0, double my0, double mx1, double my1);
95 
96 protected:
97  /*
98  * Updates the master_grid within the specified
99  * bounding box using this layer's values.
100  *
101  * TrueOverwrite means every value from this layer
102  * is written into the master grid.
103  */
104  void updateWithTrueOverwrite(
105  nav2_costmap_2d::Costmap2D & master_grid,
106  int min_i, int min_j, int max_i, int max_j);
107 
108  /*
109  * Updates the master_grid within the specified
110  * bounding box using this layer's values.
111  *
112  * Overwrite means every valid value from this layer
113  * is written into the master grid (does not copy NO_INFORMATION)
114  */
115  void updateWithOverwrite(
116  nav2_costmap_2d::Costmap2D & master_grid,
117  int min_i, int min_j, int max_i, int max_j);
118 
119  /*
120  * Updates the master_grid within the specified
121  * bounding box using this layer's values.
122  *
123  * Sets the new value to the maximum of the master_grid's value
124  * and this layer's value. If the master value is NO_INFORMATION,
125  * it is overwritten. If the layer's value is NO_INFORMATION,
126  * the master value does not change.
127  */
128  void updateWithMax(
129  nav2_costmap_2d::Costmap2D & master_grid, int min_i, int min_j, int max_i,
130  int max_j);
131 
132  /*
133  * Updates the master_grid within the specified
134  * bounding box using this layer's values.
135  *
136  * Sets the new value to the maximum of the master_grid's value
137  * and this layer's value. If the master value is NO_INFORMATION,
138  * it is NOT overwritten. If the layer's value is NO_INFORMATION,
139  * the master value does not change.
140  */
141  void updateWithMaxWithoutUnknownOverwrite(
142  nav2_costmap_2d::Costmap2D & master_grid, int min_i, int min_j, int max_i,
143  int max_j);
144 
145  /*
146  * Updates the master_grid within the specified
147  * bounding box using this layer's values.
148  *
149  * Sets the new value to the sum of the master grid's value
150  * and this layer's value. If the master value is NO_INFORMATION,
151  * it is overwritten with the layer's value. If the layer's value
152  * is NO_INFORMATION, then the master value does not change.
153  *
154  * If the sum value is larger than INSCRIBED_INFLATED_OBSTACLE,
155  * the master value is set to (INSCRIBED_INFLATED_OBSTACLE - 1).
156  */
157  void updateWithAddition(
158  nav2_costmap_2d::Costmap2D & master_grid, int min_i, int min_j, int max_i,
159  int max_j);
160 
172  void touch(double x, double y, double * min_x, double * min_y, double * max_x, double * max_y);
173 
174  /*
175  * Updates the bounding box specified in the parameters
176  * to include the bounding box from the addExtraBounds
177  * call. If addExtraBounds was not called, the method will do nothing.
178  *
179  * Should be called at the beginning of the updateBounds method
180  *
181  * @param min_x bounding box (input and output)
182  * @param min_y bounding box (input and output)
183  * @param max_x bounding box (input and output)
184  * @param max_y bounding box (input and output)
185  */
186  void useExtraBounds(double * min_x, double * min_y, double * max_x, double * max_y);
187  bool has_extra_bounds_;
188 
195 
196 private:
197  double extra_min_x_, extra_max_x_, extra_min_y_, extra_max_y_;
198 };
199 
200 } // namespace nav2_costmap_2d
201 #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:62