AutoAPMS
Streamlining behaviors in ROS 2
Loading...
Searching...
No Matches
RosNodeContext Class Reference

Additional parameters specific to ROS 2 determined at runtime by TreeBuilder. More...

#include <auto_apms_behavior_tree_core/node/ros_node_context.hpp>

Public Member Functions

 RosNodeContext (rclcpp::Node::SharedPtr ros_node, rclcpp::CallbackGroup::SharedPtr tree_node_waitables_callback_group, rclcpp::executors::SingleThreadedExecutor::SharedPtr tree_node_waitables_executor, const NodeRegistrationOptions &options)
 Constructor.
 
std::string getROSNodeName () const
 Get the name of the ROS 2 node passed to the constructor.
 
std::string getFullyQualifiedRosNodeName () const
 Get the fully qualified name of the ROS 2 node passed to the constructor.
 
rclcpp::Logger getBaseLogger () const
 Get the logger of the associated ROS 2 node.
 
rclcpp::Logger getChildLogger (const std::string &name)
 Get a child logger created using the associated ROS 2 node.
 
rclcpp::Time getCurrentTime () const
 Get the current time using the associated ROS 2 node.
 
std::string getFullyQualifiedTreeNodeName (const BT::TreeNode *node, bool with_class_name=true) const
 Create a string representing the detailed name of a behavior tree node.
 
YAML::Node getExtraOptions () const
 Get the extra YAML options provided during node registration.
 
rclcpp::Node::SharedPtr getRosNode () const
 Get the associated ROS 2 node handle.
 
rclcpp::CallbackGroup::SharedPtr getWaitablesCallbackGroup () const
 Get the callback group to use when adding ROS 2 waitables (subscriptions, clients, ...) from a tree node.
 
rclcpp::executors::SingleThreadedExecutor::SharedPtr getWaitablesExecutor () const
 Get the executor used for spinning the tree node's waitables.
 
BT::Expected< std::string > getTopicName (const BT::TreeNode *node) const
 Resolve the ROS 2 topic name from the node's registration options (node manifest 'topic' feature), applying any (input:port) substitutions.
 
const NodeRegistrationOptionsgetRegistrationOptions () const
 Get the node registration options.
 

Detailed Description

Additional parameters specific to ROS 2 determined at runtime by TreeBuilder.

Definition at line 30 of file ros_node_context.hpp.

Constructor & Destructor Documentation

◆ RosNodeContext()

RosNodeContext ( rclcpp::Node::SharedPtr ros_node,
rclcpp::CallbackGroup::SharedPtr tree_node_waitables_callback_group,
rclcpp::executors::SingleThreadedExecutor::SharedPtr tree_node_waitables_executor,
const NodeRegistrationOptions & options )

Constructor.

Parameters
[in]ros_nodeROS 2 node instance used for adding waitables with.
[in]tree_node_waitables_callback_groupCallback group to be used within tree nodes when adding waitables.
[in]tree_node_waitables_executorExecutor used for executing work provided by the node's waitables.
[in]optionsConfiguration options for registering the behavior tree node.

Definition at line 25 of file ros_node_context.cpp.

Member Function Documentation

◆ getROSNodeName()

std::string getROSNodeName ( ) const

Get the name of the ROS 2 node passed to the constructor.

Returns
Name of the associated ROS 2 node.

Definition at line 39 of file ros_node_context.cpp.

◆ getFullyQualifiedRosNodeName()

std::string getFullyQualifiedRosNodeName ( ) const

Get the fully qualified name of the ROS 2 node passed to the constructor.

Returns
Fully qualified name of the associated ROS 2 node.

Definition at line 41 of file ros_node_context.cpp.

◆ getBaseLogger()

rclcpp::Logger getBaseLogger ( ) const

Get the logger of the associated ROS 2 node.

Returns
Logger instance.

Definition at line 43 of file ros_node_context.cpp.

◆ getChildLogger()

rclcpp::Logger getChildLogger ( const std::string & name)

Get a child logger created using the associated ROS 2 node.

Parameters
nameName of the new logger.
Returns
Logger instance.

Definition at line 45 of file ros_node_context.cpp.

◆ getCurrentTime()

rclcpp::Time getCurrentTime ( ) const

Get the current time using the associated ROS 2 node.

Returns
Current time.

Definition at line 60 of file ros_node_context.cpp.

◆ getFullyQualifiedTreeNodeName()

std::string getFullyQualifiedTreeNodeName ( const BT::TreeNode * node,
bool with_class_name = true ) const

Create a string representing the detailed name of a behavior tree node.

Parameters
nodePointer to the behavior tree node instance.
with_class_nameWhether to include the name of the behavior tree node class.
Returns
Fully qualified name of node.

Definition at line 68 of file ros_node_context.cpp.

◆ getExtraOptions()

YAML::Node getExtraOptions ( ) const

Get the extra YAML options provided during node registration.

Returns
YAML node with extra options.

Definition at line 83 of file ros_node_context.cpp.

◆ getRosNode()

rclcpp::Node::SharedPtr getRosNode ( ) const

Get the associated ROS 2 node handle.

Allows custom tree nodes (e.g. a StatefulActionNode that must both publish and subscribe) to create their own ROS 2 entities. Prefer the dedicated node base classes (RosPublisherNode, ...) where they suffice.

Returns
Shared pointer to the ROS 2 node.
Exceptions
auto_apms_behavior_tree::core::exceptions::RosNodeErrorif the node handle has expired.

Definition at line 85 of file ros_node_context.cpp.

◆ getWaitablesCallbackGroup()

rclcpp::CallbackGroup::SharedPtr getWaitablesCallbackGroup ( ) const

Get the callback group to use when adding ROS 2 waitables (subscriptions, clients, ...) from a tree node.

Returns
Shared pointer to the callback group, or nullptr if it has expired (add to the node's default group then).

Definition at line 96 of file ros_node_context.cpp.

◆ getWaitablesExecutor()

rclcpp::executors::SingleThreadedExecutor::SharedPtr getWaitablesExecutor ( ) const

Get the executor used for spinning the tree node's waitables.

Returns
Shared pointer to the executor, or nullptr if it has expired.

Definition at line 98 of file ros_node_context.cpp.

◆ getTopicName()

BT::Expected< std::string > getTopicName ( const BT::TreeNode * node) const

Resolve the ROS 2 topic name from the node's registration options (node manifest 'topic' feature), applying any (input:port) substitutions.

Exposed so custom tree nodes that are not derived from the provided node base classes can still honor a manifest-configured topic exactly like RosPublisherNode/RosSubscriberNode do.

Parameters
nodePointer to the behavior tree node instance.
Returns
The resolved topic name, or an error if the 'topic' option is empty or a referenced input port is unset.

Definition at line 105 of file ros_node_context.cpp.

◆ getRegistrationOptions()

const NodeRegistrationOptions & getRegistrationOptions ( ) const

Get the node registration options.

Returns
Const reference to the registration options.

Definition at line 103 of file ros_node_context.cpp.


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