Class BehaviorTreeEngine

Class Documentation

class BehaviorTreeEngine

A class to create and handle behavior trees.

Public Functions

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

A constructor for nav2_behavior_tree::BehaviorTreeEngine.

Parameters:

plugin_libraries – vector of BT plugin library names to load

inline virtual ~BehaviorTreeEngine()
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.

Parameters:
  • tree – BT to execute

  • onLoop – Function to execute on each iteration of BT execution

  • cancelRequested – Function to check if cancel was requested during BT execution

  • loopTimeout – Time period for each iteration of BT execution

Returns:

nav2_behavior_tree::BtStatus Status of BT execution

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

Function to create a BT from a XML string.

Parameters:
  • xml_string – XML string representing BT

  • blackboard – Blackboard for BT

Returns:

BT::Tree Created behavior tree

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

Function to create a BT from an XML file.

Parameters:
  • file_path – Path to BT XML file

  • blackboard – Blackboard for BT

Returns:

BT::Tree Created behavior tree

void haltAllActions(BT::Tree &tree)

Function to explicitly reset all BT nodes to initial state.

Parameters:

tree – Tree to halt

Protected Attributes

BT::BehaviorTreeFactory factory_
rclcpp::Clock::SharedPtr clock_