mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
mrs_lib::DynamicPublisher Class Reference

A helper class for easy publishing of ROS messages for debugging purposes. More...

#include <dynamic_publisher.h>

Public Member Functions

 DynamicPublisher ()
 A no-parameter constructor. More...
 
 DynamicPublisher (const ros::NodeHandle &nh)
 The main constructor. More...
 
template<class T >
void publish (const std::string name, const T &msg)
 Publishes a message to a topic, advertising the topic if necessary. More...
 

Detailed Description

A helper class for easy publishing of ROS messages for debugging purposes.

This class enables you to just call the publish() method with a topic name and a message without the need to advertise the topic.

Note
This class should only be used for debugging and not for regular publishing as it introduces some overhead.
Examples
dynamic_publisher/example.cpp.

Constructor & Destructor Documentation

◆ DynamicPublisher() [1/2]

mrs_lib::DynamicPublisher::DynamicPublisher ( )

A no-parameter constructor.

This overload will use a ros::NodeHandle with default arguments for advertising new topics, so remappings, namespaces etc. will be ignored.

◆ DynamicPublisher() [2/2]

mrs_lib::DynamicPublisher::DynamicPublisher ( const ros::NodeHandle &  nh)

The main constructor.

This overload uses the ros::NodeHandle that you provided for advertising new topics. The recommended way of constructing a DynamicPublisher.

Member Function Documentation

◆ publish()

template<class T >
void mrs_lib::DynamicPublisher::publish ( const std::string  name,
const T &  msg 
)

Publishes a message to a topic, advertising the topic if necessary.

The topic is advertised with the type of the first message published to it. If you try to publish a different type of message on the topic, it will be ignored.

Warning
Take care to always publish the same message type to the topic to avoid being spammed with errors.
Examples
dynamic_publisher/example.cpp.

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