From bc0befc7378af1df5d7a15f4d3e06dfac1209df5 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 4 May 2022 10:06:57 +1000 Subject: [PATCH] AP_Generator: mask MaintenanceRequired out from error bits in prearm Turns out the generator sets this bit when it reaches the maintenance-required state. Mask it out from the error bits so the user can still fly. Add some periodically-run code to complain about maintenance-required, separate from the prearm checks. --- .../AP_Generator/AP_Generator_RichenPower.cpp | 33 ++++++++++++++++--- .../AP_Generator/AP_Generator_RichenPower.h | 6 ++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/libraries/AP_Generator/AP_Generator_RichenPower.cpp b/libraries/AP_Generator/AP_Generator_RichenPower.cpp index 210bcb58f6..de32606ed6 100644 --- a/libraries/AP_Generator/AP_Generator_RichenPower.cpp +++ b/libraries/AP_Generator/AP_Generator_RichenPower.cpp @@ -194,6 +194,23 @@ constexpr float AP_Generator_RichenPower::heat_required_for_run() } +void AP_Generator_RichenPower::check_maintenance_required() +{ + // don't bother the user while flying: + if (hal.util->get_soft_armed()) { + return; + } + + const uint32_t now = AP_HAL::millis(); + + if (last_reading.errors & (1U< 60000) { + gcs().send_text(MAV_SEVERITY_NOTICE, "Generator: requires maintenance"); + last_maintenance_warning_ms = now; + } + } +} + /* update the state of the sensor */ @@ -205,6 +222,7 @@ void AP_Generator_RichenPower::update(void) if (last_reading_ms != 0) { update_runstate(); + check_maintenance_required(); } (void)get_reading(); @@ -335,17 +353,22 @@ bool AP_Generator_RichenPower::pre_arm_check(char *failmsg, uint8_t failmsg_len) hal.util->snprintf(failmsg, failmsg_len, "no messages in %ums", unsigned(now - last_reading_ms)); return false; } - if (last_reading.seconds_until_maintenance == 0) { - hal.util->snprintf(failmsg, failmsg_len, "requires maintenance"); - } if (SRV_Channels::get_channel_for(SRV_Channel::k_generator_control) == nullptr) { hal.util->snprintf(failmsg, failmsg_len, "need a servo output channel"); return false; } - if (last_reading.errors) { + uint16_t errors = last_reading.errors; + + // requiring maintenance isn't something that should stop + // people flying - they have work to do. But we definitely + // complain about it - a lot. + errors &= ~(1U << uint16_t(Errors::MaintenanceRequired)); + + if (errors) { + for (uint16_t i=0; i<16; i++) { - if (last_reading.errors & (1U << (uint16_t)i)) { + if (errors & (1U << i)) { if (i < (uint16_t)Errors::LAST) { hal.util->snprintf(failmsg, failmsg_len, "error: %s", error_strings[i]); } else { diff --git a/libraries/AP_Generator/AP_Generator_RichenPower.h b/libraries/AP_Generator/AP_Generator_RichenPower.h index d861ea19be..cbc6d85246 100644 --- a/libraries/AP_Generator/AP_Generator_RichenPower.h +++ b/libraries/AP_Generator/AP_Generator_RichenPower.h @@ -204,5 +204,11 @@ private: } return AP_HAL::millis() - idle_state_start_ms; } + + // check if the generator requires maintenance and send a message if it does: + void check_maintenance_required(); + // if we are emitting warnings about the generator requiring + // maintenamce, this is the last time we sent the warning: + uint32_t last_maintenance_warning_ms; }; #endif