From a89c0a91999a2b08942752dd9986b5c3ea0ba067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20Fatih=20C=C4=B1r=C4=B1t?= Date: Fri, 1 Dec 2023 10:35:34 +0300 Subject: [PATCH] fix(hw_interfaces): fix the lossy nanoseconds extraction (#101) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(hw_interfaces): fix the lossy nanoseconds extraction Signed-off-by: M. Fatih Cırıt * Apply suggestions from code review Co-authored-by: Max Schmeller <6088931+mojomex@users.noreply.github.com> --------- Signed-off-by: M. Fatih Cırıt Co-authored-by: Max Schmeller <6088931+mojomex@users.noreply.github.com> --- .../src/nebula_hesai_hw_interfaces/hesai_hw_interface.cpp | 3 +-- .../nebula_velodyne_hw_interfaces/velodyne_hw_interface.cpp | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/nebula_hw_interfaces/src/nebula_hesai_hw_interfaces/hesai_hw_interface.cpp b/nebula_hw_interfaces/src/nebula_hesai_hw_interfaces/hesai_hw_interface.cpp index 601960347..e71366831 100644 --- a/nebula_hw_interfaces/src/nebula_hesai_hw_interfaces/hesai_hw_interface.cpp +++ b/nebula_hw_interfaces/src/nebula_hesai_hw_interfaces/hesai_hw_interface.cpp @@ -189,8 +189,7 @@ void HesaiHwInterface::ReceiveCloudPacketCallback(const std::vector & b auto now_nanosecs = std::chrono::duration_cast(now.time_since_epoch()).count(); pandar_packet.stamp.sec = static_cast(now_secs); - pandar_packet.stamp.nanosec = - static_cast((now_nanosecs / 1000000000. - static_cast(now_secs)) * 1000000000); + pandar_packet.stamp.nanosec = static_cast(now_nanosecs % 1'000'000'000); scan_cloud_ptr_->packets.emplace_back(pandar_packet); int current_phase = 0; diff --git a/nebula_hw_interfaces/src/nebula_velodyne_hw_interfaces/velodyne_hw_interface.cpp b/nebula_hw_interfaces/src/nebula_velodyne_hw_interfaces/velodyne_hw_interface.cpp index b8f86f266..35aeeec82 100644 --- a/nebula_hw_interfaces/src/nebula_velodyne_hw_interfaces/velodyne_hw_interface.cpp +++ b/nebula_hw_interfaces/src/nebula_velodyne_hw_interfaces/velodyne_hw_interface.cpp @@ -72,8 +72,7 @@ void VelodyneHwInterface::ReceiveCloudPacketCallback(const std::vector std::chrono::duration_cast(now.time_since_epoch()).count(); velodyne_packet.data = packet_data; velodyne_packet.stamp.sec = static_cast(now_secs); - velodyne_packet.stamp.nanosec = - static_cast((now_nanosecs / 1000000000. - static_cast(now_secs)) * 1000000000); + velodyne_packet.stamp.nanosec = static_cast(now_nanosecs % 1'000'000'000); scan_cloud_ptr_->packets.emplace_back(velodyne_packet); processed_packets_++;