staubli_driver_ros2 main
ROS2 control driver for Staubli robots
Loading...
Searching...
No Matches
robot_driver.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
18#ifndef STAUBLI_ROBOT_DRIVER__ROBOT_DRIVER_HPP_
19#define STAUBLI_ROBOT_DRIVER__ROBOT_DRIVER_HPP_
20
21// C++
22#include <atomic>
23#include <chrono>
24#include <condition_variable>
25#include <memory>
26#include <mutex>
27#include <string>
28#include <vector>
29
30// Staubli Robot Driver
33
34namespace staubli_robot_driver {
35
43public:
59
60public:
65
70
77 bool connect(const std::string& robot_ip, int timeout_ms);
78
85 bool connect(const NetworkConfig& config, int timeout_ms = 5000);
86
91 bool disconnect();
92
97 bool is_connected() const;
98
104
112
125
132
139 rclcpp::Duration staleness_timeout = rclcpp::Duration(0, 1e8));
140
147 rclcpp::Duration staleness_timeout = rclcpp::Duration(0, 1e8));
148
154 return last_valid_sequence_id_;
155 }
156
157protected:
158 // Helper methods
160 bool is_state_msg_valid() const;
162
163private:
164 // Logger
165 rclcpp::Logger logger_;
166
167 // Sockets
168 NetworkConfig network_config_;
169 std::shared_ptr<Socket> control_socket_;
170 std::shared_ptr<Socket> diagnostics_socket_;
171
172 // Communication interfaces
173 std::shared_ptr<
175 std::shared_ptr<
177
178 // State tracking
179 size_t last_valid_sequence_id_ = 0;
180 RobotStateMessage current_robot_state_;
181 DiagnosticDataMessage current_diagnostic_data_;
182
183 // Staleness timeouts
184 rclcpp::Duration state_staleness_timeout_;
185 rclcpp::Duration diagnostic_staleness_timeout_;
186};
187
188} // namespace staubli_robot_driver
189
190#endif // STAUBLI_ROBOT_DRIVER__ROBOT_DRIVER_HPP_
Diagnostic data.
Definition messages.hpp:191
Bilateral real-time socket interface for pub/sub communication.
Definition real_time_socket_interface.hpp:39
Robot command message.
Definition messages.hpp:139
Main interface for controlling Staubli robots.
Definition robot_driver.hpp:42
bool is_connected() const
Check if connected to the robot (does not check for message staleness)
bool send_stop_all_command()
Send a STOP command to the robot (halts motion and sets IOs to zero)
bool disconnect()
Disconnect from the robot.
bool connect(const NetworkConfig &config, int timeout_ms=5000)
Connect to the robot with a specific network configuration.
bool send_robot_command(const RobotCommandMessage &command)
Send a command to the robot.
void set_state_staleness_timeout(rclcpp::Duration staleness_timeout=rclcpp::Duration(0, 1e8))
Set the staleness timeout after which the robot state is considered stale.
void set_diagnostic_staleness_timeout(rclcpp::Duration staleness_timeout=rclcpp::Duration(0, 1e8))
Set the staleness timeout after which the diagnostic data is considered stale.
size_t get_current_message_sequence() const
Get the sequence ID of the last valid received robot state message.
Definition robot_driver.hpp:153
bool connect(const std::string &robot_ip, int timeout_ms)
Connect to the robot with the default network configuration.
bool read_diagnostic_data(DiagnosticDataMessage &data)
Get the latest diagnostic data, see update_robot_state() for notes.
bool read_robot_state(RobotStateMessage &state)
Get the current (latest) robot state.
Robot state message.
Definition messages.hpp:62
Definition messages.hpp:23
constexpr uint16_t DEFAULT_CONTROL_PORT
Default port for the control socket.
Definition protocol.hpp:45
constexpr uint16_t DEFAULT_DIAGNOSTICS_PORT
Default port for the diagnostics socket.
Definition protocol.hpp:50
Configuration structure for the communication.
Definition robot_driver.hpp:45
uint16_t local_diagnostics_port
Port for diagnostics communication on ROS2 side.
Definition robot_driver.hpp:57
uint16_t local_control_port
Port for control communication on ROS2 side.
Definition robot_driver.hpp:53
std::string local_ip
Local IP address to bind to (empty string binds to any interface)
Definition robot_driver.hpp:49
uint16_t diagnostics_port
Port for diagnostics communication on the robot.
Definition robot_driver.hpp:55
std::string robot_ip
IP address of the Staubli robot.
Definition robot_driver.hpp:47
uint16_t control_port
Port for control communication on the robot.
Definition robot_driver.hpp:51