15 #ifndef NAV2_COSTMAP_2D__COSTMAP_SUBSCRIBER_HPP_
16 #define NAV2_COSTMAP_2D__COSTMAP_SUBSCRIBER_HPP_
24 #include "rclcpp/callback_group.hpp"
25 #include "rclcpp/logger.hpp"
26 #include "rclcpp/node.hpp"
27 #include "nav2_costmap_2d/costmap_2d.hpp"
28 #include "nav2_msgs/msg/costmap.hpp"
29 #include "nav2_msgs/msg/costmap_update.hpp"
30 #include "nav2_ros_common/lifecycle_node.hpp"
45 const nav2::LifecycleNode::WeakPtr & parent,
46 const std::string & topic_name);
48 template<
typename NodeT>
51 const std::string & topic_name,
52 const rclcpp::CallbackGroup::SharedPtr & callback_group =
nullptr)
53 : topic_name_(topic_name)
55 logger_ = parent->get_logger();
59 costmap_sub_ = nav2::interfaces::create_subscription<nav2_msgs::msg::Costmap>(
64 costmap_update_sub_ = nav2::interfaces::create_subscription<nav2_msgs::msg::CostmapUpdate>(
65 parent, topic_name_ +
"_updates",
82 void costmapCallback(
const nav2_msgs::msg::Costmap::ConstSharedPtr & msg);
88 std::string getFrameID()
const
94 bool isCostmapReceived()
96 std::lock_guard<std::recursive_mutex> guard(costmap_msg_mutex_);
97 return costmap_ !=
nullptr;
99 void processCurrentCostmapMsg();
101 bool haveCostmapParametersChanged();
102 bool hasCostmapSizeChanged();
103 bool hasCostmapResolutionChanged();
104 bool hasCostmapOriginPositionChanged();
106 nav2::Subscription<nav2_msgs::msg::Costmap>::SharedPtr costmap_sub_;
107 nav2::Subscription<nav2_msgs::msg::CostmapUpdate>::SharedPtr costmap_update_sub_;
109 std::shared_ptr<Costmap2D> costmap_;
110 nav2_msgs::msg::Costmap::ConstSharedPtr costmap_msg_;
112 std::string topic_name_;
113 std::string frame_id_;
114 std::recursive_mutex costmap_msg_mutex_;
115 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.