From 21c43cbaa87f64e91008bae32e4d864fcf173431 Mon Sep 17 00:00:00 2001 From: Giulio Romualdi Date: Thu, 13 Jul 2023 09:42:00 +0200 Subject: [PATCH] Use std::chrono::nanoseconds in RosClock --- .../include/BipedalLocomotion/System/RosClock.h | 6 +++--- src/System/RosImplementation/src/RosClock.cpp | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/System/RosImplementation/include/BipedalLocomotion/System/RosClock.h b/src/System/RosImplementation/include/BipedalLocomotion/System/RosClock.h index 99fd18d3ac..4b782cda45 100644 --- a/src/System/RosImplementation/include/BipedalLocomotion/System/RosClock.h +++ b/src/System/RosImplementation/include/BipedalLocomotion/System/RosClock.h @@ -58,19 +58,19 @@ class RosClock final : public IClock * @note `BipedalLocomotion::clock().now().count()` returns a double containing the seconds * since epoch. */ - std::chrono::duration now() final; + std::chrono::nanoseconds now() final; /** * Blocks the execution of the current thread for at least the specified sleepDuration. * @param time duration to sleep */ - void sleepFor(const std::chrono::duration& sleepDuration) final; + void sleepFor(const std::chrono::nanoseconds& sleepDuration) final; /** * Blocks the execution of the current thread until specified sleepTime has been reached. * @param time to block until */ - void sleepUntil(const std::chrono::duration& sleepTime) final; + void sleepUntil(const std::chrono::nanoseconds& sleepTime) final; /** * Provides a hint to the implementation to reschedule the execution of threads, allowing other diff --git a/src/System/RosImplementation/src/RosClock.cpp b/src/System/RosImplementation/src/RosClock.cpp index bd9550d9bb..04080ca998 100644 --- a/src/System/RosImplementation/src/RosClock.cpp +++ b/src/System/RosImplementation/src/RosClock.cpp @@ -14,18 +14,18 @@ using namespace BipedalLocomotion::System; -std::chrono::duration RosClock::now() +std::chrono::nanoseconds RosClock::now() { - return std::chrono::duration(m_clock.now().seconds()); + return std::chrono::nanoseconds(m_clock.now().nanoseconds()); } -void RosClock::sleepFor(const std::chrono::duration& sleepDuration) +void RosClock::sleepFor(const std::chrono::nanoseconds& sleepDuration) { // std::chrono::duration store the time in second m_clock.sleep_for(sleepDuration); } -void RosClock::sleepUntil(const std::chrono::duration& sleepTime) +void RosClock::sleepUntil(const std::chrono::nanoseconds& sleepTime) { m_clock.sleep_for(sleepTime - this->now()); }