Nav2 Navigation Stack - jazzy  jazzy
ROS 2 Navigation Stack
generate_nav2_tree_nodes_xml.cpp
1 // Copyright (c) 2024 Davide Faconti
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. Reserved.
14 
15 #include <vector>
16 #include <string>
17 #include <fstream>
18 
19 #include "behaviortree_cpp/behavior_tree.h"
20 #include "behaviortree_cpp/bt_factory.h"
21 #include "behaviortree_cpp/utils/shared_library.h"
22 #include "behaviortree_cpp/xml_parsing.h"
23 
24 #include "plugins_list.hpp"
25 #include "nav2_util/string_utils.hpp"
26 
27 int main()
28 {
29  BT::BehaviorTreeFactory factory;
30 
31  std::vector<std::string> plugins_list = nav2_util::split(nav2::details::BT_BUILTIN_PLUGINS, ';');
32 
33  for (const auto & plugin : plugins_list) {
34  std::cout << "Loading: " << plugin << "\n";
35  factory.registerFromPlugin(BT::SharedLibrary::getOSName(plugin));
36  }
37  std::cout << "\nGenerating file: nav2_tree_nodes.xml\n"
38  << "\nCompare it with the one in the git repo and update the latter if necessary.\n";
39 
40  std::ofstream xml_file;
41  xml_file.open("nav2_tree_nodes.xml");
42  xml_file << BT::writeTreeNodesModelXML(factory) << std::endl;
43  xml_file.close();
44 
45  return 0;
46 }