AutoAPMS
Streamlining behaviors in ROS 2
Loading...
Searching...
No Matches
ActionBasedTreeExecutorNode< ActionT > Class Template Referenceabstract

ROS 2 node template for executing behavior trees triggered by a custom ROS 2 action goal. More...

#include <auto_apms_behavior_tree/executor/action_based_executor_node.hpp>

Inheritance diagram for ActionBasedTreeExecutorNode< ActionT >:

Public Member Functions

 ActionBasedTreeExecutorNode (const std::string &name, const std::string &action_name, Options options)
 Constructor.
 
 ActionBasedTreeExecutorNode (const std::string &name, const std::string &action_name, rclcpp::NodeOptions ros_options=rclcpp::NodeOptions())
 Constructor with default options.
 
- Public Member Functions inherited from GenericTreeExecutorNode
 GenericTreeExecutorNode (const std::string &name, Options options)
 Constructor.
 
 GenericTreeExecutorNode (rclcpp::NodeOptions options)
 Constructor with default options.
 
std::shared_future< ExecutionResultstartExecution (const std::string &build_request, const std::string &entry_point="", const core::NodeManifest &node_manifest={})
 Start the behavior tree specified by a particular build request.
 
std::shared_future< ExecutionResultstartExecution (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< ExecutionResultstartExecution (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.
 
- Public Member Functions inherited from TreeExecutorBase
 TreeExecutorBase (rclcpp::Node::SharedPtr node_ptr, rclcpp::CallbackGroup::SharedPtr tree_node_callback_group_ptr=nullptr)
 Constructor.
 
std::shared_future< ExecutionResultstartExecution (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< ExecutionResultstartExecution (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.
 
TreeStateObservergetStateObserver ()
 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 Member Functions

virtual TreeConstructor getTreeConstructorFromGoal (std::shared_ptr< const TriggerGoal > goal_ptr)=0
 Create a TreeConstructor from the received action goal.
 
virtual bool shouldAcceptGoal (const rclcpp_action::GoalUUID &uuid, std::shared_ptr< const TriggerGoal > goal_ptr)
 Determine whether an incoming trigger action goal should be accepted.
 
virtual void onAcceptedGoal (std::shared_ptr< TriggerGoalHandle > goal_handle_ptr)
 Hook called after a trigger action goal has been accepted and before execution begins.
 
virtual void onExecutionStarted (std::shared_ptr< TriggerGoalHandle > goal_handle_ptr)
 Hook called after execution has been started successfully.
 
virtual void onGoalExecutionTermination (const ExecutionResult &result, TriggerActionContext &context)
 Handle the execution result for the action client.
 
- Protected Member Functions inherited from GenericTreeExecutorNode
ExecutorParameters getExecutorParameters () const
 Get a copy of the current executor parameters.
 
std::map< std::string, rclcpp::ParameterValue > getParameterValuesWithPrefix (const std::string &prefix)
 Assemble all parameters of this node that have a specific prefix.
 
bool updateScriptingEnumsWithParameterValues (const std::map< std::string, rclcpp::ParameterValue > &value_map, bool simulate=false)
 Update the internal buffer of scripting enums.
 
bool updateGlobalBlackboardWithParameterValues (const std::map< std::string, rclcpp::ParameterValue > &value_map, bool simulate=false)
 Update the global blackboard using parameter values.
 
void loadBuildHandler (const std::string &name)
 Load a particular behavior tree build handler plugin.
 
TreeConstructor makeTreeConstructor (const std::string &build_request, const std::string &entry_point="", const core::NodeManifest &node_manifest={})
 Create a callback that builds a behavior tree according to a specific request.
 
core::TreeBuilder::SharedPtr createTreeBuilder ()
 Create a tree builder for building the behavior tree.
 
virtual bool clearGlobalBlackboard () override
 Reset the global blackboard and clear all entries.
 

Additional Inherited Members

- Public Types inherited from TreeExecutorBase
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...
 
- Static Public Attributes inherited from GenericTreeExecutorNode
static const std::string PARAM_VALUE_NO_BUILD_HANDLER = "none"
 Value indicating that no build handler is loaded.
 
- Static Protected Member Functions inherited from GenericTreeExecutorNode
static std::string stripPrefixFromParameterName (const std::string &prefix, const std::string &param_name)
 Get the name of a parameter without its prefix.
 
- Protected Attributes inherited from TreeExecutorBase
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.
 

Detailed Description

template<typename ActionT>
class auto_apms_behavior_tree::ActionBasedTreeExecutorNode< ActionT >

ROS 2 node template for executing behavior trees triggered by a custom ROS 2 action goal.

This class extends GenericTreeExecutorNode to trigger behavior tree execution when an action goal of the specified type ActionT is received. It creates an action server and manages the lifecycle of the action goal in coordination with the behavior tree execution.

Derived classes must implement:

Derived classes may optionally override:

Template Parameters
ActionTThe ROS 2 action type that triggers the behavior tree execution.

Definition at line 46 of file action_based_executor_node.hpp.

Constructor & Destructor Documentation

◆ ActionBasedTreeExecutorNode() [1/2]

template<typename ActionT>
ActionBasedTreeExecutorNode ( const std::string & name,
const std::string & action_name,
Options options )

Constructor.

Parameters
nameName of the rclcpp::Node.
action_nameName for the trigger action server.
optionsExecutor options.

Definition at line 144 of file action_based_executor_node.hpp.

◆ ActionBasedTreeExecutorNode() [2/2]

template<typename ActionT>
ActionBasedTreeExecutorNode ( const std::string & name,
const std::string & action_name,
rclcpp::NodeOptions ros_options = rclcpp::NodeOptions() )

Constructor with default options.

Parameters
nameName of the rclcpp::Node.
action_nameName for the trigger action server.
ros_optionsROS 2 node options.

Definition at line 156 of file action_based_executor_node.hpp.

Member Function Documentation

◆ getTreeConstructorFromGoal()

template<typename ActionT>
virtual TreeConstructor getTreeConstructorFromGoal ( std::shared_ptr< const TriggerGoal > goal_ptr)
protectedpure virtual

Create a TreeConstructor from the received action goal.

Derived classes must implement this to define how the action goal maps to a behavior tree execution. This is where the build request, entry point, and node manifest should be determined from the goal.

Parameters
goal_ptrShared pointer to the action goal.
Returns
Callback for creating the behavior tree.
Exceptions
std::exceptionif the goal cannot be processed (will cause goal rejection).

◆ shouldAcceptGoal()

template<typename ActionT>
bool shouldAcceptGoal ( const rclcpp_action::GoalUUID & uuid,
std::shared_ptr< const TriggerGoal > goal_ptr )
protectedvirtual

Determine whether an incoming trigger action goal should be accepted.

The default implementation rejects the goal if the executor is currently busy.

Parameters
uuidThe unique identifier of the incoming goal.
goal_ptrShared pointer to the incoming goal.
Returns
true if the goal should be accepted, false if it should be rejected.

Definition at line 163 of file action_based_executor_node.hpp.

◆ onAcceptedGoal()

template<typename ActionT>
void onAcceptedGoal ( std::shared_ptr< TriggerGoalHandle > goal_handle_ptr)
protectedvirtual

Hook called after a trigger action goal has been accepted and before execution begins.

Parameters
goal_handle_ptrShared pointer to the accepted goal handle.

Definition at line 176 of file action_based_executor_node.hpp.

◆ onExecutionStarted()

template<typename ActionT>
void onExecutionStarted ( std::shared_ptr< TriggerGoalHandle > goal_handle_ptr)
protectedvirtual

Hook called after execution has been started successfully.

The default implementation sets up the action context for tracking the execution result (attached mode). Derived classes may override this to implement detached behavior by succeeding the goal handle immediately.

Parameters
goal_handle_ptrShared pointer to the accepted goal handle.

Definition at line 181 of file action_based_executor_node.hpp.

◆ onGoalExecutionTermination()

template<typename ActionT>
void onGoalExecutionTermination ( const ExecutionResult & result,
TriggerActionContext & context )
protectedvirtual

Handle the execution result for the action client.

The default implementation succeeds for TREE_SUCCEEDED, aborts for TREE_FAILED, handles cancellation for TERMINATED_PREMATURELY, and aborts for ERROR.

Parameters
resultThe execution result.
contextThe action context for sending the result back.

Definition at line 188 of file action_based_executor_node.hpp.


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