From 1a24da7322fa0bf827606f0472a2d152793c5031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20Fatih=20C=C4=B1r=C4=B1t?= Date: Thu, 30 Nov 2023 18:41:45 +0300 Subject: [PATCH 1/2] fix(hw_interfaces): fix the lossy nanoseconds extraction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: M. Fatih Cırıt --- .../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..8bfe0399f 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 % 1000000000); 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..0aa2a4d3f 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 % 1000000000); scan_cloud_ptr_->packets.emplace_back(velodyne_packet); processed_packets_++; From 7aee61e92b3841c43beb4adcdfbd8d4e053dd97b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20Fatih=20C=C4=B1r=C4=B1t?= Date: Fri, 1 Dec 2023 09:32:17 +0300 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Max Schmeller <6088931+mojomex@users.noreply.github.com> --- .../src/nebula_hesai_hw_interfaces/hesai_hw_interface.cpp | 2 +- .../src/nebula_velodyne_hw_interfaces/velodyne_hw_interface.cpp | 2 +- 2 files changed, 2 insertions(+), 2 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 8bfe0399f..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,7 +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); + 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 0aa2a4d3f..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,7 +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); + velodyne_packet.stamp.nanosec = static_cast(now_nanosecs % 1'000'000'000); scan_cloud_ptr_->packets.emplace_back(velodyne_packet); processed_packets_++;