Skip to content
Snippets Groups Projects
Commit 7831113f authored by Andrew Tridgell's avatar Andrew Tridgell
Browse files

AP_InertialSensor: yield the CPU for the right time in wait_for_sample()

this improves timing performance
parent d973730b
No related branches found
No related tags found
No related merge requests found
...@@ -159,7 +159,13 @@ bool AP_InertialSensor_PX4::wait_for_sample(uint16_t timeout_ms) ...@@ -159,7 +159,13 @@ bool AP_InertialSensor_PX4::wait_for_sample(uint16_t timeout_ms)
} }
uint32_t start = hal.scheduler->millis(); uint32_t start = hal.scheduler->millis();
while ((hal.scheduler->millis() - start) < timeout_ms) { while ((hal.scheduler->millis() - start) < timeout_ms) {
hal.scheduler->delay_microseconds(100); uint64_t tnow = hrt_absolute_time();
// we spin for the last timing_lag microseconds. Before that
// we yield the CPU to allow IO to happen
const uint16_t timing_lag = 400;
if (_last_sample_timestamp + _sample_time_usec > tnow+timing_lag) {
hal.scheduler->delay_microseconds(_last_sample_timestamp + _sample_time_usec - (tnow+timing_lag));
}
if (sample_available()) { if (sample_available()) {
return true; return true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment