Nav2 Navigation Stack - lyrical  lyrical
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 #include <functional>
22 
23 #include "rclcpp/rclcpp.hpp"
24 #include "nav2_msgs/srv/clear_costmap_except_region.hpp"
25 #include "nav2_msgs/srv/clear_costmap_around_robot.hpp"
26 #include "nav2_msgs/srv/clear_costmap_around_pose.hpp"
27 #include "nav2_msgs/srv/clear_entire_costmap.hpp"
28 #include "nav2_costmap_2d/costmap_layer.hpp"
29 #include "nav2_ros_common/lifecycle_node.hpp"
30 #include "nav2_ros_common/service_server.hpp"
31 
32 namespace nav2_costmap_2d
33 {
34 
35 class Costmap2DROS;
36 
42 {
43 public:
48  const nav2::LifecycleNode::WeakPtr & parent, Costmap2DROS & costmap);
49 
53  ClearCostmapService() = delete;
54 
59 
64  bool clearRegion(double reset_distance, bool invert, const std::vector<std::string> & plugins);
65 
70  bool clearAroundPose(
71  const geometry_msgs::msg::PoseStamped & pose, double reset_distance,
72  const std::vector<std::string> & plugins);
73 
78  bool clearEntirely(const std::vector<std::string> & plugins);
79 
80 private:
81  // The Logger object for logging
82  rclcpp::Logger logger_{rclcpp::get_logger("nav2_costmap_2d")};
83 
84  // The costmap to clear
85  Costmap2DROS & costmap_;
86 
87  // Clearing parameters
88  unsigned char reset_value_;
89 
90  // Server for clearing the costmap
91  nav2::ServiceServer<nav2_msgs::srv::ClearCostmapExceptRegion>::SharedPtr
92  clear_except_service_;
96  void clearExceptRegionCallback(
97  const std::shared_ptr<rmw_request_id_t> request_header,
98  const std::shared_ptr<nav2_msgs::srv::ClearCostmapExceptRegion::Request> request,
99  const std::shared_ptr<nav2_msgs::srv::ClearCostmapExceptRegion::Response> response);
100 
101  nav2::ServiceServer<nav2_msgs::srv::ClearCostmapAroundRobot>::SharedPtr
102  clear_around_service_;
106  void clearAroundRobotCallback(
107  const std::shared_ptr<rmw_request_id_t> request_header,
108  const std::shared_ptr<nav2_msgs::srv::ClearCostmapAroundRobot::Request> request,
109  const std::shared_ptr<nav2_msgs::srv::ClearCostmapAroundRobot::Response> response);
110 
111  nav2::ServiceServer<nav2_msgs::srv::ClearCostmapAroundPose>::SharedPtr
112  clear_around_pose_service_;
116  void clearAroundPoseCallback(
117  const std::shared_ptr<rmw_request_id_t> request_header,
118  const std::shared_ptr<nav2_msgs::srv::ClearCostmapAroundPose::Request> request,
119  const std::shared_ptr<nav2_msgs::srv::ClearCostmapAroundPose::Response> response);
120 
121  nav2::ServiceServer<nav2_msgs::srv::ClearEntireCostmap>::SharedPtr
122  clear_entire_service_;
126  void clearEntireCallback(
127  const std::shared_ptr<rmw_request_id_t> request_header,
128  const std::shared_ptr<nav2_msgs::srv::ClearEntireCostmap::Request> request,
129  const std::shared_ptr<nav2_msgs::srv::ClearEntireCostmap::Response> response);
130 
134  void clearLayerRegion(
135  std::shared_ptr<CostmapLayer> & costmap, double pose_x, double pose_y, double reset_distance,
136  bool invert);
137 
141  bool getPosition(double & x, double & y) const;
142 
149  void validatePlugins(
150  const std::vector<std::string> & requested_plugins,
151  const std::vector<std::shared_ptr<Layer>> * layers,
152  std::vector<std::string> & invalid_plugins) const;
153 
164  bool validateAndClearPlugins(
165  const std::vector<std::string> & plugins,
166  const std::vector<std::shared_ptr<Layer>> * layers,
167  std::function<void(std::shared_ptr<CostmapLayer> &)> clear_callback,
168  const std::string & operation_name) const;
169 };
170 
171 } // namespace nav2_costmap_2d
172 
173 #endif // NAV2_COSTMAP_2D__CLEAR_COSTMAP_SERVICE_HPP_
Exposes services to clear costmap objects in inclusive/exclusive regions or completely.
bool clearAroundPose(const geometry_msgs::msg::PoseStamped &pose, double reset_distance, const std::vector< std::string > &plugins)
Clears the region around a specific pose.
bool clearEntirely(const std::vector< std::string > &plugins)
Clears the entire layer.
ClearCostmapService()=delete
A constructor.
bool clearRegion(double reset_distance, bool invert, const std::vector< std::string > &plugins)
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...