15 #ifndef NAV2_COSTMAP_2D__COSTMAP_SUBSCRIBER_HPP_
16 #define NAV2_COSTMAP_2D__COSTMAP_SUBSCRIBER_HPP_
24 #include "rclcpp/rclcpp.hpp"
25 #include "nav2_costmap_2d/costmap_2d.hpp"
26 #include "nav2_msgs/msg/costmap.hpp"
27 #include "nav2_msgs/msg/costmap_update.hpp"
28 #include "nav2_ros_common/lifecycle_node.hpp"
43 const nav2::LifecycleNode::WeakPtr & parent,
44 const std::string & topic_name);
46 template<
typename NodeT>
49 const std::string & topic_name,
50 const rclcpp::CallbackGroup::SharedPtr & callback_group =
nullptr)
51 : topic_name_(topic_name)
53 logger_ = parent->get_logger();
57 costmap_sub_ = nav2::interfaces::create_subscription<nav2_msgs::msg::Costmap>(
62 costmap_update_sub_ = nav2::interfaces::create_subscription<nav2_msgs::msg::CostmapUpdate>(
63 parent, topic_name_ +
"_updates",
80 void costmapCallback(
const nav2_msgs::msg::Costmap::ConstSharedPtr & msg);
86 std::string getFrameID()
const
92 bool isCostmapReceived()
94 std::lock_guard<std::mutex> guard(costmap_msg_mutex_);
95 return costmap_ !=
nullptr;
97 void processCurrentCostmapMsg();
99 bool haveCostmapParametersChanged();
100 bool hasCostmapSizeChanged();
101 bool hasCostmapResolutionChanged();
102 bool hasCostmapOriginPositionChanged();
104 nav2::Subscription<nav2_msgs::msg::Costmap>::SharedPtr costmap_sub_;
105 nav2::Subscription<nav2_msgs::msg::CostmapUpdate>::SharedPtr costmap_update_sub_;
107 std::shared_ptr<Costmap2D> costmap_;
108 nav2_msgs::msg::Costmap::ConstSharedPtr costmap_msg_;
110 std::string topic_name_;
111 std::string frame_id_;
112 std::mutex costmap_msg_mutex_;
113 rclcpp::Logger logger_{rclcpp::get_logger(
"nav2_costmap_2d")};
A QoS profile for latched, reliable topics with a history of 10 messages.
Subscribes to the costmap via a ros topic.
CostmapSubscriber(const nav2::LifecycleNode::WeakPtr &parent, const std::string &topic_name)
A constructor.
~CostmapSubscriber()
A destructor.
std::shared_ptr< Costmap2D > getCostmap()
Get current costmap.
void costmapCallback(const nav2_msgs::msg::Costmap::ConstSharedPtr &msg)
Callback for the costmap topic.
void costmapUpdateCallback(const nav2_msgs::msg::CostmapUpdate::ConstSharedPtr &update_msg)
Callback for the costmap's update topic.