AutopilotTester: Speed up polling w speed factor

If sim is running faster, we should also poll faster to keep the
same timing resolution. This fixed quite a large number of test
failures.
This commit is contained in:
Balduin 2025-02-03 12:02:06 +01:00 committed by Ramon Roche
parent 45582fcf55
commit 6974c4a5cb
No known key found for this signature in database
GPG Key ID: 275988FAE5821713

View File

@ -169,13 +169,22 @@ public:
{
const std::chrono::microseconds duration_us(duration);
// Hopefully this is often enough not to have PX4 time out on us.
auto realtime_sleep_duration = std::chrono::milliseconds(1);
if (speed_factor.has_value()) {
// If sim is running faster than realtime, we need to
// speed up polling (which happens w.r.t. real time) to
// maintain the check resolution w.r.t. sim time
realtime_sleep_duration /= speed_factor.value();
}
if (_telemetry && _telemetry->attitude_quaternion().timestamp_us != 0) {
const int64_t start_time_us = _telemetry->attitude_quaternion().timestamp_us;
while (true) {
// Hopefully this is often enough not to have PX4 time out on us.
std::this_thread::sleep_for(std::chrono::milliseconds(1));
std::this_thread::sleep_for(realtime_sleep_duration);
const int64_t elapsed_time_us = _telemetry->attitude_quaternion().timestamp_us - start_time_us;
@ -237,7 +246,14 @@ private:
bool poll_condition_with_timeout(
std::function<bool()> fun, std::chrono::duration<Rep, Period> duration)
{
static constexpr unsigned check_resolution = 100;
unsigned check_resolution = 100;
if (speed_factor.has_value()) {
// If sim is running faster than realtime, we need to
// speed up polling (which happens w.r.t. real time) to
// maintain the check resolution w.r.t. sim time
check_resolution *= speed_factor.value();
}
const std::chrono::microseconds duration_us(duration);