Commander: add max flight time warning (starting at 90%)

Signed-off-by: Silvan Fuhrer <silvan@auterion.com>
This commit is contained in:
Silvan Fuhrer 2023-01-30 17:28:54 +01:00
parent b1709743f7
commit 6d84da5cf1
2 changed files with 61 additions and 2 deletions

View File

@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (c) 2022 PX4 Development Team. All rights reserved.
* Copyright (c) 2022-2023 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -55,4 +55,61 @@ void FlightTimeChecks::checkAndReport(const Context &context, Report &reporter)
} else {
reporter.failsafeFlags().flight_time_limit_exceeded = false;
}
// report warning when approaching max flight time
if (!reporter.failsafeFlags().flight_time_limit_exceeded
&& context.status().takeoff_time != 0
&& _param_com_flt_time_max.get() > 0) {
const float remaining_flight_time_sec = (context.status().takeoff_time < hrt_absolute_time()) ?
_param_com_flt_time_max.get() - 1.e-6f * (hrt_absolute_time() - context.status().takeoff_time) :
_param_com_flt_time_max.get();
if (remaining_flight_time_sec < 0.1f * _param_com_flt_time_max.get()) {
// send warnings every minute until RTL
const int floored_remaining_flight_time_sec = int(remaining_flight_time_sec);
if (floored_remaining_flight_time_sec <= 60 && _last_flight_time_warning_sec == -1) {
// less than or equal to a minute remaining on first pass
if (reporter.mavlink_log_pub()) {
mavlink_log_warning(reporter.mavlink_log_pub(), "Approaching max flight time (system will RTL in %i seconds)\t",
floored_remaining_flight_time_sec);
}
/* EVENT
* @description
* Maximal flight time warning (less than 1min remaining)
*/
events::send<int16_t>(events::ID("commander_max_flight_time_warning_seconds"), events::Log::Warning,
"Approaching max flight time (system will RTL in {1} seconds)", floored_remaining_flight_time_sec);
} else if ((floored_remaining_flight_time_sec % 60) == 0 && floored_remaining_flight_time_sec >= 60
&& floored_remaining_flight_time_sec != _last_flight_time_warning_sec) {
const int floored_remaining_flight_time_min = (int)(remaining_flight_time_sec * 0.016666667f);
if (reporter.mavlink_log_pub()) {
mavlink_log_warning(reporter.mavlink_log_pub(), "Approaching max flight time (system will RTL in %i minutes)\t",
floored_remaining_flight_time_min);
}
/* EVENT
* @description
* Maximal flight time warning (more than 1min remaining)
*/
events::send<int16_t>(events::ID("commander_max_flight_time_warning_minutes"), events::Log::Warning,
"Approaching max flight time (system will RTL in {1} minutes)", floored_remaining_flight_time_min);
}
_last_flight_time_warning_sec = floored_remaining_flight_time_sec;
} else {
_last_flight_time_warning_sec = -1; //reset if not in last 10%
}
} else {
_last_flight_time_warning_sec = -1; //reset if not enabled, landed or currently already exceeded
}
}

View File

@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (c) 2022 PX4 Development Team. All rights reserved.
* Copyright (c) 2022-2023 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -44,6 +44,8 @@ public:
void checkAndReport(const Context &context, Report &reporter) override;
private:
int _last_flight_time_warning_sec{-1};
DEFINE_PARAMETERS_CUSTOM_PARENT(HealthAndArmingCheckBase,
(ParamInt<px4::params::COM_FLT_TIME_MAX>) _param_com_flt_time_max
)