AutoAPMS
Resilient Robot Mission Management
Loading...
Searching...
No Matches
TreeBuilder Class Reference

#include <auto_apms_behavior_tree/builder/tree_builder.hpp>

Public Member Functions

 TreeBuilder (std::shared_ptr< BT::BehaviorTreeFactory > factory_ptr=std::make_shared< BT::BehaviorTreeFactory >())
 
TreeBuilderregisterNodePlugins (rclcpp::Node::SharedPtr node_ptr, const NodeManifest &node_manifest, NodePluginClassLoader &tree_node_loader, bool override=false)
 
TreeBuilderregisterNodePlugins (rclcpp::Node::SharedPtr node_ptr, const NodeManifest &node_manifest, bool override=false)
 
TreeBuilderaddTreeFromXMLDocument (const tinyxml2::XMLDocument &doc)
 
TreeBuilderaddTreeFromString (const std::string &tree_str)
 
TreeBuilderaddTreeFromFile (const std::string &tree_file_path)
 
TreeBuilderaddTreeFromResource (const TreeResource &resource, rclcpp::Node::SharedPtr node_ptr)
 
std::string getMainTreeName () const
 
TreeBuildersetMainTreeName (const std::string &main_tree_name)
 
std::string writeTreeXMLToString () const
 
std::unordered_map< std::string, BT::NodeType > getRegisteredNodes ()
 
Tree buildTree (const std::string main_tree_name, TreeBlackboardSharedPtr root_bb_ptr=TreeBlackboard::create())
 
Tree buildTree (TreeBlackboardSharedPtr root_bb_ptr=TreeBlackboard::create())
 

Static Public Member Functions

static std::set< std::string > getTreeNames (const tinyxml2::XMLDocument &doc)
 
static std::string writeXMLDocumentToString (const tinyxml2::XMLDocument &doc)
 

Detailed Description

Class for creating behavior trees according to the builder design pattern.

This class extends the functionality provided by BT::BehaviorTreeFactory of BehaviorTree.CPP and offers a user-friendly API for configuring behavior trees. In contrast to the original package, the user doesn't need to manually register behavior tree node entities with the factory in order to create an instance of BT::Tree. Instead, this class conveniently automates this process for you by querying the available ament_index plugin resources implemented and registered by the developer. Additionally, this class allows for building custom XML definitions of trees programmatically.

Definition at line 40 of file tree_builder.hpp.

Constructor & Destructor Documentation

◆ TreeBuilder()

TreeBuilder ( std::shared_ptr< BT::BehaviorTreeFactory > factory_ptr = std::make_shared<BT::BehaviorTreeFactory>())

Definition at line 24 of file tree_builder.cpp.

Member Function Documentation

◆ registerNodePlugins() [1/2]

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.

Parameters
[in]node_ptrROS2 node to pass to RosNodeContext.
[in]node_manifestParameters for locating and configuring the behavior tree node plugins.
[in]tree_node_loaderReference to loader for behavior tree node plugin classes.
[in]overrideIf node_manifest specifies nodes that have already been registered, unregister the existing plugin and use the new one instead.
Exceptions
exceptions::TreeBuildErrorif registration fails.

Definition at line 29 of file tree_builder.cpp.

◆ registerNodePlugins() [2/2]

TreeBuilder & registerNodePlugins ( rclcpp::Node::SharedPtr node_ptr,
const NodeManifest & node_manifest,
bool override = false )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Creates a default behavior tree node plugin class loader.

Definition at line 100 of file tree_builder.cpp.

◆ addTreeFromXMLDocument()

TreeBuilder & addTreeFromXMLDocument ( const tinyxml2::XMLDocument & doc)

Definition at line 107 of file tree_builder.cpp.

◆ addTreeFromString()

TreeBuilder & addTreeFromString ( const std::string & tree_str)

Definition at line 155 of file tree_builder.cpp.

◆ addTreeFromFile()

TreeBuilder & addTreeFromFile ( const std::string & tree_file_path)

Definition at line 165 of file tree_builder.cpp.

◆ addTreeFromResource()

TreeBuilder & addTreeFromResource ( const TreeResource & resource,
rclcpp::Node::SharedPtr node_ptr )

Definition at line 175 of file tree_builder.cpp.

◆ getMainTreeName()

std::string getMainTreeName ( ) const

Definition at line 181 of file tree_builder.cpp.

◆ setMainTreeName()

TreeBuilder & setMainTreeName ( const std::string & main_tree_name)

Definition at line 188 of file tree_builder.cpp.

◆ writeTreeXMLToString()

std::string writeTreeXMLToString ( ) const

Definition at line 195 of file tree_builder.cpp.

◆ getRegisteredNodes()

std::unordered_map< std::string, BT::NodeType > getRegisteredNodes ( )

Definition at line 200 of file tree_builder.cpp.

◆ buildTree() [1/2]

Tree buildTree ( const std::string main_tree_name,
TreeBlackboardSharedPtr root_bb_ptr = TreeBlackboard::create() )

Definition at line 208 of file tree_builder.cpp.

◆ buildTree() [2/2]

Tree buildTree ( TreeBlackboardSharedPtr root_bb_ptr = TreeBlackboard::create())

Definition at line 225 of file tree_builder.cpp.

◆ getTreeNames()

std::set< std::string > getTreeNames ( const tinyxml2::XMLDocument & doc)
static

Definition at line 230 of file tree_builder.cpp.

◆ writeXMLDocumentToString()

std::string writeXMLDocumentToString ( const tinyxml2::XMLDocument & doc)
static

Definition at line 255 of file tree_builder.cpp.


The documentation for this class was generated from the following files: