diff --git a/src/modules/commander/HealthAndArmingChecks/checks/cpuResourceCheck.cpp b/src/modules/commander/HealthAndArmingChecks/checks/cpuResourceCheck.cpp
index 2413bfeda5b..6a142ba73b9 100644
--- a/src/modules/commander/HealthAndArmingChecks/checks/cpuResourceCheck.cpp
+++ b/src/modules/commander/HealthAndArmingChecks/checks/cpuResourceCheck.cpp
@@ -41,6 +41,8 @@ void CpuResourceChecks::checkAndReport(const Context &context, Report &reporter)
return;
}
+ static hrt_abstime high_cpu_load_start_time_us_ = 0;
+
cpuload_s cpuload;
if (!_cpuload_sub.copy(&cpuload) || hrt_elapsed_time(&cpuload.timestamp) > 2_s) {
@@ -59,26 +61,37 @@ void CpuResourceChecks::checkAndReport(const Context &context, Report &reporter)
mavlink_log_critical(reporter.mavlink_log_pub(), "Preflight Fail: No CPU load information");
}
+ high_cpu_load_start_time_us_ = hrt_absolute_time(); // reset
+
} else {
const float cpuload_percent = cpuload.load * 100.f;
if (cpuload_percent > _param_com_cpu_max.get()) {
- /* EVENT
- * @description
- * The CPU load can be reduced for example by disabling unused modules (e.g. mavlink instances) or reducing the gyro update
- * rate via IMU_GYRO_RATEMAX.
- *
- *
- * The threshold can be adjusted via COM_CPU_MAX parameter.
- *
- */
- reporter.healthFailure(NavModes::All, health_component_t::system, events::ID("check_cpuload_too_high"),
- events::Log::Error, "CPU load too high: {1:.1}%", cpuload_percent);
+ // trigger the failure if the CPU load is above the threshold for 2 seconds
+ if (high_cpu_load_start_time_us_ == 0) {
+ high_cpu_load_start_time_us_ = hrt_absolute_time();
- if (reporter.mavlink_log_pub()) {
- mavlink_log_critical(reporter.mavlink_log_pub(), "Preflight Fail: CPU load too high: %3.1f%%", (double)cpuload_percent);
+ } else if (hrt_elapsed_time(&high_cpu_load_start_time_us_) > 2_s) {
+ /* EVENT
+ * @description
+ * The CPU load can be reduced for example by disabling unused modules (e.g. mavlink instances) or reducing the gyro update
+ * rate via IMU_GYRO_RATEMAX.
+ *
+ *
+ * The threshold can be adjusted via COM_CPU_MAX parameter.
+ *
+ */
+ reporter.healthFailure(NavModes::All, health_component_t::system, events::ID("check_cpuload_too_high"),
+ events::Log::Error, "CPU load too high: {1:.1}%", cpuload_percent);
+
+ if (reporter.mavlink_log_pub()) {
+ mavlink_log_critical(reporter.mavlink_log_pub(), "Preflight Fail: CPU load too high: %3.1f%%", (double)cpuload_percent);
+ }
}
+
+ } else {
+ high_cpu_load_start_time_us_ = 0; // reset
}
}
}
diff --git a/src/modules/commander/commander_params.c b/src/modules/commander/commander_params.c
index da0afc5b671..b84fdeff6be 100644
--- a/src/modules/commander/commander_params.c
+++ b/src/modules/commander/commander_params.c
@@ -919,7 +919,8 @@ PARAM_DEFINE_INT32(COM_MOT_TEST_EN, 1);
PARAM_DEFINE_FLOAT(COM_KILL_DISARM, 5.0f);
/**
- * Maximum allowed CPU load to still arm
+ * Maximum allowed CPU load to still arm.
+ * The check fails if the CPU load is above this threshold for 2s.
*
* A negative value disables the check.
*