Nav2 Navigation Stack - kilted  kilted
ROS 2 Navigation Stack
clear_costmap_service.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_COSTMAP_2D__CLEAR_COSTMAP_SERVICE_HPP_
16 #define NAV2_COSTMAP_2D__CLEAR_COSTMAP_SERVICE_HPP_
17 
18 #include <vector>
19 #include <string>
20 #include <memory>
21 
22 #include "rclcpp/rclcpp.hpp"
23 #include "nav2_msgs/srv/clear_costmap_except_region.hpp"
24 #include "nav2_msgs/srv/clear_costmap_around_robot.hpp"
25 #include "nav2_msgs/srv/clear_entire_costmap.hpp"
26 #include "nav2_costmap_2d/costmap_layer.hpp"
27 #include "nav2_util/lifecycle_node.hpp"
28 #include "nav2_util/service_server.hpp"
29 
30 namespace nav2_costmap_2d
31 {
32 
33 class Costmap2DROS;
34 
40 {
41 public:
46  const nav2_util::LifecycleNode::WeakPtr & parent, Costmap2DROS & costmap);
47 
51  ClearCostmapService() = delete;
52 
57 
61  void clearRegion(double reset_distance, bool invert);
62 
66  void clearEntirely();
67 
68 private:
69  // The Logger object for logging
70  rclcpp::Logger logger_{rclcpp::get_logger("nav2_costmap_2d")};
71 
72  // The costmap to clear
73  Costmap2DROS & costmap_;
74 
75  // Clearing parameters
76  unsigned char reset_value_;
77 
78  // Server for clearing the costmap
79  nav2_util::ServiceServer<nav2_msgs::srv::ClearCostmapExceptRegion,
80  std::shared_ptr<rclcpp_lifecycle::LifecycleNode>>::SharedPtr clear_except_service_;
84  void clearExceptRegionCallback(
85  const std::shared_ptr<rmw_request_id_t> request_header,
86  const std::shared_ptr<nav2_msgs::srv::ClearCostmapExceptRegion::Request> request,
87  const std::shared_ptr<nav2_msgs::srv::ClearCostmapExceptRegion::Response> response);
88 
89  nav2_util::ServiceServer<nav2_msgs::srv::ClearCostmapAroundRobot,
90  std::shared_ptr<rclcpp_lifecycle::LifecycleNode>>::SharedPtr clear_around_service_;
94  void clearAroundRobotCallback(
95  const std::shared_ptr<rmw_request_id_t> request_header,
96  const std::shared_ptr<nav2_msgs::srv::ClearCostmapAroundRobot::Request> request,
97  const std::shared_ptr<nav2_msgs::srv::ClearCostmapAroundRobot::Response> response);
98 
99  nav2_util::ServiceServer<nav2_msgs::srv::ClearEntireCostmap,
100  std::shared_ptr<rclcpp_lifecycle::LifecycleNode>>::SharedPtr clear_entire_service_;
104  void clearEntireCallback(
105  const std::shared_ptr<rmw_request_id_t> request_header,
106  const std::shared_ptr<nav2_msgs::srv::ClearEntireCostmap::Request> request,
107  const std::shared_ptr<nav2_msgs::srv::ClearEntireCostmap::Response> response);
108 
112  void clearLayerRegion(
113  std::shared_ptr<CostmapLayer> & costmap, double pose_x, double pose_y, double reset_distance,
114  bool invert);
115 
119  bool getPosition(double & x, double & y) const;
120 };
121 
122 } // namespace nav2_costmap_2d
123 
124 #endif // NAV2_COSTMAP_2D__CLEAR_COSTMAP_SERVICE_HPP_
Exposes services to clear costmap objects in inclusive/exclusive regions or completely.
ClearCostmapService()=delete
A constructor.
void clearRegion(double reset_distance, bool invert)
Clears the region outside of a user-specified area reverting to the static map.
A ROS wrapper for a 2D Costmap. Handles subscribing to topics that provide observations about obstacl...
A simple wrapper on ROS2 services server.