Skip to content

Commit

Permalink
AP_ICEngine: add max retrial of cranking
Browse files Browse the repository at this point in the history
Added Param MAX_RETRY which If set 0 or less, 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.
  • Loading branch information
loki077 committed Sep 3, 2024
1 parent 7a93063 commit 1bb4a94
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
24 changes: 19 additions & 5 deletions libraries/AP_ICEngine/AP_ICEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ const AP_Param::GroupInfo AP_ICEngine::var_info[] = {
// This allows one time conversion while allowing user to flash between versions with and without converted params
AP_GROUPINFO_FLAGS("FMT_VER", 19, AP_ICEngine, param_format_version, 0, AP_PARAM_FLAG_HIDDEN),

// @Param: STRT_MX_RTRY
// @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 127
AP_GROUPINFO("STRT_MX_RTRY", 20, AP_ICEngine, max_crank_retry, 0),

AP_GROUPEND
};

Expand Down Expand Up @@ -374,6 +381,7 @@ void AP_ICEngine::update(void)
if (should_run) {
state = ICE_START_DELAY;
}
crank_retry_ct = 0;
break;

case ICE_START_HEIGHT_DELAY: {
Expand All @@ -397,8 +405,14 @@ void AP_ICEngine::update(void)
if (!should_run) {
state = ICE_OFF;
} else if (now - starter_last_run_ms >= starter_delay*1000) {
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "Starting engine");
state = ICE_STARTING;
// check if we should retry starting the engine
if (max_crank_retry >= 0 && (max_crank_retry == 0 || crank_retry_ct < max_crank_retry)) {
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "Starting engine");
state = ICE_STARTING;
crank_retry_ct++;
} else {
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "Engine Max Crank Retry reached");
}
}
break;

Expand All @@ -422,9 +436,9 @@ void AP_ICEngine::update(void)
float rpm_value;
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");
// engine has stopped when it should be running
state = ICE_START_DELAY;
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "Uncommanded engine stop");
}
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions libraries/AP_ICEngine/AP_ICEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ class AP_ICEngine {
// delay between start attempts (seconds)
AP_Float starter_delay;

// 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
AP_Int32 rpm_threshold;
Expand Down

0 comments on commit 1bb4a94

Please sign in to comment.