Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
vector_object_utils.hpp
1 // Copyright (c) 2023 Samsung R&D Institute Russia
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_MAP_SERVER__VECTOR_OBJECT_UTILS_HPP_
16 #define NAV2_MAP_SERVER__VECTOR_OBJECT_UTILS_HPP_
17 
18 #include <uuid/uuid.h>
19 #include <stdexcept>
20 #include <string>
21 
22 #include "nav_msgs/msg/occupancy_grid.hpp"
23 
24 #include "nav2_ros_common/lifecycle_node.hpp"
25 #include "nav2_ros_common/node_utils.hpp"
26 #include "nav2_util/occ_grid_values.hpp"
27 
28 namespace nav2_map_server
29 {
30 
31 // ---------- Working with UUID-s ----------
32 
38 inline std::string unparseUUID(const unsigned char * uuid)
39 {
40  char uuid_str[37];
41  uuid_unparse(uuid, uuid_str);
42  return std::string(uuid_str);
43 }
44 
45 // ---------- Working with shapes' overlays ----------
46 
48 enum class OverlayType : uint8_t
49 {
50  OVERLAY_SEQ = 0, // Vector objects are superimposed in the order in which they have arrived
51  OVERLAY_MAX = 1, // Maximum value from vector objects and map is being chosen
52  OVERLAY_MIN = 2 // Minimum value from vector objects and map is being chosen
53 };
54 
62 inline void processVal(
63  int8_t & map_val, const int8_t shape_val,
64  const OverlayType overlay_type)
65 {
66  switch (overlay_type) {
67  case OverlayType::OVERLAY_SEQ:
68  map_val = shape_val;
69  return;
70  case OverlayType::OVERLAY_MAX:
71  if (shape_val > map_val) {
72  map_val = shape_val;
73  }
74  return;
75  case OverlayType::OVERLAY_MIN:
76  if ((map_val == nav2_util::OCC_GRID_UNKNOWN || shape_val < map_val) &&
77  shape_val != nav2_util::OCC_GRID_UNKNOWN)
78  {
79  map_val = shape_val;
80  }
81  return;
82  default:
83  throw std::runtime_error{"Unknown overlay type"};
84  }
85 }
86 
94 inline void processCell(
95  const nav_msgs::msg::OccupancyGrid::SharedPtr & map,
96  const unsigned int offset,
97  const int8_t shape_val,
98  const OverlayType overlay_type)
99 {
100  processVal(map->data[offset], shape_val, overlay_type);
101 }
102 
105 {
106 public:
114  nav_msgs::msg::OccupancyGrid::SharedPtr map,
115  int8_t value, OverlayType overlay_type)
116  : map_(map), value_(value), overlay_type_(overlay_type)
117  {}
118 
123  inline void operator()(unsigned int offset)
124  {
125  processCell(map_, offset, value_, overlay_type_);
126  }
127 
128 protected:
130  nav_msgs::msg::OccupancyGrid::SharedPtr map_;
132  int8_t value_;
134  OverlayType overlay_type_;
135 };
136 
137 } // namespace nav2_map_server
138 
139 #endif // NAV2_MAP_SERVER__VECTOR_OBJECT_UTILS_HPP_
Functor class used in raytraceLine algorithm.
OverlayType overlay_type_
Overlay type.
void operator()(unsigned int offset)
Map' cell updating operator.
MapAction(nav_msgs::msg::OccupancyGrid::SharedPtr map, int8_t value, OverlayType overlay_type)
MapAction constructor.
nav_msgs::msg::OccupancyGrid::SharedPtr map_
Output map pointer.
int8_t value_
Value to put on map.