Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
Public Member Functions | Protected Attributes | List of all members
nav2_behavior_tree::BehaviorTreeEngine Class Reference

A class to create and handle behavior trees. More...

#include <nav2_behavior_tree/include/nav2_behavior_tree/behavior_tree_engine.hpp>

Public Member Functions

 BehaviorTreeEngine (const std::vector< std::string > &plugin_libraries, nav2::LifecycleNode::SharedPtr node)
 A constructor for nav2_behavior_tree::BehaviorTreeEngine. More...
 
BtStatus run (BT::Tree *tree, std::function< void()> onLoop, std::function< bool()> cancelRequested, std::chrono::milliseconds loopTimeout=std::chrono::milliseconds(10))
 Function to execute a BT at a specific rate. More...
 
BT::Tree createTreeFromText (const std::string &xml_string, BT::Blackboard::Ptr blackboard)
 Function to create a BT from a XML string. More...
 
BT::Tree createTreeFromFile (const std::string &file_path, BT::Blackboard::Ptr blackboard)
 Function to create a BT from an XML file. More...
 
BTInfo parseTreeInfo (const std::string &filename)
 Function to parse Behavior Tree information from an XML file. More...
 
BT::Tree createTree (const std::string &tree_id, BT::Blackboard::Ptr blackboard)
 Function to create a BT from a BehaviorTree ID. More...
 
void addGrootMonitoring (BT::Tree *tree, uint16_t server_port)
 Add Groot2 monitor to publish BT status changes. More...
 
void resetGrootMonitor ()
 Reset groot monitor.
 
void registerTreeFromFile (const std::string &file_path)
 Function to register a BT from an XML file. More...
 
void haltAllActions (BT::Tree &tree)
 Function to explicitly reset all BT nodes to initial state. More...
 

Protected Attributes

BT::BehaviorTreeFactory factory_
 
nav2::LifecycleNode::WeakPtr node_
 
std::unique_ptr< BT::Groot2Publisher > groot_monitor_
 

Detailed Description

A class to create and handle behavior trees.

Definition at line 53 of file behavior_tree_engine.hpp.

Constructor & Destructor Documentation

◆ BehaviorTreeEngine()

nav2_behavior_tree::BehaviorTreeEngine::BehaviorTreeEngine ( const std::vector< std::string > &  plugin_libraries,
nav2::LifecycleNode::SharedPtr  node 
)
explicit

A constructor for nav2_behavior_tree::BehaviorTreeEngine.

Parameters
plugin_librariesvector of BT plugin library names to load

Definition at line 33 of file behavior_tree_engine.cpp.

Member Function Documentation

◆ addGrootMonitoring()

void nav2_behavior_tree::BehaviorTreeEngine::addGrootMonitoring ( BT::Tree *  tree,
uint16_t  server_port 
)

Add Groot2 monitor to publish BT status changes.

Parameters
treeBT to monitor
server_portGroot2 Server port, first of the pair (server_port, publisher_port)

Definition at line 190 of file behavior_tree_engine.cpp.

◆ createTree()

BT::Tree nav2_behavior_tree::BehaviorTreeEngine::createTree ( const std::string &  tree_id,
BT::Blackboard::Ptr  blackboard 
)

Function to create a BT from a BehaviorTree ID.

Parameters
tree_idBehaviorTree ID
blackboardBlackboard for BT
Returns
BT::Tree Created behavior tree

Definition at line 175 of file behavior_tree_engine.cpp.

◆ createTreeFromFile()

BT::Tree nav2_behavior_tree::BehaviorTreeEngine::createTreeFromFile ( const std::string &  file_path,
BT::Blackboard::Ptr  blackboard 
)

Function to create a BT from an XML file.

Parameters
file_pathPath to BT XML file
blackboardBlackboard for BT
Returns
BT::Tree Created behavior tree

Definition at line 113 of file behavior_tree_engine.cpp.

◆ createTreeFromText()

BT::Tree nav2_behavior_tree::BehaviorTreeEngine::createTreeFromText ( const std::string &  xml_string,
BT::Blackboard::Ptr  blackboard 
)

Function to create a BT from a XML string.

Parameters
xml_stringXML string representing BT
blackboardBlackboard for BT
Returns
BT::Tree Created behavior tree

Definition at line 105 of file behavior_tree_engine.cpp.

◆ haltAllActions()

void nav2_behavior_tree::BehaviorTreeEngine::haltAllActions ( BT::Tree &  tree)

Function to explicitly reset all BT nodes to initial state.

Parameters
treeTree to halt

Definition at line 212 of file behavior_tree_engine.cpp.

◆ parseTreeInfo()

BTInfo nav2_behavior_tree::BehaviorTreeEngine::parseTreeInfo ( const std::string &  filename)

Function to parse Behavior Tree information from an XML file.

Parameters
filenamePath to BT XML file
Returns
BTInfo Struct containing BT ID information

Definition at line 120 of file behavior_tree_engine.cpp.

◆ registerTreeFromFile()

void nav2_behavior_tree::BehaviorTreeEngine::registerTreeFromFile ( const std::string &  file_path)

Function to register a BT from an XML file.

Register a tree from an XML file and return the tree.

Parameters
file_pathPath to BT XML file

Definition at line 183 of file behavior_tree_engine.cpp.

◆ run()

BtStatus nav2_behavior_tree::BehaviorTreeEngine::run ( BT::Tree *  tree,
std::function< void()>  onLoop,
std::function< bool()>  cancelRequested,
std::chrono::milliseconds  loopTimeout = std::chrono::milliseconds(10) 
)

Function to execute a BT at a specific rate.

Parameters
treeBT to execute
onLoopFunction to execute on each iteration of BT execution
cancelRequestedFunction to check if cancel was requested during BT execution
loopTimeoutTime period for each iteration of BT execution
Returns
nav2_behavior_tree::BtStatus Status of BT execution

Definition at line 46 of file behavior_tree_engine.cpp.


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