AutoAPMS
Resilient Robot Mission Management
|
Base class that offers basic functionality for executing behavior trees. More...
#include <auto_apms_behavior_tree/executor/executor_base.hpp>
Public Types | |
enum class | ExecutionState : uint8_t { IDLE , STARTING , RUNNING , PAUSED , HALTED } |
Enum representing possible behavior tree execution states. More... | |
enum class | ControlCommand : uint8_t { RUN , PAUSE , HALT , TERMINATE } |
Enum representing possible commands for controlling the behavior tree execution routine. More... | |
enum class | TreeExitBehavior : uint8_t { TERMINATE , RESTART } |
Enum representing possible options for what to do when a behavior tree is completed. More... | |
enum class | ExecutionResult : uint8_t { TREE_SUCCEEDED , TREE_FAILED , TERMINATED_PREMATURELY , ERROR } |
Enum representing possible behavior tree execution results. More... | |
Public Member Functions | |
TreeExecutorBase (rclcpp::Node::SharedPtr node_ptr, rclcpp::CallbackGroup::SharedPtr tree_node_callback_group_ptr=nullptr) | |
Constructor. | |
std::shared_future< ExecutionResult > | startExecution (TreeConstructor make_tree, double tick_rate_sec=0.1, int groot2_port=-1) |
Start a behavior tree that is built using a callback. | |
template<typename TimeRepT = int64_t, typename TimeT = std::milli> | |
std::shared_future< ExecutionResult > | startExecution (TreeConstructor make_tree, const std::chrono::duration< TimeRepT, TimeT > &tick_rate, int groot2_port=-1) |
Start a behavior tree that is built using a callback. | |
void | setControlCommand (ControlCommand cmd) |
Set the command that handles the control flow of the execution routine. | |
bool | isBusy () |
Determine whether this executor is currently executing a behavior tree. | |
ExecutionState | getExecutionState () |
Get a status code indicating the current state of execution. | |
std::string | getTreeName () |
Get the name of the tree that is currently executing. | |
TreeBlackboardSharedPtr | getGlobalBlackboardPtr () |
Get a shared pointer to the global blackboard instance. | |
void | clearGlobalBlackboard () |
Reset the global blackboard and clear all entries. | |
TreeStateObserver & | getStateObserver () |
Get a reference to the current behavior tree state observer. | |
rclcpp::Node::SharedPtr | getNodePtr () |
Get a shared pointer to the parent ROS 2 node. | |
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr | get_node_base_interface () |
Get the node's base interface. Is required to be able to register derived classes as ROS2 components. | |
rclcpp::CallbackGroup::SharedPtr | getTreeNodeWaitablesCallbackGroupPtr () |
Get the callback group used for all waitables registered by behavior tree nodes. | |
rclcpp::executors::SingleThreadedExecutor::SharedPtr | getTreeNodeWaitablesExecutorPtr () |
Get the ROS 2 executor instance used for spinning waitables registered by behavior tree nodes. | |
Protected Attributes | |
rclcpp::Node::SharedPtr | node_ptr_ |
Shared pointer to the parent ROS 2 node. | |
const rclcpp::Logger | logger_ |
Logger associated with the parent ROS 2 node. | |
Private Member Functions | |
virtual bool | onInitialTick () |
Callback invoked once before the behavior tree is ticked for the very first time. | |
virtual bool | onTick () |
Callback invoked every time before the behavior tree is ticked. | |
virtual bool | afterTick () |
Callback invoked every time after the behavior tree is ticked. | |
virtual TreeExitBehavior | onTreeExit (bool success) |
Callback invoked last thing when the execution routine completes because the behavior tree is finished. | |
virtual void | onTermination (const ExecutionResult &result) |
Callback invoked when the execution routine terminates. | |
Base class that offers basic functionality for executing behavior trees.
This class implements a highly configurable execution routine for behavior trees. Inheriting classes are able to modify certain callbacks by overriding the corresponding virtual methods. The user is able to control the execution by giving certain commands at runtime.
rclcpp::Node
. Definition at line 40 of file executor_base.hpp.
|
strong |
Enum representing possible behavior tree execution states.
Definition at line 46 of file executor_base.hpp.
|
strong |
Enum representing possible commands for controlling the behavior tree execution routine.
Definition at line 58 of file executor_base.hpp.
|
strong |
Enum representing possible options for what to do when a behavior tree is completed.
Enumerator | |
---|---|
TERMINATE | Stop execution and reset the timer. |
RESTART | Restart execution and keep on running. |
Definition at line 69 of file executor_base.hpp.
|
strong |
Enum representing possible behavior tree execution results.
Definition at line 78 of file executor_base.hpp.
TreeExecutorBase | ( | rclcpp::Node::SharedPtr | node_ptr, |
rclcpp::CallbackGroup::SharedPtr | tree_node_callback_group_ptr = nullptr ) |
Constructor.
node_ptr | Parent ROS 2 node to be used to set up the required communication interfaces. |
tree_node_callback_group_ptr | Callback group that is used for all waitables registered by behavior tree nodes. |
Definition at line 25 of file executor_base.cpp.
std::shared_future< TreeExecutorBase::ExecutionResult > startExecution | ( | TreeConstructor | make_tree, |
double | tick_rate_sec = 0.1, | ||
int | groot2_port = -1 ) |
Start a behavior tree that is built using a callback.
Executing the behavior tree is achieved by regularly invoking the internal routine that ticks the behavior tree created using make_tree
. This requires to register a timer with the associated ROS 2 node. Consequently, the behavior tree is executed asynchronously. The user is provided a shared future object that allows to check whether the execution finished. Once this future completes, the execution result can be evaluated.
make_tree | Callback that creates a BT::Tree object which will be ticked to execute the tree. |
tick_rate_sec | Behavior tree tick rate in seconds (1 tick every tick_rate_sec seconds) i.e. the interval of the timer that regularly invokes the execution routine. |
groot2_port | Port number used for introspection and debugging with Groot2. -1 means that no BT::Groot2Publisher will be installed. |
Definition at line 50 of file executor_base.cpp.
|
inline |
Start a behavior tree that is built using a callback.
Executing the behavior tree is achieved by regularly invoking the internal routine that ticks the behavior tree created using make_tree
. This requires to register a timer with the associated ROS 2 node. Consequently, the behavior tree is executed asynchronously. The user is provided a shared future object that allows to check whether the execution finished. Once this future completes, the execution result can be evaluated.
make_tree | Callback that creates a BT::Tree object which will be ticked to execute the tree. |
tick_rate | Behavior tree tick rate i.e. the interval of the timer that regularly invokes the execution routine. |
groot2_port | Port number used for introspection and debugging with Groot2. -1 means that no BT::Groot2Publisher will be installed. |
Definition at line 289 of file executor_base.hpp.
|
privatevirtual |
Callback invoked once before the behavior tree is ticked for the very first time.
false
if the execution should be aborted, true
to continue. Definition at line 239 of file executor_base.cpp.
|
privatevirtual |
Callback invoked every time before the behavior tree is ticked.
false
if the execution should be aborted, true
to continue. Reimplemented in TreeExecutorNode.
Definition at line 241 of file executor_base.cpp.
|
privatevirtual |
Callback invoked every time after the behavior tree is ticked.
false
if the execution should be aborted, true
to continue. Reimplemented in TreeExecutorNode.
Definition at line 243 of file executor_base.cpp.
|
privatevirtual |
Callback invoked last thing when the execution routine completes because the behavior tree is finished.
This callback is only invoked, if there haven't been any errors during execution.
Definition at line 245 of file executor_base.cpp.
|
privatevirtual |
Callback invoked when the execution routine terminates.
If the execution routine is restarted, this won't be called. It's only when a final result is available, that this callback takes effect.
result | Final result code of the behavior tree execution. |
Reimplemented in TreeExecutorNode.
Definition at line 250 of file executor_base.cpp.
void setControlCommand | ( | ControlCommand | cmd | ) |
Set the command that handles the control flow of the execution routine.
cmd | Control command. |
Definition at line 252 of file executor_base.cpp.
bool isBusy | ( | ) |
Determine whether this executor is currently executing a behavior tree.
true
if this executor is busy, false
otherwise. Definition at line 254 of file executor_base.cpp.
TreeExecutorBase::ExecutionState getExecutionState | ( | ) |
Get a status code indicating the current state of execution.
Definition at line 256 of file executor_base.cpp.
std::string getTreeName | ( | ) |
Get the name of the tree that is currently executing.
If the executor is not busy, NO_TREE_NAME
is returned.
Definition at line 269 of file executor_base.cpp.
TreeBlackboardSharedPtr getGlobalBlackboardPtr | ( | ) |
Get a shared pointer to the global blackboard instance.
The global blackboard is used as a root blackboard on every tree that is being created. This means, that all entries of the global blackboard are publicly available to the trees at runtime and can be queried using the '@' prefix.
Definition at line 275 of file executor_base.cpp.
void clearGlobalBlackboard | ( | ) |
Reset the global blackboard and clear all entries.
Definition at line 277 of file executor_base.cpp.
TreeStateObserver & getStateObserver | ( | ) |
Get a reference to the current behavior tree state observer.
auto_apms_behavior_tree::exceptions::TreeExecutorError | if executor is not busy. |
Definition at line 279 of file executor_base.cpp.
rclcpp::Node::SharedPtr getNodePtr | ( | ) |
Get a shared pointer to the parent ROS 2 node.
rclcpp::Node
associated with this executor. Definition at line 287 of file executor_base.cpp.
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr get_node_base_interface | ( | ) |
Get the node's base interface. Is required to be able to register derived classes as ROS2 components.
rclcpp::Node
associated with this executor. Definition at line 289 of file executor_base.cpp.
rclcpp::CallbackGroup::SharedPtr getTreeNodeWaitablesCallbackGroupPtr | ( | ) |
Get the callback group used for all waitables registered by behavior tree nodes.
Definition at line 294 of file executor_base.cpp.
rclcpp::executors::SingleThreadedExecutor::SharedPtr getTreeNodeWaitablesExecutorPtr | ( | ) |
Get the ROS 2 executor instance used for spinning waitables registered by behavior tree nodes.
rclcpp::executors::SingleThreadedExecutor
for behavior tree node waitables. Definition at line 299 of file executor_base.cpp.
|
protected |
Shared pointer to the parent ROS 2 node.
Definition at line 258 of file executor_base.hpp.
|
protected |
Logger associated with the parent ROS 2 node.
Definition at line 260 of file executor_base.hpp.