AutoAPMS
Resilient Robot Mission Management
Loading...
Searching...
No Matches
tree_builder.hpp
Go to the documentation of this file.
1// Copyright 2024 Robin Müller
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// https://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#pragma once
16
17#include <tinyxml2.h>
18
23
25{
26
41{
42 static inline const std::string MAIN_TREE_ATTRIBUTE_NAME = "main_tree_to_execute";
43 static inline const std::string TREE_ELEMENT_NAME = "BehaviorTree";
44 static inline const std::string TREE_ID_ATTRIBUTE_NAME = "ID";
45
46public:
47 TreeBuilder(std::shared_ptr<BT::BehaviorTreeFactory> factory_ptr = std::make_shared<BT::BehaviorTreeFactory>());
48
59 TreeBuilder& registerNodePlugins(rclcpp::Node::SharedPtr node_ptr, const NodeManifest& node_manifest,
60 NodePluginClassLoader& tree_node_loader, bool override = false);
61
67 TreeBuilder& registerNodePlugins(rclcpp::Node::SharedPtr node_ptr, const NodeManifest& node_manifest,
68 bool override = false);
69
70 TreeBuilder& addTreeFromXMLDocument(const tinyxml2::XMLDocument& doc);
71
72 TreeBuilder& addTreeFromString(const std::string& tree_str);
73
74 TreeBuilder& addTreeFromFile(const std::string& tree_file_path);
75
76 TreeBuilder& addTreeFromResource(const TreeResource& resource, rclcpp::Node::SharedPtr node_ptr);
77
78 std::string getMainTreeName() const;
79
80 TreeBuilder& setMainTreeName(const std::string& main_tree_name);
81
82 std::string writeTreeXMLToString() const;
83
84 std::unordered_map<std::string, BT::NodeType> getRegisteredNodes();
85
86 Tree buildTree(const std::string main_tree_name, TreeBlackboardSharedPtr root_bb_ptr = TreeBlackboard::create());
87
88 Tree buildTree(TreeBlackboardSharedPtr root_bb_ptr = TreeBlackboard::create());
89
90 /* Static helper functions */
91
92 static std::set<std::string> getTreeNames(const tinyxml2::XMLDocument& doc);
93
94 static std::string writeXMLDocumentToString(const tinyxml2::XMLDocument& doc);
95
96private:
97 tinyxml2::XMLDocument doc_;
98 std::shared_ptr<BT::BehaviorTreeFactory> factory_ptr_;
99};
100
101} // namespace auto_apms_behavior_tree
Data structure for resource lookup data and configuration parameters required for loading and registe...
Version of pluginlib::ClassLoader specifically for loading installed behavior tree node plugins.
Class for creating behavior trees according to the builder design pattern.
TreeBuilder & addTreeFromString(const std::string &tree_str)
TreeBuilder(std::shared_ptr< BT::BehaviorTreeFactory > factory_ptr=std::make_shared< BT::BehaviorTreeFactory >())
TreeBuilder & addTreeFromFile(const std::string &tree_file_path)
static std::set< std::string > getTreeNames(const tinyxml2::XMLDocument &doc)
std::unordered_map< std::string, BT::NodeType > getRegisteredNodes()
TreeBuilder & addTreeFromResource(const TreeResource &resource, rclcpp::Node::SharedPtr node_ptr)
static std::string writeXMLDocumentToString(const tinyxml2::XMLDocument &doc)
TreeBuilder & addTreeFromXMLDocument(const tinyxml2::XMLDocument &doc)
TreeBuilder & setMainTreeName(const std::string &main_tree_name)
TreeBuilder & registerNodePlugins(rclcpp::Node::SharedPtr node_ptr, const NodeManifest &node_manifest, NodePluginClassLoader &tree_node_loader, bool override=false)
Load behavior tree node plugins and register with behavior tree factory.
Tree buildTree(const std::string main_tree_name, TreeBlackboardSharedPtr root_bb_ptr=TreeBlackboard::create())
std::shared_ptr< TreeBlackboard > TreeBlackboardSharedPtr
Struct containing behavior tree resource data.