From 42d6034c1eafe03f56db42839ecd48094daaf668 Mon Sep 17 00:00:00 2001 From: Felix Exner Date: Tue, 1 Jul 2025 08:42:05 +0200 Subject: [PATCH 1/3] Add support for config structs in ReverseInterface and ScriptCommandSender --- .../control/reverse_interface.h | 16 ++++++++++++++++ .../control/script_command_interface.h | 8 ++++++++ src/control/reverse_interface.cpp | 12 +++++++++--- src/control/script_command_interface.cpp | 5 +++++ src/ur/ur_driver.cpp | 12 ++++++++++-- 5 files changed, 48 insertions(+), 5 deletions(-) diff --git a/include/ur_client_library/control/reverse_interface.h b/include/ur_client_library/control/reverse_interface.h index e68acd976..9ee952e26 100644 --- a/include/ur_client_library/control/reverse_interface.h +++ b/include/ur_client_library/control/reverse_interface.h @@ -34,6 +34,7 @@ #include "ur_client_library/types.h" #include "ur_client_library/log.h" #include "ur_client_library/ur/robot_receive_timeout.h" +#include "ur_client_library/ur/version_information.h" #include #include #include @@ -62,6 +63,17 @@ enum class FreedriveControlMessage : int32_t FREEDRIVE_START = 1, ///< Represents command to start freedrive mode. }; +struct ReverseInterfaceConfig +{ + uint32_t port = 50001; //!< Port the server is started on + std::function handle_program_state = [](bool) { + return; + }; //!< Function handle to a callback on program state changes. + std::chrono::milliseconds step_time = std::chrono::milliseconds(8); //!< The robots step time + uint32_t keepalive_count = 0; //!< Number of allowed timeout reads on the robot. + VersionInformation robot_software_version = VersionInformation(); //!< The robot software version. +}; + /*! * \brief The ReverseInterface class handles communication to the robot. It starts a server and * waits for the robot to connect via its URCaps program. @@ -82,6 +94,8 @@ class ReverseInterface ReverseInterface(uint32_t port, std::function handle_program_state, std::chrono::milliseconds step_time = std::chrono::milliseconds(8)); + ReverseInterface(const ReverseInterfaceConfig& config); + /*! * \brief Disconnects possible clients so the reverse interface object can be safely destroyed. */ @@ -167,6 +181,8 @@ class ReverseInterface socket_t client_fd_; comm::TCPServer server_; + VersionInformation robot_software_version_; + template size_t append(uint8_t* buffer, T& val) { diff --git a/include/ur_client_library/control/script_command_interface.h b/include/ur_client_library/control/script_command_interface.h index 2512c0247..3f240ac8f 100644 --- a/include/ur_client_library/control/script_command_interface.h +++ b/include/ur_client_library/control/script_command_interface.h @@ -63,6 +63,14 @@ class ScriptCommandInterface : public ReverseInterface */ ScriptCommandInterface(uint32_t port); + /*! + * \brief Creates a ScriptCommandInterface object, including a new TCPServer + * + * \param config Configuration for the ReverseInterface, including the port to start the server + * on. + */ + ScriptCommandInterface(const ReverseInterfaceConfig& config); + /*! * \brief Zero the force torque sensor * diff --git a/src/control/reverse_interface.cpp b/src/control/reverse_interface.cpp index 85c184599..ae65ff946 100644 --- a/src/control/reverse_interface.cpp +++ b/src/control/reverse_interface.cpp @@ -35,10 +35,16 @@ namespace control { ReverseInterface::ReverseInterface(uint32_t port, std::function handle_program_state, std::chrono::milliseconds step_time) + : ReverseInterface(ReverseInterfaceConfig{ port, handle_program_state, step_time }) +{ +} + +ReverseInterface::ReverseInterface(const ReverseInterfaceConfig& config) : client_fd_(INVALID_SOCKET) - , server_(port) - , handle_program_state_(handle_program_state) - , step_time_(step_time) + , server_(config.port) + , robot_software_version_(config.robot_software_version) + , handle_program_state_(config.handle_program_state) + , step_time_(config.step_time) , keep_alive_count_modified_deprecated_(false) { handle_program_state_(false); diff --git a/src/control/script_command_interface.cpp b/src/control/script_command_interface.cpp index ca2fb6d8e..6a1eba1cf 100644 --- a/src/control/script_command_interface.cpp +++ b/src/control/script_command_interface.cpp @@ -38,6 +38,11 @@ ScriptCommandInterface::ScriptCommandInterface(uint32_t port) : ReverseInterface client_connected_ = false; } +ScriptCommandInterface::ScriptCommandInterface(const ReverseInterfaceConfig& config) : ReverseInterface(config) +{ + client_connected_ = false; +} + bool ScriptCommandInterface::zeroFTSensor() { const int message_length = 1; diff --git a/src/ur/ur_driver.cpp b/src/ur/ur_driver.cpp index 6ba6aded2..ad4af76eb 100644 --- a/src/ur/ur_driver.cpp +++ b/src/ur/ur_driver.cpp @@ -89,7 +89,10 @@ void UrDriver::init(const UrDriverConfiguration& config) std::string local_ip = config.reverse_ip.empty() ? rtde_client_->getIP() : config.reverse_ip; trajectory_interface_.reset(new control::TrajectoryPointInterface(config.trajectory_port)); - script_command_interface_.reset(new control::ScriptCommandInterface(config.script_command_port)); + control::ReverseInterfaceConfig script_command_config; + script_command_config.port = config.script_command_port; + script_command_config.robot_software_version = rtde_client_->getVersion(); + script_command_interface_.reset(new control::ScriptCommandInterface(script_command_config)); startPrimaryClientCommunication(); @@ -622,7 +625,12 @@ void UrDriver::setupReverseInterface(const uint32_t reverse_port) { auto rtde_frequency = rtde_client_->getTargetFrequency(); auto step_time = std::chrono::milliseconds(static_cast(1000 / rtde_frequency)); - reverse_interface_.reset(new control::ReverseInterface(reverse_port, handle_program_state_, step_time)); + control::ReverseInterfaceConfig config; + config.step_time = step_time; + config.port = reverse_port; + config.handle_program_state = handle_program_state_; + config.robot_software_version = robot_version_; + reverse_interface_.reset(new control::ReverseInterface(config)); } void UrDriver::startPrimaryClientCommunication() From bb26b7450f61e5ba8049e1c6b5d5003eaa06b6df Mon Sep 17 00:00:00 2001 From: Felix Exner Date: Wed, 2 Jul 2025 09:38:14 +0200 Subject: [PATCH 2/3] Use the config-based constructor everywhere --- src/control/script_command_interface.cpp | 3 +-- src/control/trajectory_point_interface.cpp | 2 +- tests/test_reverse_interface.cpp | 6 ++++-- tests/test_script_command_interface.cpp | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/control/script_command_interface.cpp b/src/control/script_command_interface.cpp index 6a1eba1cf..d38933430 100644 --- a/src/control/script_command_interface.cpp +++ b/src/control/script_command_interface.cpp @@ -33,9 +33,8 @@ namespace urcl { namespace control { -ScriptCommandInterface::ScriptCommandInterface(uint32_t port) : ReverseInterface(port, [](bool foo) { return foo; }) +ScriptCommandInterface::ScriptCommandInterface(uint32_t port) : ScriptCommandInterface(ReverseInterfaceConfig{ port }) { - client_connected_ = false; } ScriptCommandInterface::ScriptCommandInterface(const ReverseInterfaceConfig& config) : ReverseInterface(config) diff --git a/src/control/trajectory_point_interface.cpp b/src/control/trajectory_point_interface.cpp index 2b8f2aea5..85c6221bc 100644 --- a/src/control/trajectory_point_interface.cpp +++ b/src/control/trajectory_point_interface.cpp @@ -56,7 +56,7 @@ std::string trajectoryResultToString(const TrajectoryResult result) } } -TrajectoryPointInterface::TrajectoryPointInterface(uint32_t port) : ReverseInterface(port, [](bool foo) { return foo; }) +TrajectoryPointInterface::TrajectoryPointInterface(uint32_t port) : ReverseInterface(ReverseInterfaceConfig{ port }) { } diff --git a/tests/test_reverse_interface.cpp b/tests/test_reverse_interface.cpp index 73466cfde..3674b7556 100644 --- a/tests/test_reverse_interface.cpp +++ b/tests/test_reverse_interface.cpp @@ -150,8 +150,10 @@ class ReverseIntefaceTest : public ::testing::Test void SetUp() { - reverse_interface_.reset(new control::ReverseInterface( - 50001, std::bind(&ReverseIntefaceTest::handleProgramState, this, std::placeholders::_1))); + control::ReverseInterfaceConfig config; + config.port = 50001; + config.handle_program_state = std::bind(&ReverseIntefaceTest::handleProgramState, this, std::placeholders::_1); + reverse_interface_.reset(new control::ReverseInterface(config)); client_.reset(new Client(50001)); } diff --git a/tests/test_script_command_interface.cpp b/tests/test_script_command_interface.cpp index 86901dc7a..abe395096 100644 --- a/tests/test_script_command_interface.cpp +++ b/tests/test_script_command_interface.cpp @@ -102,7 +102,7 @@ class ScriptCommandInterfaceTest : public ::testing::Test void SetUp() { - script_command_interface_.reset(new control::ScriptCommandInterface(50004)); + script_command_interface_.reset(new control::ScriptCommandInterface(control::ReverseInterfaceConfig{ 50004 })); client_.reset(new Client(50004)); } From bc56aa4eac1bcdef4aa9407c8c79b863bb82a603 Mon Sep 17 00:00:00 2001 From: Felix Exner Date: Wed, 2 Jul 2025 09:41:11 +0200 Subject: [PATCH 3/3] Add deprecation notices --- include/ur_client_library/control/reverse_interface.h | 1 + include/ur_client_library/control/script_command_interface.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/ur_client_library/control/reverse_interface.h b/include/ur_client_library/control/reverse_interface.h index 9ee952e26..dbfb407e2 100644 --- a/include/ur_client_library/control/reverse_interface.h +++ b/include/ur_client_library/control/reverse_interface.h @@ -91,6 +91,7 @@ class ReverseInterface * \param handle_program_state Function handle to a callback on program state changes. * \param step_time The robots step time */ + [[deprecated("Use ReverseInterfaceConfig instead of port, handle_program_state and step_time parameters")]] ReverseInterface(uint32_t port, std::function handle_program_state, std::chrono::milliseconds step_time = std::chrono::milliseconds(8)); diff --git a/include/ur_client_library/control/script_command_interface.h b/include/ur_client_library/control/script_command_interface.h index 3f240ac8f..9c15d49dd 100644 --- a/include/ur_client_library/control/script_command_interface.h +++ b/include/ur_client_library/control/script_command_interface.h @@ -61,6 +61,7 @@ class ScriptCommandInterface : public ReverseInterface * * \param port Port to start the server on */ + [[deprecated("Use ReverseInterfaceConfig instead of port, handle_program_state and step_time parameters")]] ScriptCommandInterface(uint32_t port); /*! @@ -203,4 +204,4 @@ class ScriptCommandInterface : public ReverseInterface } // namespace control } // namespace urcl -#endif // UR_CLIENT_LIBRARY_SCRIPT_COMMAND_INTERFACE_H_INCLUDED \ No newline at end of file +#endif // UR_CLIENT_LIBRARY_SCRIPT_COMMAND_INTERFACE_H_INCLUDED