AutoAPMS
Resilient Robot Mission Management
Loading...
Searching...
No Matches
RosPublisherNode< MessageT > Class Template Reference

Generic behavior tree node wrapper for a ROS 2 publisher. More...

#include <auto_apms_behavior_tree_core/node/ros_publisher_node.hpp>

Public Member Functions

 RosPublisherNode (const std::string &instance_name, const Config &config, Context context, const rclcpp::QoS &qos={10})
 Constructor.
 
virtual bool setMessage (MessageT &msg)
 Callback invoked when ticked to define the message to be published.
 
bool createPublisher (const std::string &topic_name)
 Create the ROS 2 publisher.
 
std::string getTopicName () const
 Get the name of the topic name this node publishes to.
 

Static Public Member Functions

static BT::PortsList providedBasicPorts (BT::PortsList addition)
 Derived nodes implementing the static method RosPublisherNode::providedPorts may call this method to also include the default port for ROS 2 behavior tree nodes.
 
static BT::PortsList providedPorts ()
 If a behavior tree requires input/output data ports, the developer must define this method accordingly.
 

Detailed Description

template<class MessageT>
class auto_apms_behavior_tree::core::RosPublisherNode< MessageT >

Generic behavior tree node wrapper for a ROS 2 publisher.

When ticked, this node publishes a single message to a topic. Inheriting classes must reimplement the virtual methods as described below.

By default, the name of the topic will be determined as follows:

  1. If a value is passed using the input port named port, use that.
  2. Otherwise, use the value from NodeRegistrationOptions::port passed on construction as part of RosNodeContext.

It is possible to customize which port is used to determine the topic name and also extend the input's value with a prefix or suffix. This is achieved by including the special pattern (input:<port_name>) in NodeRegistrationOptions::port and replacing <port_name> with the desired input port name.

Example: Given the user implements an input port BT::InputPort<std::string>("my_port"), one may create a client for the topic "foo/bar" by defining NodeRegistrationOptions::port as (input:my_port)/bar and providing the string "foo" to the port with name my_port.

Additionally, the following characteristics depend on NodeRegistrationOptions:

  • logger_level: Minimum severity level enabled for logging using the ROS 2 Logger API.
Template Parameters
MessageTType of the ROS 2 message.

Definition at line 57 of file ros_publisher_node.hpp.

Constructor & Destructor Documentation

◆ RosPublisherNode()

template<class MessageT>
RosPublisherNode ( const std::string & instance_name,
const Config & config,
Context context,
const rclcpp::QoS & qos = {10} )
inlineexplicit

Constructor.

Derived nodes are automatically created by TreeBuilder::instantiate when included inside a node manifest associated with the behavior tree resource.

Parameters
instance_nameName given to this specific node instance.
configStructure of internal data determined at runtime by BT::BehaviorTreeFactory.
contextAdditional parameters specific to ROS 2 determined at runtime by TreeBuilder.
qosQuality of service settings forwarded to the publisher.

Definition at line 144 of file ros_publisher_node.hpp.

Member Function Documentation

◆ providedBasicPorts()

template<class MessageT>
static BT::PortsList providedBasicPorts ( BT::PortsList addition)
inlinestatic

Derived nodes implementing the static method RosPublisherNode::providedPorts may call this method to also include the default port for ROS 2 behavior tree nodes.

Parameters
additionAdditional ports to add to the ports list.
Returns
List of ports containing the default port along with node-specific ports.

Definition at line 88 of file ros_publisher_node.hpp.

◆ providedPorts()

template<class MessageT>
static BT::PortsList providedPorts ( )
inlinestatic

If a behavior tree requires input/output data ports, the developer must define this method accordingly.

Returns
List of ports used by this node.

Definition at line 99 of file ros_publisher_node.hpp.

◆ setMessage()

template<class MessageT>
bool setMessage ( MessageT & msg)
inlinevirtual

Callback invoked when ticked to define the message to be published.

The node may deny to publish a message by returning false. Otherwise, this method should return true.

By default, this callback simply returns true and sends an empty message.

Parameters
msgReference to the message.
Returns
false if no message should be published. In that case, the return status of this node will be BT::NodeStatus::FAILURE. Otherwise, the message will be published and the node returns BT::NodeStatus::SUCCESS.

Definition at line 232 of file ros_publisher_node.hpp.

◆ createPublisher()

template<class MessageT>
bool createPublisher ( const std::string & topic_name)
inline

Create the ROS 2 publisher.

Parameters
topic_nameName of the topic.
Returns
true if the publisher was created successfully, false otherwise.

Definition at line 162 of file ros_publisher_node.hpp.

◆ getTopicName()

template<class MessageT>
std::string getTopicName ( ) const
inline

Get the name of the topic name this node publishes to.

Returns
String representing the topic name.

Definition at line 238 of file ros_publisher_node.hpp.


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