-
Notifications
You must be signed in to change notification settings - Fork 266
Description
By default windows timing is only accurate to about ~15ms. Things like time.monotonic() tick with only that rate even if the datatype would allow for higher prescision. This is a common issue for things like Games as well, so newer windows versions offer ways to boost the scheduler rate. Fyi this does not only concern ROS timers, even if they might be affected by it.
In the past this has lead to a number of issues, that have been fixed mostly in a symptomatic manner. Some of them include:
- Timer related tests experience more jitter on windows #513 (this one even describes a low res tick step pattern, which is a result of this issue)
- Timer tests fail sporadically #267
- 👩🌾 Regression on TestExecutor.test_create_task_coroutine_wake_from_another_thread #1562
- Fix windows regression: Increase clock accuracy #1564 (additional flaky test noticed during the fix of 👩🌾 Regression on TestExecutor.test_create_task_coroutine_wake_from_another_thread #1562)
The following PR includes a bit of off-topic discussion, including some simple experiments, regarding this isuue: #1563
As originally suggested by (@traversaro) possible fix could include something like this during the start/stop of rclpy:
WindowsSchedulerBooster()
{
#if defined(_WIN32)
// Only affects Windows systems.
TIMECAPS tm; // Stores system timer capabilities.
// Get the minimum timer resolution supported by the system.
timeGetDevCaps(&tm, sizeof(TIMECAPS));
// Set the system timer resolution to the minimum value for higher precision.
timeBeginPeriod(tm.wPeriodMin);
#endif
}
~WindowsSchedulerBooster()
{
#if defined(_WIN32)
// Only affects Windows systems.
TIMECAPS tm; // Stores system timer capabilities.
// Get the minimum timer resolution supported by the system.
timeGetDevCaps(&tm, sizeof(TIMECAPS));
// Restore the system timer resolution to the default value.
timeEndPeriod(tm.wPeriodMin);
#endif
}Here is a blog post that talks about timer accuracy in windows: https://www.siliceum.com/en/blog/post/windows-high-resolution-timers/