Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
layered_costmap.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__LAYERED_COSTMAP_HPP_
39 #define NAV2_COSTMAP_2D__LAYERED_COSTMAP_HPP_
40 
41 #include <memory>
42 #include <string>
43 #include <vector>
44 
45 #include "nav2_costmap_2d/cost_values.hpp"
46 #include "nav2_costmap_2d/layer.hpp"
47 #include "nav2_costmap_2d/costmap_2d.hpp"
48 
49 namespace nav2_costmap_2d
50 {
51 class Layer;
52 
58 {
59 public:
63  LayeredCostmap(std::string global_frame, bool rolling_window, bool track_unknown);
64 
69 
74  void updateMap(double robot_x, double robot_y, double robot_yaw);
75 
76  std::string getGlobalFrameID() const
77  {
78  return global_frame_;
79  }
80 
84  void resizeMap(
85  unsigned int size_x, unsigned int size_y, double resolution, double origin_x,
86  double origin_y,
87  bool size_locked = false);
88 
92  void getUpdatedBounds(double & minx, double & miny, double & maxx, double & maxy)
93  {
94  minx = minx_;
95  miny = miny_;
96  maxx = maxx_;
97  maxy = maxy_;
98  }
99 
104  bool isCurrent();
105 
110  {
111  return &combined_costmap_;
112  }
113 
117  bool isRolling()
118  {
119  return rolling_window_;
120  }
121 
126  {
127  return combined_costmap_.getDefaultValue() == nav2_costmap_2d::NO_INFORMATION;
128  }
129 
133  std::vector<std::shared_ptr<Layer>> * getPlugins()
134  {
135  return &plugins_;
136  }
137 
141  std::vector<std::shared_ptr<Layer>> * getFilters()
142  {
143  return &filters_;
144  }
145 
149  void addPlugin(std::shared_ptr<Layer> plugin);
150 
151 
155  void addFilter(std::shared_ptr<Layer> filter);
156 
157 
162  {
163  return size_locked_;
164  }
165 
169  void getBounds(unsigned int * x0, unsigned int * xn, unsigned int * y0, unsigned int * yn)
170  {
171  *x0 = bx0_;
172  *xn = bxn_;
173  *y0 = by0_;
174  *yn = byn_;
175  }
176 
181  {
182  return initialized_;
183  }
184 
188  void setFootprint(const std::vector<geometry_msgs::msg::Point> & footprint_spec);
189 
191  const std::vector<geometry_msgs::msg::Point> & getFootprint()
192  {
193  return *std::atomic_load(&footprint_);
194  }
195 
201  double getCircumscribedRadius() {return circumscribed_radius_.load();}
202 
208  double getInscribedRadius() {return inscribed_radius_.load();}
209 
212  bool isOutofBounds(double robot_x, double robot_y);
213 
214 private:
215  // primary_costmap_ is a bottom costmap used by plugins when costmap filters were enabled.
216  // combined_costmap_ is a final costmap where all results produced by plugins and filters (if any)
217  // to be merged.
218  // The separation is aimed to avoid interferences of work between plugins and filters.
219  // primary_costmap_ and combined_costmap_ have the same sizes, origins and default values.
220  Costmap2D primary_costmap_, combined_costmap_;
221  std::string global_frame_;
222 
223  bool rolling_window_;
224 
225  bool current_;
226  double minx_, miny_, maxx_, maxy_;
227  unsigned int bx0_, bxn_, by0_, byn_;
228 
229  std::vector<std::shared_ptr<Layer>> plugins_;
230  std::vector<std::shared_ptr<Layer>> filters_;
231 
232  bool initialized_;
233  bool size_locked_;
234  std::atomic<double> circumscribed_radius_, inscribed_radius_;
235  std::shared_ptr<std::vector<geometry_msgs::msg::Point>> footprint_;
236 };
237 
238 } // namespace nav2_costmap_2d
239 
240 #endif // NAV2_COSTMAP_2D__LAYERED_COSTMAP_HPP_
A 2D costmap provides a mapping between points in the world and their associated "costs".
Definition: costmap_2d.hpp:69
unsigned char getDefaultValue()
Get the default background value of the costmap.
Definition: costmap_2d.hpp:309
Instantiates different layer plugins and aggregates them into one score.
std::vector< std::shared_ptr< Layer > > * getPlugins()
Get the vector of pointers to the costmap plugins.
std::vector< std::shared_ptr< Layer > > * getFilters()
Get the vector of pointers to the costmap filters.
bool isRolling()
If this costmap is rolling or not.
void addPlugin(std::shared_ptr< Layer > plugin)
Add a new plugin to the plugins vector to process.
Costmap2D * getCostmap()
Get the costmap pointer to the master costmap.
void addFilter(std::shared_ptr< Layer > filter)
Add a new costmap filter plugin to the filters vector to process.
void resizeMap(unsigned int size_x, unsigned int size_y, double resolution, double origin_x, double origin_y, bool size_locked=false)
Resize the map to a new size, resolution, or origin.
void getBounds(unsigned int *x0, unsigned int *xn, unsigned int *y0, unsigned int *yn)
Get the bounds of the costmap.
double getCircumscribedRadius()
The radius of a circle centered at the origin of the robot which just surrounds all points on the rob...
bool isInitialized()
if the costmap is initialized
bool isOutofBounds(double robot_x, double robot_y)
Checks if the robot is outside the bounds of its costmap in the case of poorly configured setups.
void updateMap(double robot_x, double robot_y, double robot_yaw)
Update the underlying costmap with new data. If you want to update the map outside of the update loop...
LayeredCostmap(std::string global_frame, bool rolling_window, bool track_unknown)
Constructor for a costmap.
void getUpdatedBounds(double &minx, double &miny, double &maxx, double &maxy)
Get the size of the bounds for update.
bool isSizeLocked()
Get if the size of the costmap is locked.
bool isTrackingUnknown()
If this costmap is tracking unknown space or not.
void setFootprint(const std::vector< geometry_msgs::msg::Point > &footprint_spec)
Updates the stored footprint, updates the circumscribed and inscribed radii, and calls onFootprintCha...
double getInscribedRadius()
The radius of a circle centered at the origin of the robot which is just within all points and edges ...
bool isCurrent()
If the costmap is current, e.g. are all the layers processing recent data and not stale information f...
const std::vector< geometry_msgs::msg::Point > & getFootprint()
Returns the latest footprint stored with setFootprint().