Nav2 Navigation Stack - humble  humble
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 
29 namespace nav2_costmap_2d
30 {
31 
32 class Costmap2DROS;
33 
39 {
40 public:
44  ClearCostmapService(const nav2_util::LifecycleNode::WeakPtr & parent, Costmap2DROS & costmap);
45 
49  ClearCostmapService() = delete;
50 
55 
59  void clearRegion(double reset_distance, bool invert);
60 
64  void clearEntirely();
65 
66 private:
67  // The Logger object for logging
68  rclcpp::Logger logger_{rclcpp::get_logger("nav2_costmap_2d")};
69 
70  // The costmap to clear
71  Costmap2DROS & costmap_;
72 
73  // Clearing parameters
74  unsigned char reset_value_;
75 
76  // Server for clearing the costmap
77  rclcpp::Service<nav2_msgs::srv::ClearCostmapExceptRegion>::SharedPtr clear_except_service_;
81  void clearExceptRegionCallback(
82  const std::shared_ptr<rmw_request_id_t> request_header,
83  const std::shared_ptr<nav2_msgs::srv::ClearCostmapExceptRegion::Request> request,
84  const std::shared_ptr<nav2_msgs::srv::ClearCostmapExceptRegion::Response> response);
85 
86  rclcpp::Service<nav2_msgs::srv::ClearCostmapAroundRobot>::SharedPtr clear_around_service_;
90  void clearAroundRobotCallback(
91  const std::shared_ptr<rmw_request_id_t> request_header,
92  const std::shared_ptr<nav2_msgs::srv::ClearCostmapAroundRobot::Request> request,
93  const std::shared_ptr<nav2_msgs::srv::ClearCostmapAroundRobot::Response> response);
94 
95  rclcpp::Service<nav2_msgs::srv::ClearEntireCostmap>::SharedPtr clear_entire_service_;
99  void clearEntireCallback(
100  const std::shared_ptr<rmw_request_id_t> request_header,
101  const std::shared_ptr<nav2_msgs::srv::ClearEntireCostmap::Request> request,
102  const std::shared_ptr<nav2_msgs::srv::ClearEntireCostmap::Response> response);
103 
107  void clearLayerRegion(
108  std::shared_ptr<CostmapLayer> & costmap, double pose_x, double pose_y, double reset_distance,
109  bool invert);
110 
114  bool getPosition(double & x, double & y) const;
115 };
116 
117 } // namespace nav2_costmap_2d
118 
119 #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...