staubli_driver_ros2 main
ROS2 control driver for Staubli robots
Loading...
Searching...
No Matches
real_time_socket_subscriber.hpp
Go to the documentation of this file.
1// Copyright 2025 ICUBE Laboratory, University of Strasbourg
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Author: Thibault Poignonec (thibault.poignonec@gmail.fr)
16
17#ifndef STAUBLI_ROBOT_DRIVER__REAL_TIME_SOCKET_SUBSCRIBER_HPP_
18#define STAUBLI_ROBOT_DRIVER__REAL_TIME_SOCKET_SUBSCRIBER_HPP_
19
20// C++
21#include <atomic>
22#include <cstdint>
23#include <chrono>
24#include <functional>
25#include <memory>
26#include <string>
27#include <vector>
28
29// ROS2
30#include <rclcpp/duration.hpp>
31#include <rclcpp/logging.hpp>
32#include <rclcpp/time.hpp>
33
34// Realtime tools (ROS2 package)
35#include <realtime_tools/realtime_thread_safe_box.hpp>
36
37// Staubli Robot Driver
41
42namespace staubli_robot_driver {
43
49 rclcpp::Duration time_since_received{1, 0};
52};
53
62template <typename MessageType>
64public:
65 explicit RealTimeSocketSubscriber(std::shared_ptr<Socket> socket);
67
68 // Read the latest message and check for lost packages and staleness
69
93
98 virtual bool is_ready() const;
99
100protected:
101 // Communication initialization
103
104 // Update the message buffer with a new message
105 void update_message(std::vector<uint8_t>& data, size_t bytes_transferred);
106
107 // Error handling
108 void handle_error(const std::string& error_msg);
109
110protected:
111 std::shared_ptr<Socket> socket_;
114
115 rclcpp::Logger logger_;
116
117private:
118 realtime_tools::RealtimeThreadSafeBox<MessageType> message_buffer_;
119 bool first_read_; // Flag to indicate if it's the first read
120};
121
122// Declarations for message types
126
127} // namespace staubli_robot_driver
128
129#endif // STAUBLI_ROBOT_DRIVER__REAL_TIME_SOCKET_SUBSCRIBER_HPP_
Bilateral real-time socket interface for pub/sub communication.
Definition real_time_socket_interface.hpp:39
Real-time socket subscriber class template.
Definition real_time_socket_subscriber.hpp:63
virtual bool is_ready() const
Check if the subscriber is ready (socket connected and receiving)
std::shared_ptr< Socket > socket_
Definition real_time_socket_subscriber.hpp:111
rclcpp::Logger logger_
Definition real_time_socket_subscriber.hpp:115
void update_message(std::vector< uint8_t > &data, size_t bytes_transferred)
size_t last_read_sequence_number_
Sequence number of the last read RobotStateMessage.
Definition real_time_socket_subscriber.hpp:113
RealTimeSocketSubscriber(std::shared_ptr< Socket > socket)
void handle_error(const std::string &error_msg)
bool read_message(MessageType &msg, MessageStatus &status)
Read the latest message and check for lost packages and staleness.
Definition messages.hpp:23
MessageType
Message types for communication.
Definition types.hpp:25
Status struct to hold message status information.
Definition real_time_socket_subscriber.hpp:45
size_t lost_packages
Number of lost packages (0 if none)
Definition real_time_socket_subscriber.hpp:51
bool new_message
True if a new message was received.
Definition real_time_socket_subscriber.hpp:47
rclcpp::Duration time_since_received
Time since the message was received (see msg.reception_timestamp)
Definition real_time_socket_subscriber.hpp:49