Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
costmap.hpp
Go to the documentation of this file.
1 // Copyright (c) 2025 Angsa Robotics
2 // Copyright (c) 2025 lotusymt
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef NAV2_COLLISION_MONITOR__COSTMAP_HPP_
17 #define NAV2_COLLISION_MONITOR__COSTMAP_HPP_
18 
24 #include <memory>
25 #include <string>
26 #include <vector>
27 
28 #include "nav2_collision_monitor/source.hpp"
29 #include "nav2_msgs/msg/costmap.hpp"
30 #include <nav2_ros_common/lifecycle_node.hpp>
31 #include <nav2_ros_common/subscription.hpp>
32 #include "nav2_ros_common/tf2_factories.hpp"
33 
34 namespace nav2_collision_monitor
35 {
36 
49 class CostmapSource : public Source
50 {
51 public:
64  const nav2::LifecycleNode::WeakPtr & node,
65  const std::string & source_name,
66  const nav2::TransformBuffer::SharedPtr tf_buffer,
67  const std::string & base_frame_id,
68  const std::string & global_frame_id,
69  const tf2::Duration & transform_tolerance,
70  const rclcpp::Duration & source_timeout,
71  const bool base_shift_correction);
72 
75 
83  bool configure();
84 
96  bool getSourceData(
97  const rclcpp::Time & curr_time,
98  std::vector<Point> & data) override;
99 
106  void getParameters(std::string & source_topic);
107 
112  bool hasData() const {return data_ != nullptr;}
113 
114 private:
119  void dataCallback(nav2_msgs::msg::Costmap::ConstSharedPtr msg);
120 
122  nav2_msgs::msg::Costmap::ConstSharedPtr data_;
123 
125  nav2::Subscription<nav2_msgs::msg::Costmap>::SharedPtr data_sub_;
126 
131  int cost_threshold_{253};
132 
136  bool treat_unknown_as_obstacle_{true};
137 };
138 
139 } // namespace nav2_collision_monitor
140 
141 #endif // NAV2_COLLISION_MONITOR__COSTMAP_HPP_
Reads nav2_msgs::msg::Costmap and produces obstacle points for Collision Monitor.
Definition: costmap.hpp:50
bool configure()
Declare and get parameters; create the subscription.
Definition: costmap.cpp:53
bool hasData() const
Check if costmap data has been received.
Definition: costmap.hpp:112
void getParameters(std::string &source_topic)
Read parameters specific to the costmap source.
Definition: costmap.cpp:122
bool getSourceData(const rclcpp::Time &curr_time, std::vector< Point > &data) override
Produce current obstacle points from the latest costmap.
Definition: costmap.cpp:72
CostmapSource(const nav2::LifecycleNode::WeakPtr &node, const std::string &source_name, const nav2::TransformBuffer::SharedPtr tf_buffer, const std::string &base_frame_id, const std::string &global_frame_id, const tf2::Duration &transform_tolerance, const rclcpp::Duration &source_timeout, const bool base_shift_correction)
Construct a CostmapSource.
Definition: costmap.cpp:30
Basic data source class.
Definition: source.hpp:44