staubli_driver_ros2 main
ROS2 control driver for Staubli robots
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
staubli_robot_driver::RealTimeSocketSubscriber< MessageType > Class Template Reference

Real-time socket subscriber class template. More...

#include <real_time_socket_subscriber.hpp>

Public Member Functions

 RealTimeSocketSubscriber (std::shared_ptr< Socket > socket)
 
virtual ~RealTimeSocketSubscriber ()
 
bool read_message (MessageType &msg, MessageStatus &status)
 Read the latest message and check for lost packages and staleness.
 
virtual bool is_ready () const
 Check if the subscriber is ready (socket connected and receiving)
 

Protected Member Functions

bool init_communication ()
 
void update_message (std::vector< uint8_t > &data, size_t bytes_transferred)
 
void handle_error (const std::string &error_msg)
 

Protected Attributes

std::shared_ptr< Socketsocket_
 
size_t last_read_sequence_number_
 Sequence number of the last read RobotStateMessage.
 
rclcpp::Logger logger_
 

Detailed Description

template<typename MessageType>
class staubli_robot_driver::RealTimeSocketSubscriber< MessageType >

Real-time socket subscriber class template.

Subscribes to messages of type MessageType over a socket. Handles message reception and status tracking in a thread-safe manner.

Template Parameters
MessageTypeType of message to subscribe to

Constructor & Destructor Documentation

◆ RealTimeSocketSubscriber()

template<typename MessageType >
staubli_robot_driver::RealTimeSocketSubscriber< MessageType >::RealTimeSocketSubscriber ( std::shared_ptr< Socket socket)
explicit

◆ ~RealTimeSocketSubscriber()

Member Function Documentation

◆ read_message()

Read the latest message and check for lost packages and staleness.

This method retrieves the most recent message received over the socket, along with its status information. It checks for lost packages based on sequence numbers and computes the time since the message was received (time of deserialization in async thread).

This method is thread-safe and can be called from real-time contexts. If no message AT ALL has been received yet, it returns false. If no message was received since last call, but one had arrived at some point before, the method returns true, but with the status.new_message field set to false.

In any case, the staleness of the message should be checked using the status.time_since_received field.

Parameters
msgReference to store the received message
statusReference to store the message status information
Returns
true if a message was received (at some point) and that the returned message is valid, false otherwise. Check status in any case...

◆ is_ready()

Check if the subscriber is ready (socket connected and receiving)

Returns
true if the subscriber is ready, false otherwise

Reimplemented in staubli_robot_driver::RealTimeSocketInterface< MessageSub, MessagePub >.

◆ init_communication()

template<typename MessageType >
bool staubli_robot_driver::RealTimeSocketSubscriber< MessageType >::init_communication ( )
protected

◆ update_message()

template<typename MessageType >
void staubli_robot_driver::RealTimeSocketSubscriber< MessageType >::update_message ( std::vector< uint8_t > &  data,
size_t  bytes_transferred 
)
protected

◆ handle_error()

template<typename MessageType >
void staubli_robot_driver::RealTimeSocketSubscriber< MessageType >::handle_error ( const std::string &  error_msg)
protected

Member Data Documentation

◆ socket_

template<typename MessageType >
std::shared_ptr<Socket> staubli_robot_driver::RealTimeSocketSubscriber< MessageType >::socket_
protected

◆ last_read_sequence_number_

template<typename MessageType >
size_t staubli_robot_driver::RealTimeSocketSubscriber< MessageType >::last_read_sequence_number_
protected

Sequence number of the last read RobotStateMessage.

◆ logger_

template<typename MessageType >
rclcpp::Logger staubli_robot_driver::RealTimeSocketSubscriber< MessageType >::logger_
protected

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