diff --git a/src/modules/commander/HealthAndArmingChecks/checks/flightTimeCheck.cpp b/src/modules/commander/HealthAndArmingChecks/checks/flightTimeCheck.cpp index 85b68a8485..d5e122935d 100644 --- a/src/modules/commander/HealthAndArmingChecks/checks/flightTimeCheck.cpp +++ b/src/modules/commander/HealthAndArmingChecks/checks/flightTimeCheck.cpp @@ -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(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(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 + } } diff --git a/src/modules/commander/HealthAndArmingChecks/checks/flightTimeCheck.hpp b/src/modules/commander/HealthAndArmingChecks/checks/flightTimeCheck.hpp index a4350886fb..b49ec6186f 100644 --- a/src/modules/commander/HealthAndArmingChecks/checks/flightTimeCheck.hpp +++ b/src/modules/commander/HealthAndArmingChecks/checks/flightTimeCheck.hpp @@ -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) _param_com_flt_time_max )