Nav2 Navigation Stack - kilted  kilted
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, rclcpp::Node::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...
 
void addGrootMonitoring (BT::Tree *tree, uint16_t server_port)
 Add Groot2 monitor to publish BT status changes. More...
 
void resetGrootMonitor ()
 Reset groot monitor.
 
void haltAllActions (BT::Tree &tree)
 Function to explicitly reset all BT nodes to initial state. More...
 

Protected Attributes

BT::BehaviorTreeFactory factory_
 
rclcpp::Clock::SharedPtr clock_
 
std::unique_ptr< BT::Groot2Publisher > groot_monitor_
 

Detailed Description

A class to create and handle behavior trees.

Definition at line 43 of file behavior_tree_engine.hpp.

Constructor & Destructor Documentation

◆ BehaviorTreeEngine()

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

A constructor for nav2_behavior_tree::BehaviorTreeEngine.

Parameters
plugin_librariesvector of BT plugin library names to load

Definition at line 31 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 105 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 97 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 89 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 127 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 49 of file behavior_tree_engine.cpp.


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