Skip to content

Commit

Permalink
AP_BattMonitor: Add the battery critical action delay time
Browse files Browse the repository at this point in the history
  • Loading branch information
muramura committed Oct 21, 2024
1 parent a22e28c commit 462d2bb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
9 changes: 6 additions & 3 deletions libraries/AP_BattMonitor/AP_BattMonitor_Backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,12 @@ AP_BattMonitor::Failsafe AP_BattMonitor_Backend::update_failsafes(void)
// this is the first time our voltage has dropped below minimum so start timer
if (_state.critical_voltage_start_ms == 0) {
_state.critical_voltage_start_ms = now;
} else if (_params._low_voltage_timeout > 0 &&
now - _state.critical_voltage_start_ms > uint32_t(_params._low_voltage_timeout)*1000U) {
return AP_BattMonitor::Failsafe::Critical;
} else {
int32_t voltage_timeout = _params._crt_voltage_timeout > 0 ? _params._crt_voltage_timeout : _params._low_voltage_timeout*1000;
if (voltage_timeout > 0 &&
now - _state.critical_voltage_start_ms > uint32_t(voltage_timeout)) {
return AP_BattMonitor::Failsafe::Critical;
}
}
} else {
// acceptable voltage so reset timer
Expand Down
11 changes: 11 additions & 0 deletions libraries/AP_BattMonitor/AP_BattMonitor_Params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ const AP_Param::GroupInfo AP_BattMonitor_Params::var_info[] = {
AP_GROUPINFO("ESC_INDEX", 22, AP_BattMonitor_Params, _esc_telem_outbound_index, 0),
#endif

#ifndef HAL_BUILD_AP_PERIPH
// @Param: CRT_TIMER
// @DisplayName: Critical voltage timeout
// @Description: This is the timeout in milli-seconds before a critical voltage event will be triggered. For aircraft with low C batteries it may be necessary to raise this in order to cope with critical voltage on long takeoffs. A value of zero disables critical voltage errors.
// @Units: ms
// @Increment: 1
// @Range: 0 120000
// @User: Advanced
AP_GROUPINFO("CRT_TIMER", 23, AP_BattMonitor_Params, _crt_voltage_timeout, 0),
#endif // HAL_BUILD_AP_PERIPH

AP_GROUPEND

};
Expand Down
1 change: 1 addition & 0 deletions libraries/AP_BattMonitor/AP_BattMonitor_Params.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class AP_BattMonitor_Params {
#endif
AP_Int8 _type; /// 0=disabled, 3=voltage only, 4=voltage and current
AP_Int8 _low_voltage_timeout; /// timeout in seconds before a low voltage event will be triggered
AP_Int32 _crt_voltage_timeout; /// timeout in milli-seconds before a critical voltage event will be triggered
AP_Int8 _failsafe_voltage_source; /// voltage type used for detection of low voltage event
AP_Int8 _failsafe_low_action; /// action to preform on a low battery failsafe
AP_Int8 _failsafe_critical_action; /// action to preform on a critical battery failsafe
Expand Down

0 comments on commit 462d2bb

Please sign in to comment.