Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
costmap.hpp
1 // Copyright (c) 2018 Intel Corporation
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_UTIL__COSTMAP_HPP_
16 #define NAV2_UTIL__COSTMAP_HPP_
17 
18 #include <vector>
19 #include <cstdint>
20 
21 #include "nav2_ros_common/lifecycle_node.hpp"
22 #include "nav2_msgs/msg/costmap.hpp"
23 #include "nav2_msgs/msg/costmap_meta_data.hpp"
24 #include "nav_msgs/msg/occupancy_grid.hpp"
25 
26 namespace nav2_util
27 {
28 
29 enum class TestCostmap
30 {
31  open_space,
32  bounded,
33  bottom_left_obstacle,
34  top_left_obstacle,
35  maze1,
36  maze2
37 };
38 
44 class Costmap
45 {
46 public:
47  typedef uint8_t CostValue;
48 
57  Costmap(
58  nav2::LifecycleNode * node, bool trinary_costmap = true, bool track_unknown_space = true,
59  int lethal_threshold = 100, int unknown_cost_value = -1);
60  Costmap() = delete;
61  ~Costmap();
62 
67  void set_static_map(const nav_msgs::msg::OccupancyGrid & occupancy_grid);
68 
73  void set_test_costmap(const TestCostmap & testCostmapType);
74 
80  nav2_msgs::msg::Costmap get_costmap(const nav2_msgs::msg::CostmapMetaData & specifications);
81 
86  nav2_msgs::msg::CostmapMetaData get_properties() {return costmap_properties_;}
87 
92  bool is_free(const unsigned int x_coordinate, const unsigned int y_coordinate) const;
93 
98  bool is_free(const unsigned int index) const;
99 
100  // Mapping for often used cost values
101  static const CostValue no_information;
102  static const CostValue lethal_obstacle;
103  static const CostValue inscribed_inflated_obstacle;
104  static const CostValue medium_cost;
105  static const CostValue free_space;
106 
107 private:
112  std::vector<uint8_t> get_test_data(const TestCostmap configuration);
113 
118  uint8_t interpret_value(const int8_t value) const;
119 
120  // Costmap isn't itself a node
121  nav2::LifecycleNode * node_;
122 
123  // TODO(orduno): For now, only holding costs from static map
124  nav2_msgs::msg::CostmapMetaData costmap_properties_;
125  std::vector<uint8_t> costs_;
126 
127  // Static layer parameters
128  bool trinary_costmap_;
129  bool track_unknown_space_;
130  int lethal_threshold_;
131  int unknown_cost_value_;
132 
133  // Flags to determine the origin of the costmap
134  bool map_provided_;
135  bool using_test_map_;
136 };
137 
138 } // namespace nav2_util
139 
140 #endif // NAV2_UTIL__COSTMAP_HPP_
A lifecycle node wrapper to enable common Nav2 needs such as manipulating parameters.
Class for a single layered costmap initialized from an occupancy grid representing the map.
Definition: costmap.hpp:45
nav2_msgs::msg::CostmapMetaData get_properties()
Get a metadata message from this object.
Definition: costmap.hpp:86
bool is_free(const unsigned int x_coordinate, const unsigned int y_coordinate) const
Get whether some coordinates are free.
Definition: costmap.cpp:250
void set_static_map(const nav_msgs::msg::OccupancyGrid &occupancy_grid)
Set the static map of this costmap.
Definition: costmap.cpp:52
void set_test_costmap(const TestCostmap &testCostmapType)
Set the test costmap type of this costmap.
Definition: costmap.cpp:87
nav2_msgs::msg::Costmap get_costmap(const nav2_msgs::msg::CostmapMetaData &specifications)
Get a costmap message from this object.
Definition: costmap.cpp:108