Skip to content

Commit

Permalink
Use std::chrono::nanoseconds in RosClock
Browse files Browse the repository at this point in the history
  • Loading branch information
GiulioRomualdi committed Jul 13, 2023
1 parent 4e18603 commit 21c43cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> 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<double>& 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<double>& sleepTime) final;
void sleepUntil(const std::chrono::nanoseconds& sleepTime) final;

/**
* Provides a hint to the implementation to reschedule the execution of threads, allowing other
Expand Down
8 changes: 4 additions & 4 deletions src/System/RosImplementation/src/RosClock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@

using namespace BipedalLocomotion::System;

std::chrono::duration<double> RosClock::now()
std::chrono::nanoseconds RosClock::now()
{
return std::chrono::duration<double>(m_clock.now().seconds());
return std::chrono::nanoseconds(m_clock.now().nanoseconds());
}

void RosClock::sleepFor(const std::chrono::duration<double>& 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<double>& sleepTime)
void RosClock::sleepUntil(const std::chrono::nanoseconds& sleepTime)
{
m_clock.sleep_for(sleepTime - this->now());
}
Expand Down

0 comments on commit 21c43cb

Please sign in to comment.