From 6cb1cdcc50829aba7492923d4f2ed6234c93c76d Mon Sep 17 00:00:00 2001 From: "Felix Exner (fexner)" Date: Mon, 21 Oct 2024 18:08:30 +0200 Subject: [PATCH] Fix component lifecycle (#1098) * Correctly reset async_thread_shutdown when starting the async thread * Do not use a global log handler object --------- (cherry picked from commit 141a17ac4380f3e26c3cfb87512922f72b86a57d) --- .../include/ur_robot_driver/hardware_interface.hpp | 2 +- ur_robot_driver/src/hardware_interface.cpp | 1 + ur_robot_driver/src/urcl_log_handler.cpp | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ur_robot_driver/include/ur_robot_driver/hardware_interface.hpp b/ur_robot_driver/include/ur_robot_driver/hardware_interface.hpp index 6fc227766..f7167e793 100644 --- a/ur_robot_driver/include/ur_robot_driver/hardware_interface.hpp +++ b/ur_robot_driver/include/ur_robot_driver/hardware_interface.hpp @@ -190,7 +190,7 @@ class URPositionHardwareInterface : public hardware_interface::SystemInterface bool first_pass_; bool initialized_; double system_interface_initialized_; - bool async_thread_shutdown_; + std::atomic_bool async_thread_shutdown_; double get_robot_software_version_major_; double get_robot_software_version_minor_; double get_robot_software_version_bugfix_; diff --git a/ur_robot_driver/src/hardware_interface.cpp b/ur_robot_driver/src/hardware_interface.cpp index b682bfd9b..2852df1b4 100644 --- a/ur_robot_driver/src/hardware_interface.cpp +++ b/ur_robot_driver/src/hardware_interface.cpp @@ -532,6 +532,7 @@ void URPositionHardwareInterface::readBitsetData(const std::unique_ptr g_log_handler(new UrclLogHandler); UrclLogHandler::UrclLogHandler() = default; @@ -82,10 +81,11 @@ void UrclLogHandler::log(const char* file, int line, urcl::LogLevel loglevel, co void registerUrclLogHandler(const std::string& tf_prefix) { if (g_registered == false) { - g_log_handler->setTFPrefix(tf_prefix); + std::unique_ptr log_handler(new UrclLogHandler); + log_handler->setTFPrefix(tf_prefix); // Log level is decided by ROS2 log level urcl::setLogLevel(urcl::LogLevel::DEBUG); - urcl::registerLogHandler(std::move(g_log_handler)); + urcl::registerLogHandler(std::move(log_handler)); g_registered = true; } }