Public Member Functions | Private Attributes | List of all members
BT::BehaviorTreeFactory Class Reference

The BehaviorTreeFactory is used to create instances of a TreeNode at run-time. More...

#include <bt_factory.h>

Public Member Functions

void addDescriptionToManifest (const std::string &node_id, const std::string &description)
 
 BehaviorTreeFactory ()
 
const std::unordered_map< std::string, NodeBuilder > & builders () const
 All the builders. Made available mostly for debug purposes. More...
 
const std::set< std::string > & builtinNodes () const
 List of builtin IDs. More...
 
void clearRegisteredBehaviorTrees ()
 Clear previously-registered behavior trees. More...
 
Tree createTree (const std::string &tree_name, Blackboard::Ptr blackboard=Blackboard::create())
 
Tree createTreeFromFile (const std::string &file_path, Blackboard::Ptr blackboard=Blackboard::create())
 
Tree createTreeFromText (const std::string &text, Blackboard::Ptr blackboard=Blackboard::create())
 
std::unique_ptr< TreeNodeinstantiateTreeNode (const std::string &name, const std::string &ID, const NodeConfiguration &config) const
 instantiateTreeNode creates an instance of a previously registered TreeNode. More...
 
const std::unordered_map< std::string, TreeNodeManifest > & manifests () const
 Manifests of all the registered TreeNodes. More...
 
void registerBehaviorTreeFromFile (const std::string &filename)
 registerBehaviorTreeFromFile. Load the definition of an entire behavior tree, but don't instantiate it. You can instantiate it later with: More...
 
void registerBehaviorTreeFromText (const std::string &xml_text)
 
void registerBuilder (const TreeNodeManifest &manifest, const NodeBuilder &builder)
 
template<typename T >
void registerBuilder (const std::string &ID, const NodeBuilder &builder)
 
std::vector< std::string > registeredBehaviorTrees () const
 
void registerFromPlugin (const std::string &file_path)
 registerFromPlugin load a shared library and execute the function BT_REGISTER_NODES (see macro). More...
 
void registerFromROSPlugins ()
 registerFromROSPlugins finds all shared libraries that export ROS plugins for behaviortree_cpp, and calls registerFromPlugin for each library. More...
 
template<typename T >
void registerNodeType (const std::string &ID)
 
template<typename T >
void registerNodeType (const std::string &ID, PortsList ports)
 
void registerSimpleAction (const std::string &ID, const SimpleActionNode::TickFunctor &tick_functor, PortsList ports={})
 registerSimpleAction help you register nodes of type SimpleActionNode. More...
 
void registerSimpleCondition (const std::string &ID, const SimpleConditionNode::TickFunctor &tick_functor, PortsList ports={})
 registerSimpleCondition help you register nodes of type SimpleConditionNode. More...
 
void registerSimpleDecorator (const std::string &ID, const SimpleDecoratorNode::TickFunctor &tick_functor, PortsList ports={})
 registerSimpleDecorator help you register nodes of type SimpleDecoratorNode. More...
 
bool unregisterBuilder (const std::string &ID)
 Remove a registered ID. More...
 

Private Attributes

std::unordered_map< std::string, Anybehavior_tree_definitions_
 
std::unordered_map< std::string, NodeBuilderbuilders_
 
std::set< std::string > builtin_IDs_
 
std::unordered_map< std::string, TreeNodeManifestmanifests_
 
std::shared_ptr< BT::Parserparser_
 

Detailed Description

The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.

Some node types are "builtin", whilst other are used defined and need to be registered using a unique ID.

Definition at line 251 of file bt_factory.h.

Constructor & Destructor Documentation

◆ BehaviorTreeFactory()

BT::BehaviorTreeFactory::BehaviorTreeFactory ( )

Definition at line 25 of file bt_factory.cpp.

Member Function Documentation

◆ addDescriptionToManifest()

void BT::BehaviorTreeFactory::addDescriptionToManifest ( const std::string &  node_id,
const std::string &  description 
)

