#include <frequencyGoverner.h>
Public Member Functions | |
| FrequencyGoverner (double frequency, double duration=0.0) | |
| The constructor initializes the FrequencyGoverner and starts the internal timer. | |
| ~FrequencyGoverner () | |
| The destructor destroys the FrequencyGoverner instance and deletes any file created by the constructor, thereby releasing the lock. | |
| double | getActualFrequency () |
| This method returns the average frequency at which method sleepIfNecessary() has been called. | |
| unsigned int | getCount () |
| This method returns the number of times that method sleepIfNecessary() has been called. | |
| double | getSlack () |
| This method returns how long, in seconds, method sleepIfNecessary() would have slept if it had been called instead of getSlack(). | |
| bool | isFinished () |
| This method reports whether or not the specified period (from constructor argument "duration") has elapsed. | |
| void | sleepIfNecessary () |
| This method sleeps just long enough to prevent a loop from running faster than the specifed frequency. | |
Here's an example of how it might be used:
double frequency = 30.0; // Hz. double duration = 10.0; // Seconds. FrequencyGoverner governer(frequency, duration); while(!governer.isFinished()) { // Do something. // [..] governer.sleepIfNecessary(); }
Definition at line 40 of file frequencyGoverner.h.
| dlr::utilities::FrequencyGoverner::FrequencyGoverner | ( | double | frequency, | |
| double | duration = 0.0 | |||
| ) | [inline, explicit] |
The constructor initializes the FrequencyGoverner and starts the internal timer.
| frequency | This argument specifies how fast you'd like the loop to run. Setting this argument to zero indicates no throttling of loop speed. | |
| duration | This argument specifies how long you'd like the loop to run. Setting this argument to zero indicates no timeout. |
Definition at line 56 of file frequencyGoverner.h.
| dlr::utilities::FrequencyGoverner::~FrequencyGoverner | ( | ) | [inline] |
The destructor destroys the FrequencyGoverner instance and deletes any file created by the constructor, thereby releasing the lock.
Definition at line 65 of file frequencyGoverner.h.
| double dlr::utilities::FrequencyGoverner::getActualFrequency | ( | ) | [inline] |
This method returns the average frequency at which method sleepIfNecessary() has been called.
This average includes any time spent between the constructor and the first call to sleepIfNecessary(). As long as the other code in the frequency-governed loop isn't too heavy, the return value should be approximately equal to the frequency specified in the constructor call.
Definition at line 81 of file frequencyGoverner.h.
| unsigned int dlr::utilities::FrequencyGoverner::getCount | ( | ) | [inline] |
This method returns the number of times that method sleepIfNecessary() has been called.
Definition at line 95 of file frequencyGoverner.h.
| double dlr::utilities::FrequencyGoverner::getSlack | ( | ) | [inline] |
This method returns how long, in seconds, method sleepIfNecessary() would have slept if it had been called instead of getSlack().
Definition at line 107 of file frequencyGoverner.h.
Referenced by sleepIfNecessary().
| bool dlr::utilities::FrequencyGoverner::isFinished | ( | ) | [inline] |
This method reports whether or not the specified period (from constructor argument "duration") has elapsed.
Definition at line 118 of file frequencyGoverner.h.
| void dlr::utilities::FrequencyGoverner::sleepIfNecessary | ( | ) | [inline] |
This method sleeps just long enough to prevent a loop from running faster than the specifed frequency.
Definition at line 129 of file frequencyGoverner.h.
References getSlack().
1.5.8