Nav2 Navigation Stack - kilted  kilted
ROS 2 Navigation Stack
graph_loader.hpp
1 // Copyright (c) 2025 Open Navigation LLC
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_LOADER_HPP_
16 #define NAV2_ROUTE__GRAPH_LOADER_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_loader.hpp"
32 #include "rclcpp/node_interfaces/node_parameters_interface.hpp"
33 
34 namespace nav2_route
35 {
36 
42 {
43 public:
48  explicit GraphLoader(
49  nav2_util::LifecycleNode::SharedPtr node,
50  std::shared_ptr<tf2_ros::Buffer> tf,
51  const std::string frame);
52 
56  ~GraphLoader() = default;
57 
68  bool loadGraphFromFile(
69  Graph & graph,
70  GraphToIDMap & idx_map,
71  const std::string & filepath);
72 
83  Graph & graph,
84  GraphToIDMap & idx_map);
85 
91  bool transformGraph(Graph & graph);
92 
93 protected:
94  std::string route_frame_, graph_filepath_;
95  std::shared_ptr<tf2_ros::Buffer> tf_;
96  rclcpp::Logger logger_{rclcpp::get_logger("GraphLoader")};
97 
98  // Graph Parser
99  pluginlib::ClassLoader<GraphFileLoader> plugin_loader_;
100  GraphFileLoader::Ptr graph_file_loader_;
101  std::string default_plugin_id_;
102  std::string plugin_type_;
103 };
104 
105 } // namespace nav2_route
106 
107 #endif // NAV2_ROUTE__GRAPH_LOADER_HPP_
An action server to load graph files into the graph object for search and processing.
bool transformGraph(Graph &graph)
Transform the coordinates in the graph to the route frame.
~GraphLoader()=default
A destructor for nav2_route::GraphLoader.
bool loadGraphFromFile(Graph &graph, GraphToIDMap &idx_map, const std::string &filepath)
Loads a graph object with file information from a filepath.
bool loadGraphFromParameter(Graph &graph, GraphToIDMap &idx_map)
Loads a graph object with file information from ROS parameter, if provided.
GraphLoader(nav2_util::LifecycleNode::SharedPtr node, std::shared_ptr< tf2_ros::Buffer > tf, const std::string frame)
A constructor for nav2_route::GraphLoader.