Add a description to a specific manifest. This description will be added to <TreeNodesModel> with the function writeTreeNodesModelXML()

Definition at line 321 of file bt_factory.cpp.

◆ builders()

const std::unordered_map< std::string, NodeBuilder > & BT::BehaviorTreeFactory::builders ( ) const

All the builders. Made available mostly for debug purposes.

Definition at line 262 of file bt_factory.cpp.

◆ builtinNodes()

const std::set< std::string > & BT::BehaviorTreeFactory::builtinNodes ( ) const

List of builtin IDs.

Definition at line 273 of file bt_factory.cpp.

◆ clearRegisteredBehaviorTrees()

void BT::BehaviorTreeFactory::clearRegisteredBehaviorTrees ( )

Clear previously-registered behavior trees.

Definition at line 238 of file bt_factory.cpp.

◆ createTree()

Tree BT::BehaviorTreeFactory::createTree ( const std::string &  tree_name,
Blackboard::Ptr  blackboard = Blackboard::create() 
)

Definition at line 313 of file bt_factory.cpp.

◆ createTreeFromFile()

Tree BT::BehaviorTreeFactory::createTreeFromFile ( const std::string &  file_path,
Blackboard::Ptr  blackboard = Blackboard::create() 
)

Definition at line 295 of file bt_factory.cpp.

◆ createTreeFromText()

Tree BT::BehaviorTreeFactory::createTreeFromText ( const std::string &  text,
Blackboard::Ptr  blackboard = Blackboard::create() 
)

Definition at line 278 of file bt_factory.cpp.

◆ instantiateTreeNode()

std::unique_ptr< TreeNode > BT::BehaviorTreeFactory::instantiateTreeNode ( const std::string &  name,
const std::string &  ID,
const NodeConfiguration config 
) const

instantiateTreeNode creates an instance of a previously registered TreeNode.

Parameters
namename of this particular instance
IDID used when it was registered
configconfiguration that is passed to the constructor of the TreeNode.
Returns
new node.

Definition at line 243 of file bt_factory.cpp.

◆ manifests()

const std::unordered_map< std::string, TreeNodeManifest > & BT::BehaviorTreeFactory::manifests ( ) const

Manifests of all the registered TreeNodes.

Definition at line 268 of file bt_factory.cpp.

◆ registerBehaviorTreeFromFile()

void BT::BehaviorTreeFactory::registerBehaviorTreeFromFile ( const std::string &  filename)

registerBehaviorTreeFromFile. Load the definition of an entire behavior tree, but don't instantiate it. You can instantiate it later with:

BehaviorTreeFactory::createTree(tree_id)

where "tree_id" come from the XML attribute <BehaviorTree id="tree_id">

Definition at line 223 of file bt_factory.cpp.

◆ registerBehaviorTreeFromText()

void BT::BehaviorTreeFactory::registerBehaviorTreeFromText ( const std::string &  xml_text)

Same of registerBehaviorTreeFromFile, but passing the XML text, instead of the filename.

Definition at line 228 of file bt_factory.cpp.

◆ registerBuilder() [1/2]

void BT::BehaviorTreeFactory::registerBuilder ( const TreeNodeManifest manifest,
const NodeBuilder builder 
)

The most generic way to register a NodeBuilder.

Throws if you try to register twice a builder with the same registration_ID.

Definition at line 91 of file bt_factory.cpp.

◆ registerBuilder() [2/2]

template<typename T >
void BT::BehaviorTreeFactory::registerBuilder ( const std::string &  ID,
const NodeBuilder builder 
)
inline

Definition at line 267 of file bt_factory.h.

◆ registeredBehaviorTrees()

std::vector< std::string > BT::BehaviorTreeFactory::registeredBehaviorTrees ( ) const

Returns the ID of the trees registered either with registerBehaviorTreeFromFile or registerBehaviorTreeFromText.

Definition at line 233 of file bt_factory.cpp.

