Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
graph_saver.hpp
1 // Copyright (c) 2024 John Chrosniak
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_ROUTE__GRAPH_SAVER_HPP_
16 #define NAV2_ROUTE__GRAPH_SAVER_HPP_
17 
18 #include <string>
19 #include <memory>
20 #include <vector>
21 #include <unordered_map>
22 #include <nlohmann/json.hpp>
23 #include <pluginlib/class_loader.hpp>
24 
25 #include "nav2_ros_common/lifecycle_node.hpp"
26 #include "nav2_ros_common/tf2_factories.hpp"
27 #include "nav2_ros_common/node_utils.hpp"
28 #include "nav2_util/robot_utils.hpp"
29 #include "nav2_route/types.hpp"
30 #include "nav2_route/interfaces/graph_file_saver.hpp"
31 #include "rclcpp/node_interfaces/node_parameters_interface.hpp"
32 
33 namespace nav2_route
34 {
35 
41 {
42 public:
49  explicit GraphSaver(
50  nav2::LifecycleNode::SharedPtr node,
51  nav2::TransformBuffer::SharedPtr tf,
52  const std::string frame);
53 
57  ~GraphSaver() = default;
58 
65  bool saveGraphToFile(
66  Graph & graph,
67  std::string filepath = "");
68 
74  bool transformGraph(Graph & graph);
75 
76 protected:
77  std::string route_frame_, graph_filepath_;
78  nav2::TransformBuffer::SharedPtr tf_;
79  rclcpp::Logger logger_{rclcpp::get_logger("GraphSaver")};
80 
81  // Graph Parser
82  pluginlib::ClassLoader<GraphFileSaver> plugin_loader_;
83  GraphFileSaver::Ptr graph_file_saver_;
84  std::string default_plugin_id_;
85  std::string plugin_type_;
86 };
87 
88 } // namespace nav2_route
89 
90 #endif // NAV2_ROUTE__GRAPH_SAVER_HPP_
An object to save graph objects to a file.
Definition: graph_saver.hpp:41
GraphSaver(nav2::LifecycleNode::SharedPtr node, nav2::TransformBuffer::SharedPtr tf, const std::string frame)
A constructor for nav2_route::GraphSaver.
Definition: graph_saver.cpp:23
bool saveGraphToFile(Graph &graph, std::string filepath="")
Saves a graph object to a file.
Definition: graph_saver.cpp:62
~GraphSaver()=default
A destructor for nav2_route::GraphSaver.
bool transformGraph(Graph &graph)
Transform the coordinates in the graph to the route frame.
Definition: graph_saver.cpp:98