Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
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: David V. Lu!!
36  *********************************************************************/
37 #ifndef NAV2_COSTMAP_2D__LAYER_HPP_
38 #define NAV2_COSTMAP_2D__LAYER_HPP_
39 
40 #include <atomic>
41 #include <string>
42 #include <vector>
43 #include <unordered_set>
44 
45 #include "nav2_ros_common/tf2_factories.hpp"
46 #include "rclcpp/rclcpp.hpp"
47 #include "nav2_costmap_2d/costmap_2d.hpp"
48 #include "nav2_costmap_2d/layered_costmap.hpp"
49 #include "nav2_ros_common/lifecycle_node.hpp"
50 
51 namespace nav2_costmap_2d
52 {
53 class LayeredCostmap;
54 
59 class Layer
60 {
61 public:
65  Layer();
69  virtual ~Layer() {}
70 
74  void initialize(
75  LayeredCostmap * parent,
76  std::string name,
77  nav2::TransformBuffer * tf,
78  const nav2::LifecycleNode::WeakPtr & node,
79  rclcpp::CallbackGroup::SharedPtr callback_group);
81  virtual void deactivate() {}
83  virtual void activate() {}
87  virtual void reset() = 0;
91  virtual bool isClearable() = 0;
92 
101  virtual void updateBounds(
102  double robot_x, double robot_y, double robot_yaw, double * min_x,
103  double * min_y,
104  double * max_x,
105  double * max_y) = 0;
106 
111  virtual void updateCosts(
112  Costmap2D & master_grid,
113  int min_i, int min_j, int max_i, int max_j) = 0;
114 
116  virtual void matchSize() {}
117 
121  virtual void onFootprintChanged() {}
123  std::string getName() const
124  {
125  return name_;
126  }
127 
138  bool isCurrent() const
139  {
140  return current_;
141  }
142 
147  void setCurrent(bool current)
148  {
149  current_ = current;
150  }
151 
153  bool isEnabled() const
154  {
155  return enabled_;
156  }
157 
159  const std::vector<geometry_msgs::msg::Point> & getFootprint() const;
161  std::string getFullName(const std::string & param_name);
162 
179  std::string joinWithParentNamespace(const std::string & topic);
180 
181 protected:
182  LayeredCostmap * layered_costmap_;
183  std::string name_;
184  nav2::TransformBuffer * tf_;
185  rclcpp::CallbackGroup::SharedPtr callback_group_;
186  nav2::LifecycleNode::WeakPtr node_;
187  rclcpp::Clock::SharedPtr clock_;
188  rclcpp::Logger logger_{rclcpp::get_logger("nav2_costmap_2d")};
189 
195  virtual void onInitialize() {}
196 
197  std::atomic_bool current_;
198  // Currently this var is managed by subclasses.
199  // TODO(bpwilcox): make this managed by this class and/or container class.
200  bool enabled_;
201 
202 private:
203  std::vector<geometry_msgs::msg::Point> footprint_spec_;
204 };
205 
206 } // namespace nav2_costmap_2d
207 
208 #endif // NAV2_COSTMAP_2D__LAYER_HPP_
A 2D costmap provides a mapping between points in the world and their associated "costs".
Definition: costmap_2d.hpp:69
Abstract class for layered costmap plugin implementations.
Definition: layer.hpp:60
virtual void onFootprintChanged()
LayeredCostmap calls this whenever the footprint there changes (via LayeredCostmap::setFootprint())....
Definition: layer.hpp:121
virtual void activate()
Restart publishers if they've been stopped.
Definition: layer.hpp:83
std::string joinWithParentNamespace(const std::string &topic)
Definition: layer.cpp:83
virtual void deactivate()
Stop publishers.
Definition: layer.hpp:81
virtual bool isClearable()=0
If clearing operations should be processed on this layer or not.
void setCurrent(bool current)
Set whether the data in the layer is up to date.
Definition: layer.hpp:147
bool isCurrent() const
Check to make sure all the data in the layer is up to date. If the layer is not up to date,...
Definition: layer.hpp:138
virtual void onInitialize()
This is called at the end of initialize(). Override to implement subclass-specific initialization.
Definition: layer.hpp:195
virtual void reset()=0
Reset this costmap.
virtual ~Layer()
A destructor.
Definition: layer.hpp:69
bool isEnabled() const
Gets whether the layer is enabled.
Definition: layer.hpp:153
const std::vector< geometry_msgs::msg::Point > & getFootprint() const
Convenience function for layered_costmap_->getFootprint().
Definition: layer.cpp:70
Layer()
A constructor.
Definition: layer.cpp:39
void initialize(LayeredCostmap *parent, std::string name, nav2::TransformBuffer *tf, const nav2::LifecycleNode::WeakPtr &node, rclcpp::CallbackGroup::SharedPtr callback_group)
Initialization process of layer on startup.
Definition: layer.cpp:48
virtual void updateBounds(double robot_x, double robot_y, double robot_yaw, double *min_x, double *min_y, double *max_x, double *max_y)=0
This is called by the LayeredCostmap to poll this plugin as to how much of the costmap it needs to up...
virtual void matchSize()
Implement this to make this layer match the size of the parent costmap.
Definition: layer.hpp:116
virtual void updateCosts(Costmap2D &master_grid, int min_i, int min_j, int max_i, int max_j)=0
Actually update the underlying costmap, only within the bounds calculated during UpdateBounds().
std::string getFullName(const std::string &param_name)
Convenience functions for declaring ROS parameters.
Definition: layer.cpp:76
std::string getName() const
Get the name of the costmap layer.
Definition: layer.hpp:123
Instantiates different layer plugins and aggregates them into one score.