From 3d49765bba0c1166e17826a4c4819c92d63c20ec Mon Sep 17 00:00:00 2001 From: "Dr. Denis" Date: Mon, 22 Dec 2025 20:01:03 +0100 Subject: [PATCH] Refactor read and write operation handling Removed timing and return value checks from read and write operations. --- .../hardware_component_interface.hpp | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/hardware_interface/include/hardware_interface/hardware_component_interface.hpp b/hardware_interface/include/hardware_interface/hardware_component_interface.hpp index 9a5c3c00d6..700f044a4e 100644 --- a/hardware_interface/include/hardware_interface/hardware_component_interface.hpp +++ b/hardware_interface/include/hardware_interface/hardware_component_interface.hpp @@ -130,17 +130,6 @@ class HardwareComponentInterface : public rclcpp_lifecycle::node_interfaces::Lif async_handler_->init( [this, is_sensor_type](const rclcpp::Time & time, const rclcpp::Duration & period) { - const auto read_start_time = std::chrono::steady_clock::now(); - const auto ret_read = read(time, period); - const auto read_end_time = std::chrono::steady_clock::now(); - read_return_info_.store(ret_read, std::memory_order_release); - read_execution_time_.store( - std::chrono::duration_cast(read_end_time - read_start_time), - std::memory_order_release); - if (ret_read != return_type::OK) - { - return ret_read; - } if ( !is_sensor_type && lifecycle_id_cache_.load(std::memory_order_acquire) == lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE) @@ -153,9 +142,19 @@ class HardwareComponentInterface : public rclcpp_lifecycle::node_interfaces::Lif std::chrono::duration_cast( write_end_time - write_start_time), std::memory_order_release); - return ret_write; + if (ret_write != return_type::OK) + { + return ret_write; + } } - return return_type::OK; + const auto read_start_time = std::chrono::steady_clock::now(); + const auto ret_read = read(time, period); + const auto read_end_time = std::chrono::steady_clock::now(); + read_return_info_.store(ret_read, std::memory_order_release); + read_execution_time_.store( + std::chrono::duration_cast(read_end_time - read_start_time), + std::memory_order_release); + return ret_read; }, async_thread_params); async_handler_->start_thread();