-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 timestamps #2658
fix timestamps #2658
Changes from 1 commit
b54cf11
baadd0f
4538682
3a6d8ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -708,17 +708,35 @@ bool BaseRealSenseNode::setBaseTime(double frame_time, rs2_timestamp_domain time | |
return false; | ||
} | ||
|
||
uint64_t BaseRealSenseNode::millisecondsToNanoseconds(double timestamp_ms) | ||
{ | ||
// modf breaks input into an integral and fractional part | ||
double int_part_ms, fract_part_ms; | ||
fract_part_ms = modf(timestamp_ms, &int_part_ms); | ||
|
||
//convert to ns | ||
uint64_t int_part_ns = static_cast<uint64_t>(int_part_ms) * 1000000; | ||
uint64_t fract_part_ns = static_cast<uint64_t>(fract_part_ms * 10000000); | ||
|
||
// Convert fract_parts_ns into 6 digits and round it | ||
// to be aligned with librealsense get_timestamp API | ||
fract_part_ns = (fract_part_ns % 10 > 4) ? (fract_part_ns/10 + 1) : (fract_part_ns/10); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More efficient |
||
|
||
return int_part_ns + fract_part_ns; | ||
} | ||
|
||
rclcpp::Time BaseRealSenseNode::frameSystemTimeSec(rs2::frame frame) | ||
{ | ||
double timestamp_ms = frame.get_timestamp(); | ||
if (frame.get_frame_timestamp_domain() == RS2_TIMESTAMP_DOMAIN_HARDWARE_CLOCK) | ||
{ | ||
double elapsed_camera_ns = (/*ms*/ frame.get_timestamp() - /*ms*/ _camera_time_base) * 1e6; | ||
double elapsed_camera_ns = millisecondsToNanoseconds(timestamp_ms - _camera_time_base); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Converting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this question in more related to Librealsense API, since frame.get_timestamp is returning a double timestamp. |
||
|
||
/* | ||
Fixing deprecated-declarations compilation warning. | ||
Duration(rcl_duration_value_t) is deprecated in favor of | ||
static Duration::from_nanoseconds(rcl_duration_value_t) | ||
starting from GALAXY. | ||
starting from GALACTIC. | ||
*/ | ||
#if defined(FOXY) || defined(ELOQUENT) || defined(DASHING) | ||
auto duration = rclcpp::Duration(elapsed_camera_ns); | ||
|
@@ -730,7 +748,7 @@ rclcpp::Time BaseRealSenseNode::frameSystemTimeSec(rs2::frame frame) | |
} | ||
else | ||
{ | ||
return rclcpp::Time(frame.get_timestamp() * 1e6); | ||
return rclcpp::Time(millisecondsToNanoseconds(timestamp_ms)); | ||
} | ||
} | ||
|
||
|
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.
Too many zeros.
It would be better to use a constant
static constexpr uint64_t milli_to_nano = 1000000
.Can also use C++14 digit separator
1'000'000
:-)