From 80f0892de586bd68968319748414f1cb62e69ca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Fri, 3 Apr 2020 11:51:29 +0200 Subject: [PATCH] fix commander: set _was_landed before _land_detector topic update Before _was_landed was set to the same value as the current _land_detector.landed, thus outside of the update condition, _was_landed && !_land_detector.landed could never be true. This affects setting the home position, which is now set upon arming AND upon takeoff. --- src/modules/commander/Commander.cpp | 7 +++---- src/modules/commander/Commander.hpp | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/modules/commander/Commander.cpp b/src/modules/commander/Commander.cpp index 4bdc9190f8..72acce0574 100644 --- a/src/modules/commander/Commander.cpp +++ b/src/modules/commander/Commander.cpp @@ -1552,6 +1552,8 @@ Commander::run() /* Update land detector */ if (_land_detector_sub.updated()) { + _was_landed = _land_detector.landed; + bool was_falling = _land_detector.freefall; _land_detector_sub.copy(&_land_detector); // Only take actions if armed @@ -1573,15 +1575,12 @@ Commander::run() } } - if (_was_falling != _land_detector.freefall) { + if (was_falling != _land_detector.freefall) { if (_land_detector.freefall) { mavlink_and_console_log_info(&mavlink_log_pub, "Freefall detected"); } } } - - _was_landed = _land_detector.landed; - _was_falling = _land_detector.freefall; } diff --git a/src/modules/commander/Commander.hpp b/src/modules/commander/Commander.hpp index a10f64b13a..e3485f18f5 100644 --- a/src/modules/commander/Commander.hpp +++ b/src/modules/commander/Commander.hpp @@ -362,7 +362,6 @@ private: bool _status_changed{true}; bool _arm_tune_played{false}; bool _was_landed{true}; - bool _was_falling{false}; bool _was_armed{false}; bool _failsafe_old{false}; ///< check which state machines for changes, clear "changed" flag bool _have_taken_off_since_arming{false};