mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
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:
parent
45582fcf55
commit
6974c4a5cb
@ -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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user