From 3fd2f9f616233882d2cdc33e42b3109831ee3910 Mon Sep 17 00:00:00 2001 From: CursedRock17 Date: Mon, 22 Apr 2024 23:05:59 -0400 Subject: [PATCH 1/2] Improved Accuracy Signed-off-by: CursedRock17 --- tf2/src/time.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/tf2/src/time.cpp b/tf2/src/time.cpp index dfa09b128..71821a4c0 100644 --- a/tf2/src/time.cpp +++ b/tf2/src/time.cpp @@ -34,6 +34,7 @@ #include "rcutils/snprintf.h" #include "rcutils/strerror.h" +#include "rcutils/time.h" #include "tf2/time.h" tf2::TimePoint tf2::get_now() @@ -60,16 +61,7 @@ tf2::TimePoint tf2::timeFromSec(double t_sec) double tf2::durationToSec(const tf2::Duration & input) { int64_t count = input.count(); - - // scale the nanoseconds separately for improved accuracy - int32_t sec, nsec; - nsec = static_cast(count % 1000000000l); - sec = static_cast((count - nsec) / 1000000000l); - - double sec_double, nsec_double; - nsec_double = 1e-9 * static_cast(nsec); - sec_double = static_cast(sec); - return sec_double + nsec_double; + return RCUTILS_NS_TO_S(count); } double tf2::timeToSec(const tf2::TimePoint & timepoint) From eb14e05856351ffcd95cac9dc08e9683583f33cf Mon Sep 17 00:00:00 2001 From: CursedRock17 Date: Mon, 19 Aug 2024 12:12:25 -0400 Subject: [PATCH 2/2] Changing method Signed-off-by: CursedRock17 --- tf2/src/time.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tf2/src/time.cpp b/tf2/src/time.cpp index 71821a4c0..808c151fd 100644 --- a/tf2/src/time.cpp +++ b/tf2/src/time.cpp @@ -61,7 +61,7 @@ tf2::TimePoint tf2::timeFromSec(double t_sec) double tf2::durationToSec(const tf2::Duration & input) { int64_t count = input.count(); - return RCUTILS_NS_TO_S(count); + return rcutils_nanoseconds_to_seconds(count); } double tf2::timeToSec(const tf2::TimePoint & timepoint)