Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
map_saver.hpp
1 // Copyright (c) 2020 Samsung Research Russia
2 // Copyright (c) 2018 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef NAV2_MAP_SERVER__MAP_SAVER_HPP_
17 #define NAV2_MAP_SERVER__MAP_SAVER_HPP_
18 
19 #include <memory>
20 #include <string>
21 
22 #include "rclcpp/rclcpp.hpp"
23 #include "rclcpp_lifecycle/state.hpp"
24 #include "nav2_ros_common/lifecycle_node.hpp"
25 #include "nav2_msgs/srv/save_map.hpp"
26 #include "nav2_ros_common/service_server.hpp"
27 
28 #include "map_io.hpp"
29 
30 namespace nav2_map_server
31 {
32 
38 {
39 public:
44  explicit MapSaver(const rclcpp::NodeOptions & options = rclcpp::NodeOptions());
45 
49  ~MapSaver();
50 
57  bool saveMapTopicToFile(
58  const std::string & map_topic,
59  const SaveParameters & save_parameters);
60 
66  nav2::CallbackReturn on_configure(const rclcpp_lifecycle::State & state) override;
72  nav2::CallbackReturn on_activate(const rclcpp_lifecycle::State & state) override;
78  nav2::CallbackReturn on_deactivate(const rclcpp_lifecycle::State & state) override;
84  nav2::CallbackReturn on_cleanup(const rclcpp_lifecycle::State & state) override;
90  nav2::CallbackReturn on_shutdown(const rclcpp_lifecycle::State & state) override;
91 
92 protected:
99  void saveMapCallback(
100  const std::shared_ptr<rmw_request_id_t> request_header,
101  const std::shared_ptr<nav2_msgs::srv::SaveMap::Request> request,
102  std::shared_ptr<nav2_msgs::srv::SaveMap::Response> response);
103 
104  // The timeout for saving the map in service
105  std::shared_ptr<rclcpp::Duration> save_map_timeout_;
106  // Default values for map thresholds
107  double free_thresh_default_;
108  double occupied_thresh_default_;
109  // param for handling QoS configuration
110  bool map_subscribe_transient_local_;
111 
112  // The name of the service for saving a map from topic
113  const std::string save_map_service_name_{"save_map"};
114  // A service to save the map to a file at run time (SaveMap)
115  nav2::ServiceServer<nav2_msgs::srv::SaveMap>::SharedPtr save_map_service_;
116 };
117 
118 } // namespace nav2_map_server
119 
120 #endif // NAV2_MAP_SERVER__MAP_SAVER_HPP_
A lifecycle node wrapper to enable common Nav2 needs such as manipulating parameters.
A class that provides map saving methods and services.
Definition: map_saver.hpp:38
nav2::CallbackReturn on_cleanup(const rclcpp_lifecycle::State &state) override
Called when it is required node clean-up.
Definition: map_saver.cpp:105
nav2::CallbackReturn on_configure(const rclcpp_lifecycle::State &state) override
Sets up map saving service.
Definition: map_saver.cpp:61
~MapSaver()
Destructor for the nav2_map_server::MapServer.
Definition: map_saver.cpp:56
nav2::CallbackReturn on_activate(const rclcpp_lifecycle::State &state) override
Called when node switched to active state.
Definition: map_saver.cpp:83
nav2::CallbackReturn on_shutdown(const rclcpp_lifecycle::State &state) override
Called when in Shutdown state.
Definition: map_saver.cpp:115
void saveMapCallback(const std::shared_ptr< rmw_request_id_t > request_header, const std::shared_ptr< nav2_msgs::srv::SaveMap::Request > request, std::shared_ptr< nav2_msgs::srv::SaveMap::Response > response)
Map saving service callback.
Definition: map_saver.cpp:121
bool saveMapTopicToFile(const std::string &map_topic, const SaveParameters &save_parameters)
Read a message from incoming map topic and save map to a file.
Definition: map_saver.cpp:144
nav2::CallbackReturn on_deactivate(const rclcpp_lifecycle::State &state) override
Called when node switched to inactive state.
Definition: map_saver.cpp:94
MapSaver(const rclcpp::NodeOptions &options=rclcpp::NodeOptions())
Constructor for the nav2_map_server::MapSaver.
Definition: map_saver.cpp:44