Simulator: Add scaling API to adjust for slow simulators

The simulation engine had the ability to pause already and properly handled load spikes, however, it was not hardened against constant drift. This addition enables it to run at a constant slower-than-realtime rate successfully.
This commit is contained in:
Lorenz Meier
2017-08-01 19:50:35 +02:00
parent cf7d4fc1a7
commit 1c0dd8ba49
3 changed files with 67 additions and 22 deletions
+23 -1
View File
@@ -332,6 +332,28 @@ void hrt_start_delay()
pthread_mutex_unlock(&_hrt_mutex);
}
void hrt_stop_delay_delta(hrt_abstime delta)
{
pthread_mutex_lock(&_hrt_mutex);
uint64_t delta_measured = _hrt_absolute_time_internal() - _start_delay_time;
if (delta_measured < delta) {
//PX4_WARN("Slim slowdown inaccurate: (slowdown delay: %" PRIu64 " us, true: %" PRIu64 " us)", delta, delta_measured);
delta = delta_measured;
}
_delay_interval += delta;
_start_delay_time = 0;
if (delta > 100000) {
PX4_WARN("Computer load temporarily too high for real-time simulation. (slowdown delay: %" PRIu64 " us)", delta);
}
pthread_mutex_unlock(&_hrt_mutex);
}
void hrt_stop_delay()
{
pthread_mutex_lock(&_hrt_mutex);
@@ -340,7 +362,7 @@ void hrt_stop_delay()
_start_delay_time = 0;
if (delta > 100000) {
PX4_INFO("Computer load temporarily too high for real-time simulation. (slowdown delay: %" PRIu64 " us)", delta);
PX4_WARN("Computer load temporarily too high for real-time simulation. (slowdown delay: %" PRIu64 " us)", delta);
}
pthread_mutex_unlock(&_hrt_mutex);