-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(hw_interfaces): fix the lossy nanoseconds extraction #101
Conversation
Signed-off-by: M. Fatih Cırıt <[email protected]>
There were errors in 100~ nanoseconds range from the lossy conversion when I tested it. |
https://www.twitch.tv/videos/1991133148?t=01h12m47s was found/fixed during this stream. |
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #101 +/- ##
========================================
- Coverage 8.27% 3.96% -4.32%
========================================
Files 87 27 -60
Lines 8456 5950 -2506
Branches 853 463 -390
========================================
- Hits 700 236 -464
+ Misses 7180 5302 -1878
+ Partials 576 412 -164
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @xmfcx for your PR, and for noticing the issue.
If you could add separators ' for every 3 0s to make it more readable as suggested in the comments below, it would be perfect!
nebula_hw_interfaces/src/nebula_hesai_hw_interfaces/hesai_hw_interface.cpp
Outdated
Show resolved
Hide resolved
nebula_hw_interfaces/src/nebula_velodyne_hw_interfaces/velodyne_hw_interface.cpp
Outdated
Show resolved
Hide resolved
Co-authored-by: Max Schmeller <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
PR Type
Related Links
None.
Description
The first line of code you provided appears to have a bug related to the calculation of the nanoseconds portion of a timestamp. Here's the breakdown:
First Line Analysis:
packet.stamp.nanosec = static_cast<int>((now_nanosecs / 1000000000. - static_cast<double>(now_secs)) * 1000000000);
now_nanosecs
), dividing it by 1 billion (to get the seconds part), and then subtracting the seconds part (now_secs
) from it. This result is then multiplied by 1 billion to convert it back to nanoseconds.now_nanosecs
by 1 billion and then subtractnow_secs
, you might not get an accurate nanoseconds part because of potential floating-point precision errors. The calculation also unnecessarily converts values to adouble
and then back to anint
, which can introduce additional precision errors.Second Line Fix:
packet.stamp.nanosec = static_cast<std::uint32_t>(now_nanosecs % 1000000000);
%
). It effectively gets the remainder ofnow_nanosecs
when divided by 1 billion, which directly gives the nanoseconds part without needing to convert to seconds first.In summary, the first line has a potential precision issue due to unnecessary floating-point calculations and conversions, while the second line efficiently and accurately calculates the nanoseconds part using the modulo operation.
Review Procedure
Remarks
Pre-Review Checklist for the PR Author
PR Author should check the checkboxes below when creating the PR.
Checklist for the PR Reviewer
Reviewers should check the checkboxes below before approval.
Post-Review Checklist for the PR Author
PR Author should check the checkboxes below before merging.
CI Checks