◆ registerFromPlugin()

void BT::BehaviorTreeFactory::registerFromPlugin ( const std::string &  file_path)

registerFromPlugin load a shared library and execute the function BT_REGISTER_NODES (see macro).

Parameters
file_pathpath of the file

Definition at line 143 of file bt_factory.cpp.

◆ registerFromROSPlugins()

void BT::BehaviorTreeFactory::registerFromROSPlugins ( )

registerFromROSPlugins finds all shared libraries that export ROS plugins for behaviortree_cpp, and calls registerFromPlugin for each library.

Exceptions
Ifnot compiled with ROS support or if the library cannot load for any reason

Definition at line 214 of file bt_factory.cpp.

◆ registerNodeType() [1/2]

template<typename T >
void BT::BehaviorTreeFactory::registerNodeType ( const std::string &  ID)
inline

registerNodeType is the method to use to register your custom TreeNode.

It accepts only classed derived from either ActionNodeBase, DecoratorNode, ControlNode or ConditionNode.

Definition at line 364 of file bt_factory.h.

◆ registerNodeType() [2/2]

template<typename T >
void BT::BehaviorTreeFactory::registerNodeType ( const std::string &  ID,
PortsList  ports 
)
inline

Definition at line 422 of file bt_factory.h.

◆ registerSimpleAction()

void BT::BehaviorTreeFactory::registerSimpleAction ( const std::string &  ID,
const SimpleActionNode::TickFunctor tick_functor,
PortsList  ports = {} 
)

registerSimpleAction help you register nodes of type SimpleActionNode.

Parameters
IDregistration ID
tick_functorthe callback to be invoked in the tick() method.
portsif your SimpleNode requires ports, provide the list here.

Definition at line 117 of file bt_factory.cpp.

◆ registerSimpleCondition()

void BT::BehaviorTreeFactory::registerSimpleCondition ( const std::string &  ID,
const SimpleConditionNode::TickFunctor tick_functor,
PortsList  ports = {} 
)

registerSimpleCondition help you register nodes of type SimpleConditionNode.

Parameters
IDregistration ID
tick_functorthe callback to be invoked in the tick() method.
portsif your SimpleNode requires ports, provide the list here.

Definition at line 104 of file bt_factory.cpp.

◆ registerSimpleDecorator()

void BT::BehaviorTreeFactory::registerSimpleDecorator ( const std::string &  ID,
const SimpleDecoratorNode::TickFunctor tick_functor,
PortsList  ports = {} 
)

registerSimpleDecorator help you register nodes of type SimpleDecoratorNode.

Parameters
IDregistration ID
tick_functorthe callback to be invoked in the tick() method.
portsif your SimpleNode requires ports, provide the list here.

Definition at line 130 of file bt_factory.cpp.

◆ unregisterBuilder()

bool BT::BehaviorTreeFactory::unregisterBuilder ( const std::string &  ID)

Remove a registered ID.

Definition at line 75 of file bt_factory.cpp.

Member Data Documentation

◆ behavior_tree_definitions_

std::unordered_map<std::string, Any> BT::BehaviorTreeFactory::behavior_tree_definitions_
private

Definition at line 493 of file bt_factory.h.

◆ builders_

std::unordered_map<std::string, NodeBuilder> BT::BehaviorTreeFactory::builders_
private

Definition at line 490 of file bt_factory.h.

◆ builtin_IDs_

std::set<std::string> BT::BehaviorTreeFactory::builtin_IDs_
private

Definition at line 492 of file bt_factory.h.

◆ manifests_

std::unordered_map<std::string, TreeNodeManifest> BT::BehaviorTreeFactory::manifests_
private

Definition at line 491 of file bt_factory.h.

◆ parser_

std::shared_ptr<BT::Parser> BT::BehaviorTreeFactory::parser_
private

Definition at line 495 of file bt_factory.h.


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


behaviortree_cpp_v3
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Mon Jul 3 2023 02:50:14