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/callback_group.hpp"
47 #include "rclcpp/clock.hpp"
48 #include "rclcpp/logger.hpp"
49 #include "nav2_costmap_2d/costmap_2d.hpp"
50 #include "nav2_costmap_2d/layered_costmap.hpp"
51 #include "nav2_ros_common/lifecycle_node.hpp"
52 
53 namespace nav2_costmap_2d
54 {
55 class LayeredCostmap;
56 
61 class Layer
62 {
63 public:
67  Layer();
71  virtual ~Layer() {}
72 
76  void initialize(
77  LayeredCostmap * parent,
78  std::string name,
79  nav2::TransformBuffer * tf,
80  const nav2::LifecycleNode::WeakPtr & node,
81  rclcpp::CallbackGroup::SharedPtr callback_group);
83  virtual void deactivate() {}
85  virtual void activate() {}
89  virtual void reset() = 0;
93  virtual bool isClearable() = 0;
94 
103  virtual void updateBounds(
104  double robot_x, double robot_y, double robot_yaw, double * min_x,
105  double * min_y,
106  double * max_x,
107  double * max_y) = 0;
108 
113  virtual void updateCosts(
114  Costmap2D & master_grid,
115  int min_i, int min_j, int max_i, int max_j) = 0;
116 
118  virtual void matchSize() {}
119 
123  virtual void onFootprintChanged() {}
125  std::string getName() const
126  {
127  return name_;
128  }
129 
140  bool isCurrent() const
141  {
142  return current_;
143  }
144 
149  void setCurrent(bool current)
150  {
151  current_ = current;
152  }
153 
155  bool isEnabled() const
156  {
157  return enabled_;
158  }
159 
161  const std::vector<geometry_msgs::msg::Point> & getFootprint() const;
163  std::string getFullName(const std::string & param_name);
164 
181  std::string joinWithParentNamespace(const std::string & topic);
182 
183 protected:
184  LayeredCostmap * layered_costmap_;
185  std::string name_;
186  nav2::TransformBuffer * tf_;
187  rclcpp::CallbackGroup::SharedPtr callback_group_;
188  nav2::LifecycleNode::WeakPtr node_;
189  rclcpp::Clock::SharedPtr clock_;
190  rclcpp::Logger logger_{rclcpp::get_logger("nav2_costmap_2d")};
191 
197  virtual void onInitialize() {}
198 
199  std::atomic_bool current_;
200  // Currently this var is managed by subclasses.
201  // TODO(bpwilcox): make this managed by this class and/or container class.
202  bool enabled_;
203 
204 private:
205  std::vector<geometry_msgs::msg::Point> footprint_spec_;
206 };
207 
208 } // namespace nav2_costmap_2d
209 
210 #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:62
virtual void onFootprintChanged()
LayeredCostmap calls this whenever the footprint there changes (via LayeredCostmap::setFootprint())....
Definition: layer.hpp:123
virtual void activate()
Restart publishers if they've been stopped.
Definition: layer.hpp:85
std::string joinWithParentNamespace(const std::string &topic)
Definition: layer.cpp:83
virtual void deactivate()
Stop publishers.
Definition: layer.hpp:83
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:149
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:140
virtual void onInitialize()
This is called at the end of initialize(). Override to implement subclass-specific initialization.
Definition: layer.hpp:197
virtual void reset()=0
Reset this costmap.
virtual ~Layer()
A destructor.
Definition: layer.hpp:71
bool isEnabled() const
Gets whether the layer is enabled.
Definition: layer.hpp:155
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:118
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:125
Instantiates different layer plugins and aggregates them into one score.