Metronome.cpp
Go to the documentation of this file.
1 #include "Metronome.h"
2 
4 
5 namespace armarx::core::time
6 {
7 
8  Metronome::Metronome(const Frequency& targetFrequency, ClockType clockType) :
9  _clock{clockType}, _targetPeriod{targetFrequency.toCycleDuration()}
10  {
11  reset();
12  }
13 
14  Metronome::Metronome(const Duration& targetPeriod, ClockType clockType) :
15  _clock{clockType}, _targetPeriod{targetPeriod}
16  {
17  reset();
18  }
19 
20  Metronome::Metronome(const Duration& targetPeriod, const Clock& clock) :
21  _clock{clock}, _targetPeriod(targetPeriod)
22  {
23  reset();
24  }
25 
26  Duration
28  {
29  const Duration waitTime = _clock.waitUntil(_nextCheckpoint);
30  _nextCheckpoint += _targetPeriod;
31  return waitTime;
32  }
33 
34  void
36  {
37  _nextCheckpoint = _clock.now() + _targetPeriod;
38  }
39 
40 } // namespace armarx::core::time
armarx::core::time::Metronome::Metronome
Metronome(const Frequency &targetFrequency, ClockType clockType=ClockType::Virtual)
Definition: Metronome.cpp:8
armarx::core::time
Definition: Clock.cpp:13
armarx::core::time::Frequency
Represents a frequency.
Definition: Frequency.h:16
armarx::core::time::Clock::waitUntil
Duration waitUntil(const DateTime &dateTime) const
Wait and block until the given date/time is surpassed.
Definition: Clock.cpp:80
armarx::core::time::Clock
Clock to get date/time from a specific clock type or wait for certain durations or until certain date...
Definition: Clock.h:25
Clock.h
armarx::core::time::ClockType
ClockType
Describes the type of clock.
Definition: ClockType.h:9
Metronome.h
armarx::core::time::Metronome::waitForNextTick
Duration waitForNextTick()
Wait and block until the target period is met.
Definition: Metronome.cpp:27
armarx::core::time::Duration
Represents a duration.
Definition: Duration.h:16
armarx::core::time::Metronome::reset
void reset()
Resets the rate limiter so that the next targetted time point will be in the current time plus the ta...
Definition: Metronome.cpp:35
armarx::core::time::Clock::now
DateTime now() const
Current date/time of the clock.
Definition: Clock.cpp:22