Skip to content

Commit 141a17a

Browse files
author
Felix Exner (fexner)
authored
Fix component lifecycle (#1098)
* Correctly reset async_thread_shutdown when starting the async thread * Do not use a global log handler object ---------
1 parent 3bc9a82 commit 141a17a

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
@@ -191,7 +191,7 @@ class URPositionHardwareInterface : public hardware_interface::SystemInterface
191191
bool first_pass_;
192192
bool initialized_;
193193
double system_interface_initialized_;
194-
bool async_thread_shutdown_;
194+
std::atomic_bool async_thread_shutdown_;
195195
double get_robot_software_version_major_;
196196
double get_robot_software_version_minor_;
197197
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
@@ -534,6 +534,7 @@ void URPositionHardwareInterface::readBitsetData(const std::unique_ptr<rtde::Dat
534534

535535
void URPositionHardwareInterface::asyncThread()
536536
{
537+
async_thread_shutdown_ = false;
537538
while (!async_thread_shutdown_) {
538539
if (initialized_) {
539540
// 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)