|
|
Simple rate limiter for use in loops to maintain a certain frequency given a clock. More...
#include <ArmarXCore/core/time/Metronome.h>
Public Types | |
| enum class | NextTickMode { wait_for_next_tick , tick_immediately } |
| Modes that influence how the reset method should function for the next waitForNextTick() method call. More... | |
Public Member Functions | |
| Metronome (const Duration &targetPeriod, ClockType clockType=ClockType::Virtual) | |
| Constructs a new rate limiter with given target period and clock type. | |
| Metronome (const Duration &targetPeriod, const Clock &clock) | |
| Constructs a new rate limiter with given target period and clock. | |
| Metronome (const Frequency &targetFrequency, ClockType clockType=ClockType::Virtual, NextTickMode mode=NextTickMode::wait_for_next_tick) | |
| void | reset (NextTickMode mode=NextTickMode::wait_for_next_tick) const |
| Resets the rate limiter so that the next targetted time point will be in the current time plus the target period. | |
| Duration | waitForNextTick () const |
| Wait and block until the target period is met. | |
Simple rate limiter for use in loops to maintain a certain frequency given a clock.
In most cases, it is enough sufficient to construct a rate limiter with a given target duration (or target period). This will then use virtual time. In cases where a specific clock is required, a constructor taking a clock or clock type can be used.
Code example:
Another example with a do-while loop where the metronome must be placed at the top of a loop because of continue etc.:
Definition at line 56 of file Metronome.h.
|
strong |
Modes that influence how the reset method should function for the next waitForNextTick() method call.
| Enumerator | |
|---|---|
| wait_for_next_tick | If waitForNextTicK() is called shortly after reset() (or any constructor), the metronome will wait for the length of a period. |
| tick_immediately | If waitForNextTicK() is called shortly after reset() (or any constructor), the metronome will not wait and continue immediately. This is useful, if the waitForNextTick() method must be called at the top of the scope of a loop and it is not desired for the metronome to block the first loop iteration. |
Definition at line 64 of file Metronome.h.
| Metronome | ( | const Frequency & | targetFrequency, |
| ClockType | clockType = ClockType::Virtual, | ||
| NextTickMode | mode = NextTickMode::wait_for_next_tick ) |
Definition at line 8 of file Metronome.cpp.
| Metronome | ( | const Duration & | targetPeriod, |
| ClockType | clockType = ClockType::Virtual ) |
Constructs a new rate limiter with given target period and clock type.
| targetPeriod | Period to target for in loops etc. |
| clockType | Type of clock to use to assess time. |
Definition at line 14 of file Metronome.cpp.
Constructs a new rate limiter with given target period and clock.
| targetPeriod | Period to target for in loops etc. |
| clock | Clock to use to assess time. |
Definition at line 20 of file Metronome.cpp.
| void reset | ( | NextTickMode | mode = NextTickMode::wait_for_next_tick | ) | const |
Resets the rate limiter so that the next targetted time point will be in the current time plus the target period.
Definition at line 35 of file Metronome.cpp.
| Duration waitForNextTick | ( | ) | const |
Wait and block until the target period is met.
Definition at line 27 of file Metronome.cpp.