From d4738d87dab3461474c7a5c3a9c620bcf19578c5 Mon Sep 17 00:00:00 2001 From: Loki077 Date: Mon, 26 Aug 2024 12:44:01 +1000 Subject: [PATCH] AP_ICEngine: add max retrial of cranking Added Param MAX_RETRY which If set 0 then there is no limit to retrials. If set to a value greater than 0 then the engine will retry starting the engine this many times before giving up --- libraries/AP_ICEngine/AP_ICEngine.cpp | 18 ++++++++++++++++-- libraries/AP_ICEngine/AP_ICEngine.h | 4 ++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/libraries/AP_ICEngine/AP_ICEngine.cpp b/libraries/AP_ICEngine/AP_ICEngine.cpp index 12ec2b02dd1132..3693d7162fa013 100644 --- a/libraries/AP_ICEngine/AP_ICEngine.cpp +++ b/libraries/AP_ICEngine/AP_ICEngine.cpp @@ -167,6 +167,12 @@ const AP_Param::GroupInfo AP_ICEngine::var_info[] = { // 18 was IGNITION_RLY + // @Param: MAX_RETRY + // @DisplayName: Maximum number of retries + // @Description: If set 0 then there is no limit to retrials. If set to a value greater than 0 then the engine will retry starting the engine this many times before giving up. + // @User: Standard + // @Range: 0 254 + AP_GROUPINFO("MAX_RETRY", 19, AP_ICEngine, max_crank_retry, 0), AP_GROUPEND }; @@ -340,8 +346,14 @@ void AP_ICEngine::update(void) if (!AP::rpm()->get_rpm(rpm_instance-1, rpm_value) || rpm_value < rpm_threshold) { // engine has stopped when it should be running - state = ICE_START_DELAY; - GCS_SEND_TEXT(MAV_SEVERITY_INFO, "Uncommanded engine stop"); + if (max_crank_retry == 0 || crank_retry_ct < max_crank_retry) { + state = ICE_START_DELAY; + crank_retry_ct++; + GCS_SEND_TEXT(MAV_SEVERITY_INFO, "Uncommanded engine stop"); + } else { + state = ICE_OFF; + GCS_SEND_TEXT(MAV_SEVERITY_INFO, "Engine Max Crank Retry reached"); + } } } #endif @@ -360,6 +372,8 @@ void AP_ICEngine::update(void) // force ignition off when disarmed state = ICE_OFF; } + // reset the crank retry counter when disarmed + crank_retry_ct = 0; } #if AP_RPM_ENABLED diff --git a/libraries/AP_ICEngine/AP_ICEngine.h b/libraries/AP_ICEngine/AP_ICEngine.h index 419b6a62bc70fa..4a448a9d8feffd 100644 --- a/libraries/AP_ICEngine/AP_ICEngine.h +++ b/libraries/AP_ICEngine/AP_ICEngine.h @@ -112,6 +112,10 @@ class AP_ICEngine { AP_Int16 pwm_ignition_off; AP_Int16 pwm_starter_on; AP_Int16 pwm_starter_off; + + // max crank retry + AP_Int8 max_crank_retry; + int8_t crank_retry_ct; #if AP_RPM_ENABLED // RPM above which engine is considered to be running