Class BTAction

Inheritance Relationships

Base Type

  • public plansys2::ActionExecutorClient

Class Documentation

class BTAction : public plansys2::ActionExecutorClient

Class that implements an action executor using Behavior Trees.

This class provides a framework for executing PDDL actions using Behavior Trees. It loads and executes a BT from an XML file and handles the lifecycle operations.

Public Functions

explicit BTAction(const std::string &action)

Constructor for the BTAction.

Parameters:

action[in] Name of the action this executor handles.

BTAction(const std::string &action, const std::chrono::nanoseconds &rate)

Constructor for the BTAction.

Parameters:
  • action[in] Name of the action this executor handles.

  • rate[in] Execution rate for the action.

inline const std::string &getActionName() const

Get the name of the action.

Returns:

std::string The action name.

inline const std::string &getBTFile() const

Get the path to the BT XML file.

Returns:

std::string The path to the BT XML file.

Protected Types

using CallbackReturnT = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn

Protected Functions

CallbackReturnT on_configure(const rclcpp_lifecycle::State &state)

Configures the action executor.

Retrieves parameters for action name, BT XML file, and plugins. Registers BT plugins and creates a blackboard.

Parameters:

state[in] The current lifecycle state.

Returns:

SUCCESS if configuration successful, FAILURE otherwise.

CallbackReturnT on_activate(const rclcpp_lifecycle::State &state)

Activates the action executor.

Creates the BT from the XML file, sets up the blackboard with action arguments, and initializes logging if enabled.

Parameters:

state[in] The current lifecycle state.

Returns:

SUCCESS if activation successful, FAILURE otherwise.

CallbackReturnT on_deactivate(const rclcpp_lifecycle::State &state)

Deactivates the action executor.

Cleans up loggers and halts the BT.

Parameters:

state[in] The current lifecycle state.

Returns:

SUCCESS if deactivation successful, FAILURE otherwise.

CallbackReturnT on_cleanup(const rclcpp_lifecycle::State &state)

Cleans up resources.

Parameters:

state[in] The current lifecycle state.

Returns:

SUCCESS if cleanup successful, FAILURE otherwise.

void do_work()

Main work method that executes the BT.

Called periodically to execute a tick of the BT. Handles the BT execution status (SUCCESS, RUNNING, FAILURE) and reports feedback/results accordingly.

void add_groot_monitoring(BT::Tree *tree, uint16_t server_port)

Add Groot2 monitor to publish BT status changes.

Parameters:
  • tree – BT to monitor

  • server_port – Groot2 Server port, first of the pair (server_port, publisher_port)

void reset_groot_monitor()

Reset Groot2 monitor.

Protected Attributes

BT::BehaviorTreeFactory factory_

Factory for creating Behavior Trees instances.

Return:

BT::BehaviorTreeFactory& Reference to the factory.