Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 133a6e3

Browse files
committed
commander: make battery warning state sticky while armed
Signed-off-by: RomanBapst <[email protected]>
1 parent e360dd3 commit 133a6e3

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

src/modules/commander/Commander.cpp

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3968,6 +3968,27 @@ void Commander::battery_status_check()
39683968

39693969
if (_battery_sub.copy(&battery)) {
39703970

3971+
3972+
bool battery_warning_level_increased_while_armed = false;
3973+
bool update_internal_battery_state = false;
3974+
3975+
if (armed.armed) {
3976+
if (battery.warning > _battery_warning) {
3977+
battery_warning_level_increased_while_armed = true;
3978+
update_internal_battery_state = true;
3979+
}
3980+
3981+
} else {
3982+
if (_battery_warning != battery.warning) {
3983+
update_internal_battery_state = true;
3984+
}
3985+
}
3986+
3987+
if (update_internal_battery_state) {
3988+
_battery_warning = battery.warning;
3989+
}
3990+
3991+
39713992
if ((hrt_elapsed_time(&battery.timestamp) < 5_s)
39723993
&& battery.connected
39733994
&& (_battery_warning == battery_status_s::BATTERY_WARNING_NONE)) {
@@ -3978,18 +3999,16 @@ void Commander::battery_status_check()
39783999
status_flags.condition_battery_healthy = false;
39794000
}
39804001

3981-
// execute battery failsafe if the state has gotten worse
3982-
if (armed.armed) {
3983-
if (battery.warning > _battery_warning) {
3984-
battery_failsafe(&mavlink_log_pub, status, status_flags, &internal_state, battery.warning,
3985-
(low_battery_action_t)_param_com_low_bat_act.get());
3986-
}
4002+
// execute battery failsafe if the state has gotten worse while we are armed
4003+
if (battery_warning_level_increased_while_armed) {
4004+
battery_failsafe(&mavlink_log_pub, status, status_flags, &internal_state, battery.warning,
4005+
(low_battery_action_t)_param_com_low_bat_act.get());
39874006
}
39884007

39894008
// Handle shutdown request from emergency battery action
3990-
if (battery.warning != _battery_warning) {
4009+
if (update_internal_battery_state) {
39914010

3992-
if ((battery.warning == battery_status_s::BATTERY_WARNING_EMERGENCY) && shutdown_if_allowed()) {
4011+
if ((_battery_warning == battery_status_s::BATTERY_WARNING_EMERGENCY) && shutdown_if_allowed()) {
39934012
mavlink_log_critical(&mavlink_log_pub, "Dangerously low battery! Shutting system down");
39944013
px4_usleep(200000);
39954014

@@ -4004,8 +4023,6 @@ void Commander::battery_status_check()
40044023
}
40054024
}
40064025

4007-
// save last value
4008-
_battery_warning = battery.warning;
40094026
_battery_current = battery.current_filtered_a;
40104027
}
40114028
}

0 commit comments

Comments
 (0)