Skip to content

Commit

Permalink
Fix component lifecycle (backport of #1098)
Browse files Browse the repository at this point in the history
* Correctly reset async_thread_shutdown when starting the async thread

* Do not use a global log handler object
  • Loading branch information
mergify[bot] authored Oct 26, 2024
1 parent 9c33a93 commit 506c612
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
1 change: 1 addition & 0 deletions ur_robot_driver/src/hardware_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ void URPositionHardwareInterface::readBitsetData(const std::unique_ptr<rtde::Dat

void URPositionHardwareInterface::asyncThread()
{
async_thread_shutdown_ = false;
while (!async_thread_shutdown_) {
if (initialized_) {
// RCLCPP_INFO(rclcpp::get_logger("URPositionHardwareInterface"), "Initialized in async thread");
Expand Down
6 changes: 3 additions & 3 deletions ur_robot_driver/src/urcl_log_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
namespace ur_robot_driver
{
bool g_registered = false;
std::unique_ptr<UrclLogHandler> g_log_handler(new UrclLogHandler);

UrclLogHandler::UrclLogHandler() = default;

Expand Down Expand Up @@ -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<UrclLogHandler> 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;
}
}
Expand Down

0 comments on commit 506c612

Please sign in to comment.