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

Common state and node-manifest support shared by the ROS-aware behavior tree node base classes. More...

#include <auto_apms_behavior_tree_core/node/base/ros_node_base.hpp>

Inheritance diagram for RosNodeBase:

Protected Member Functions

void applyPortAliasing (const BT::TreeNode *node) const
 Support the node manifest 'port_alias' feature: copy the aliased port values onto the original ports the node implementation reads.
 
template<typename InstanceT>
std::shared_ptr< InstanceT > getSharedEntity (const std::string &entity_name, const std::function< std::shared_ptr< InstanceT >()> &factory)
 Retrieve a process-wide shared ROS 2 entity, creating it via factory on first use.
 

Detailed Description

Common state and node-manifest support shared by the ROS-aware behavior tree node base classes.

This is a plain (non-BT::TreeNode) mixin that holds the RosNodeContext and a per-instance logger. It exists so the ROS-aware wrappers around the basic BehaviorTree.CPP node types (RosSyncActionNode, RosStatefulActionNode, RosConditionNode, RosDecoratorNode, RosControlNode) share identical construction logic instead of duplicating it.

Applying the node-manifest port aliasing is triggered by the derived node itself via applyPortAliasing(); the wrappers call it from their constructor once the node is fully constructed.

It additionally provides getSharedEntity(), the shared-entity registry used by the provided ROS node bases (RosPublisherNode, RosSubscriberNode, RosServiceNode, RosActionNode) and available to any downstream node so that equivalent ROS 2 entities (publishers, subscriptions, clients, ...) are created once and shared instead of being duplicated per tree node instance.

Definition at line 45 of file ros_node_base.hpp.

Member Function Documentation

◆ applyPortAliasing()

void applyPortAliasing ( const BT::TreeNode * node) const
protected

Support the node manifest 'port_alias' feature: copy the aliased port values onto the original ports the node implementation reads.

Must be called by the derived (BT::TreeNode) node from its constructor.

Parameters
nodeThe tree node instance (usually this).

Definition at line 27 of file ros_node_base.cpp.

◆ getSharedEntity()

template<typename InstanceT>
std::shared_ptr< InstanceT > getSharedEntity ( const std::string & entity_name,
const std::function< std::shared_ptr< InstanceT >()> & factory )
protected

Retrieve a process-wide shared ROS 2 entity, creating it via factory on first use.

Behavior tree nodes are frequently instantiated multiple times (e.g. the same topic used by several nodes in a tree). To avoid creating one ROS 2 entity - publisher, subscription, service/action client, or any wrapper thereof

  • per node instance, entities are shared through a registry keyed by the owning ROS 2 node's fully qualified name and entity_name. The first caller for a given key creates the instance via factory; subsequent callers receive the same instance for as long as it is still held by at least one node. Once the last owner is destroyed, the entry expires and the next caller creates a fresh instance.

A distinct registry is kept per InstanceT, so different entity types never collide even if they share a name.

Template Parameters
InstanceTType wrapping (or being) the shared ROS 2 entity.
Parameters
entity_nameName identifying the entity (e.g. the topic/service/action name) used to form the registry key.
factoryCallable creating a new instance; only invoked when no live instance exists for the key.
Returns
Shared pointer to the (possibly newly created) shared instance.

Definition at line 92 of file ros_node_base.hpp.


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