ros2_control - rolling
Loading...
Searching...
No Matches
realtime_tools::RealtimePublisher< MessageT > Class Template Reference

Public Types

using PublisherType = rclcpp::Publisher<MessageT>
 Provide various typedefs to resemble the rclcpp::Publisher type.
using PublisherSharedPtr = typename rclcpp::Publisher<MessageT>::SharedPtr
using PublishedType = typename rclcpp::TypeAdapter<MessageT>::custom_type
using ROSMessageType = typename rclcpp::TypeAdapter<MessageT>::ros_message_type

Public Member Functions

template<typename NodeT>
 RealtimePublisher (NodeT &&node, const std::string &topic_name, const rclcpp::QoS &qos, const rclcpp::PublisherOptions &options=rclcpp::PublisherOptions())
 Constructor for the realtime publisher that creates the publisher internally.
 RealtimePublisher (PublisherSharedPtr publisher)
 Constructor for the realtime publisher.
 ~RealtimePublisher ()
 Destructor.
void stop ()
 Stop the realtime publisher.
bool can_publish () const
 Check if the realtime publisher is in a state to publish messages.
bool try_publish (const MessageT &msg)
 Try to publish the given message.
std::thread & get_thread ()
 Get the thread object for the publishing thread.
const std::thread & get_thread () const
 Get the thread object for the publishing thread.
std::mutex & get_mutex ()
 Get the mutex protecting the stored message.
const std::mutex & get_mutex () const
 Get the mutex protecting the stored message.

Constructor & Destructor Documentation

◆ RealtimePublisher() [1/2]

template<class MessageT>
template<typename NodeT>
realtime_tools::RealtimePublisher< MessageT >::RealtimePublisher ( NodeT && node,
const std::string & topic_name,
const rclcpp::QoS & qos,
const rclcpp::PublisherOptions & options = rclcpp::PublisherOptions() )
inlineexplicit

Constructor for the realtime publisher that creates the publisher internally.

Starts a dedicated thread for message publishing. The publishing thread runs the publishingLoop() function to handle message delivery in a non-realtime context.

Parameters
nodethe node (or node interface/pointer) to create the publisher for
topic_namethe topic name on which we want to publish
qosthe QoS settings for the publisher
optionsthe publisher options

◆ RealtimePublisher() [2/2]

template<class MessageT>
realtime_tools::RealtimePublisher< MessageT >::RealtimePublisher ( PublisherSharedPtr publisher)
inlineexplicit

Constructor for the realtime publisher.

Starts a dedicated thread for message publishing. The publishing thread runs the publishingLoop() function to handle message delivery in a non-realtime context.

Parameters
publisherthe ROS publisher to wrap

Member Function Documentation

◆ can_publish()

template<class MessageT>
bool realtime_tools::RealtimePublisher< MessageT >::can_publish ( ) const
inline

Check if the realtime publisher is in a state to publish messages.

Returns
true if the publisher is in a state to publish messages

◆ get_thread() [1/2]

template<class MessageT>
std::thread & realtime_tools::RealtimePublisher< MessageT >::get_thread ( )
inline

Get the thread object for the publishing thread.

This can be used to set thread properties.

◆ get_thread() [2/2]

template<class MessageT>
const std::thread & realtime_tools::RealtimePublisher< MessageT >::get_thread ( ) const
inline

Get the thread object for the publishing thread.

This can be used to set thread properties.

◆ stop()

template<class MessageT>
void realtime_tools::RealtimePublisher< MessageT >::stop ( )
inline

Stop the realtime publisher.

Signals the publishing thread to exit by setting keep_running_ to false and notifying the condition variable. This allows the publishing loop to break out of its wait state and exit cleanly.

◆ try_publish()

template<class MessageT>
bool realtime_tools::RealtimePublisher< MessageT >::try_publish ( const MessageT & msg)
inline

Try to publish the given message.

This method attempts to publish the given message if the publisher is in a state to do so. It uses a try_lock to avoid blocking if the mutex is already held by another thread.

Parameters
[in]msgThe message to publish
Returns
true if the message was successfully published, false otherwise

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