From aa6f9280e12948a8050dc0e61ae0290e4d69e853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Fri, 3 Apr 2020 11:48:43 +0200 Subject: [PATCH] fix commander: set _have_taken_off_since_arming when !landed upon arming If arming and already !landed, _have_taken_off_since_arming will not be set and thus auto-disarm after 10s will be triggered (with default config). This can only happen due to quick state changes, as land detector generally sets landed=true if !armed. --- src/modules/commander/Commander.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/modules/commander/Commander.cpp b/src/modules/commander/Commander.cpp index 752121c886..4bdc9190f8 100644 --- a/src/modules/commander/Commander.cpp +++ b/src/modules/commander/Commander.cpp @@ -2189,7 +2189,12 @@ Commander::run() if (_was_armed != armed.armed) { _status_changed = true; - if (!armed.armed) { // increase the flight uuid upon disarming + if (armed.armed) { + if (!_land_detector.landed) { // check if takeoff already detected upon arming + _have_taken_off_since_arming = true; + } + + } else { // increase the flight uuid upon disarming const int32_t flight_uuid = _param_flight_uuid.get() + 1; _param_flight_uuid.set(flight_uuid); _param_flight_uuid.commit_no_notification(); @@ -2198,6 +2203,11 @@ Commander::run() } } + if (!armed.armed) { + /* Reset the flag if disarmed. */ + _have_taken_off_since_arming = false; + } + _was_armed = armed.armed; /* now set navigation state according to failsafe and main state */ @@ -2359,11 +2369,6 @@ Commander::run() _status_changed = false; - if (!armed.armed) { - /* Reset the flag if disarmed. */ - _have_taken_off_since_arming = false; - } - arm_auth_update(now, params_updated || param_init_forced); px4_usleep(COMMANDER_MONITORING_INTERVAL);