Skip to content

Commit

Permalink
AP_Scheduler: make overtime margin definable
Browse files Browse the repository at this point in the history
Also warn about overtime on ESP32 which is most likely to hit it.
  • Loading branch information
tpwrules committed Sep 1, 2024
1 parent 1439aeb commit 54a70f7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion libraries/AP_Scheduler/PerfInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ extern const AP_HAL::HAL& hal;
// we measure the main loop time
//

// loops over time by this amount or more won't be counted in filtered loop time (and thus loop rate)
#ifndef AP_SCHEDULER_OVERTIME_MARGIN_US
#define AP_SCHEDULER_OVERTIME_MARGIN_US 10000UL
#endif

// reset - reset all records of loop time to zero
void AP::PerfInfo::reset()
{
Expand Down Expand Up @@ -140,8 +145,16 @@ void AP::PerfInfo::check_loop_time(uint32_t time_in_micros)
const uint32_t now = AP_HAL::micros();
const uint32_t loop_time_us = now - last_check_us;
last_check_us = now;
if (loop_time_us < overtime_threshold_micros + 10000UL) {
if (loop_time_us < overtime_threshold_micros + AP_SCHEDULER_OVERTIME_MARGIN_US) {
filtered_loop_time = 0.99f * filtered_loop_time + 0.01f * loop_time_us * 1.0e-6f;
} else {
// esp32 is most likely to regularly trigger long loops, might be
// helpful for bringup of other boards too
#if CONFIG_HAL_BOARD == HAL_BOARD_ESP32
#ifdef SCHEDDEBUG
DEV_PRINTF("way overtime: %dus\n", loop_time_us);
#endif
#endif
}
}

Expand Down

0 comments on commit 54a70f7

Please sign in to comment.