Nav2 Navigation Stack - humble  humble
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_util/lifecycle_node.hpp"
26 #include "tf2_ros/buffer.h"
27 #include "tf2_ros/transform_listener.h"
28 #include "nav2_util/node_utils.hpp"
29 #include "nav2_util/robot_utils.hpp"
30 #include "nav2_route/types.hpp"
31 #include "nav2_route/interfaces/graph_file_saver.hpp"
32 #include "rclcpp/node_interfaces/node_parameters_interface.hpp"
33 
34 namespace nav2_route
35 {
36 
42 {
43 public:
50  explicit GraphSaver(
51  rclcpp_lifecycle::LifecycleNode::SharedPtr node,
52  std::shared_ptr<tf2_ros::Buffer> tf,
53  const std::string frame);
54 
58  ~GraphSaver() = default;
59 
66  bool saveGraphToFile(
67  Graph & graph,
68  std::string filepath = "");
69 
75  bool transformGraph(Graph & graph);
76 
77 protected:
78  std::string route_frame_, graph_filepath_;
79  std::shared_ptr<tf2_ros::Buffer> tf_;
80  rclcpp::Logger logger_{rclcpp::get_logger("GraphSaver")};
81 
82  // Graph Parser
83  pluginlib::ClassLoader<GraphFileSaver> plugin_loader_;
84  GraphFileSaver::Ptr graph_file_saver_;
85  std::string default_plugin_id_;
86  std::string plugin_type_;
87 };
88 
89 } // namespace nav2_route
90 
91 #endif // NAV2_ROUTE__GRAPH_SAVER_HPP_
An object to save graph objects to a file.
Definition: graph_saver.hpp:42
GraphSaver(rclcpp_lifecycle::LifecycleNode::SharedPtr node, std::shared_ptr< tf2_ros::Buffer > 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:64
~GraphSaver()=default
A destructor for nav2_route::GraphSaver.
bool transformGraph(Graph &graph)
Transform the coordinates in the graph to the route frame.