Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
inflation_layer_interface.hpp
1 // Copyright (c) 2026, Dexory (Tony Najjar)
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef NAV2_COSTMAP_2D__INFLATION_LAYER_INTERFACE_HPP_
16 #define NAV2_COSTMAP_2D__INFLATION_LAYER_INTERFACE_HPP_
17 
18 #include <memory>
19 #include <mutex>
20 #include <string>
21 
22 #include "nav2_costmap_2d/layer.hpp"
23 #include "nav2_costmap_2d/costmap_2d.hpp"
24 #include "nav2_costmap_2d/costmap_2d_ros.hpp"
25 
26 namespace nav2_costmap_2d
27 {
28 
35 {
36 public:
37  typedef std::recursive_mutex mutex_t;
38 
39  virtual ~InflationLayerInterface() = default;
40 
45  virtual double getCostScalingFactor() = 0;
46 
51  virtual double getInflationRadius() = 0;
52 
57  virtual mutex_t * getMutex() = 0;
58 
64  virtual unsigned char computeCost(double distance) const = 0;
65 
73  static inline std::shared_ptr<InflationLayerInterface> getInflationLayer(
74  std::shared_ptr<nav2_costmap_2d::Costmap2DROS> & costmap_ros,
75  const std::string layer_name = "")
76  {
77  const auto layered_costmap = costmap_ros->getLayeredCostmap();
78  for (auto layer = layered_costmap->getPlugins()->begin();
79  layer != layered_costmap->getPlugins()->end();
80  ++layer)
81  {
82  auto inflation_layer =
83  std::dynamic_pointer_cast<nav2_costmap_2d::InflationLayerInterface>(*layer);
84  if (inflation_layer) {
85  if (layer_name.empty() || inflation_layer->getName() == layer_name) {
86  return inflation_layer;
87  }
88  }
89  }
90  return nullptr;
91  }
92 };
93 
94 } // namespace nav2_costmap_2d
95 
96 #endif // NAV2_COSTMAP_2D__INFLATION_LAYER_INTERFACE_HPP_
Abstract interface for inflation layers, providing common methods needed by navigation components reg...
virtual double getCostScalingFactor()=0
Get the cost scaling factor.
virtual unsigned char computeCost(double distance) const =0
Given a distance, compute a cost.
virtual double getInflationRadius()=0
Get the inflation radius.
virtual mutex_t * getMutex()=0
Get the mutex of the inflation information.
static std::shared_ptr< InflationLayerInterface > getInflationLayer(std::shared_ptr< nav2_costmap_2d::Costmap2DROS > &costmap_ros, const std::string layer_name="")
Get the inflation layer from a costmap, checking for both InflationLayer and LegacyInflationLayer imp...
Abstract class for layered costmap plugin implementations.
Definition: layer.hpp:60