Metronome.cpp
Go to the documentation of this file.
1 #include "Metronome.h"
2 
4 
5 
6 namespace armarx::core::time
7 {
8 
9  Metronome::Metronome(const Frequency& targetFrequency, ClockType clockType) :
10  _clock{clockType}, _targetPeriod{targetFrequency.toCycleDuration()}
11  {
12  reset();
13  }
14 
15 
16  Metronome::Metronome(const Duration& targetPeriod, ClockType clockType) :
17  _clock{clockType}, _targetPeriod{targetPeriod}
18  {
19  reset();
20  }
21 
22 
23  Metronome::Metronome(const Duration& targetPeriod, const Clock& clock) :
24  _clock{clock}, _targetPeriod(targetPeriod)
25  {
26  reset();
27  }
28 
29 
30  Duration
32  {
33  const Duration waitTime = _clock.waitUntil(_nextCheckpoint);
34  _nextCheckpoint += _targetPeriod;
35  return waitTime;
36  }
37 
38 
39  void
41  {
42  _nextCheckpoint = _clock.now() + _targetPeriod;
43  }
44 
45 } // namespace armarx::core::time
armarx::core::time::Metronome::Metronome
Metronome(const Frequency &targetFrequency, ClockType clockType=ClockType::Virtual)
Definition: Metronome.cpp:9
armarx::core::time
Definition: Clock.cpp:13
armarx::core::time::Frequency
Represents a frequency.
Definition: Frequency.h:17
armarx::core::time::Clock::waitUntil
Duration waitUntil(const DateTime &dateTime) const
Wait and block until the given date/time is surpassed.
Definition: Clock.cpp:82
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:26
Clock.h
armarx::core::time::ClockType
ClockType
Describes the type of clock.
Definition: ClockType.h:10
Metronome.h
armarx::core::time::Metronome::waitForNextTick
Duration waitForNextTick()
Wait and block until the target period is met.
Definition: Metronome.cpp:31
armarx::core::time::Duration
Represents a duration.
Definition: Duration.h:17
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:40
armarx::core::time::Clock::now
DateTime now() const
Current date/time of the clock.
Definition: Clock.cpp:23