Skip to content

Commit 506c612

Browse files
authored
Fix component lifecycle (backport of #1098)
* Correctly reset async_thread_shutdown when starting the async thread * Do not use a global log handler object
1 parent 9c33a93 commit 506c612

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

ur_robot_driver/include/ur_robot_driver/hardware_interface.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class URPositionHardwareInterface : public hardware_interface::SystemInterface
190190
bool first_pass_;
191191
bool initialized_;
192192
double system_interface_initialized_;
193-
bool async_thread_shutdown_;
193+
std::atomic_bool async_thread_shutdown_;
194194
double get_robot_software_version_major_;
195195
double get_robot_software_version_minor_;
196196
double get_robot_software_version_bugfix_;

ur_robot_driver/src/hardware_interface.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ void URPositionHardwareInterface::readBitsetData(const std::unique_ptr<rtde::Dat
532532

533533
void URPositionHardwareInterface::asyncThread()
534534
{
535+
async_thread_shutdown_ = false;
535536
while (!async_thread_shutdown_) {
536537
if (initialized_) {
537538
// RCLCPP_INFO(rclcpp::get_logger("URPositionHardwareInterface"), "Initialized in async thread");

ur_robot_driver/src/urcl_log_handler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
namespace ur_robot_driver
5050
{
5151
bool g_registered = false;
52-
std::unique_ptr<UrclLogHandler> g_log_handler(new UrclLogHandler);
5352

5453
UrclLogHandler::UrclLogHandler() = default;
5554

@@ -82,10 +81,11 @@ void UrclLogHandler::log(const char* file, int line, urcl::LogLevel loglevel, co
8281
void registerUrclLogHandler(const std::string& tf_prefix)
8382
{
8483
if (g_registered == false) {
85-
g_log_handler->setTFPrefix(tf_prefix);
84+
std::unique_ptr<UrclLogHandler> log_handler(new UrclLogHandler);
85+
log_handler->setTFPrefix(tf_prefix);
8686
// Log level is decided by ROS2 log level
8787
urcl::setLogLevel(urcl::LogLevel::DEBUG);
88-
urcl::registerLogHandler(std::move(g_log_handler));
88+
urcl::registerLogHandler(std::move(log_handler));
8989
g_registered = true;
9090
}
9191
}

0 commit comments

Comments
 (0)