From 73ca0184ce779678eba589fdcbce3df00fa90bd9 Mon Sep 17 00:00:00 2001 From: breadoven <56191411+breadoven@users.noreply.github.com> Date: Fri, 2 Oct 2020 12:33:26 +0100 Subject: [PATCH 01/14] Fix Naming --- src/main/navigation/navigation.c | 16 ++++++++-------- src/main/navigation/navigation_private.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/navigation/navigation.c b/src/main/navigation/navigation.c index 602de217295..7a88409071b 100755 --- a/src/main/navigation/navigation.c +++ b/src/main/navigation/navigation.c @@ -222,7 +222,7 @@ static navigationFSMEvent_t nextForNonGeoStates(void); void initializeRTHSanityChecker(const fpVector3_t * pos); bool validateRTHSanityChecker(void); -static void OverRideRTHAtitudePreset(void); +static void overrideRTHAtitudePreset(void); /*************************************************************************************************/ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_IDLE(navigationFSMState_t previousState); @@ -1086,7 +1086,7 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_RTH_INITIALIZE(navigati { navigationFSMStateFlags_t prevFlags = navGetStateFlags(previousState); - posControl.flags.CanOverRideRTHAlt = false; //prevent unwanted override if AltHold selected at RTH initialize + posControl.flags.canOverrideRTHAlt = false; //prevent unwanted override if AltHold selected at RTH initialize if ((posControl.flags.estHeadingStatus == EST_NONE) || (posControl.flags.estAltStatus == EST_NONE) || (posControl.flags.estPosStatus != EST_TRUSTED) || !STATE(GPS_FIX_HOME)) { // Heading sensor, altitude sensor and HOME fix are mandatory for RTH. If not satisfied - switch to emergency landing @@ -1150,20 +1150,20 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_RTH_INITIALIZE(navigati } } -static void OverRideRTHAtitudePreset(void) +static void overrideRTHAtitudePreset(void) { if (!navConfig()->general.flags.rth_alt_control_override) { return; } if (!IS_RC_MODE_ACTIVE(BOXNAVALTHOLD)) { - posControl.flags.CanOverRideRTHAlt = true; + posControl.flags.canOverrideRTHAlt = true; } else { - if (posControl.flags.CanOverRideRTHAlt && !posControl.flags.forcedRTHActivated) { + if (posControl.flags.canOverrideRTHAlt && !posControl.flags.forcedRTHActivated) { posControl.rthState.rthInitialAltitude = posControl.actualState.abs.pos.z; posControl.rthState.rthFinalAltitude = posControl.rthState.rthInitialAltitude; - posControl.flags.CanOverRideRTHAlt = false; + posControl.flags.canOverrideRTHAlt = false; } } } @@ -1172,7 +1172,7 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_RTH_CLIMB_TO_SAFE_ALT(n { UNUSED(previousState); - OverRideRTHAtitudePreset(); + overrideRTHAtitudePreset(); if ((posControl.flags.estHeadingStatus == EST_NONE)) { return NAV_FSM_EVENT_SWITCH_TO_EMERGENCY_LANDING; @@ -1248,7 +1248,7 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_RTH_HEAD_HOME(navigatio { UNUSED(previousState); - OverRideRTHAtitudePreset(); + overrideRTHAtitudePreset(); if ((posControl.flags.estHeadingStatus == EST_NONE)) { return NAV_FSM_EVENT_SWITCH_TO_EMERGENCY_LANDING; diff --git a/src/main/navigation/navigation_private.h b/src/main/navigation/navigation_private.h index 8457c46dbbd..53583caca11 100755 --- a/src/main/navigation/navigation_private.h +++ b/src/main/navigation/navigation_private.h @@ -87,7 +87,7 @@ typedef struct navigationFlags_s { bool isTerrainFollowEnabled; // Does iNav use rangefinder for terrain following (adjusting baro altitude target according to rangefinders readings) bool forcedRTHActivated; - bool CanOverRideRTHAlt; //RTH climb altitude override possible + bool canOverrideRTHAlt; //RTH climb altitude override is possible } navigationFlags_t; typedef enum { From 181a1ce9e5fde17f73069f4f957a6b7721fc74f9 Mon Sep 17 00:00:00 2001 From: breadoven <56191411+breadoven@users.noreply.github.com> Date: Sun, 15 Nov 2020 21:49:12 +0000 Subject: [PATCH 02/14] Fix Merge Correction Errors --- src/main/navigation/navigation.c | 1 - src/main/navigation/navigation.h | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/navigation/navigation.c b/src/main/navigation/navigation.c index 8991966ebf3..f42c04fdda9 100755 --- a/src/main/navigation/navigation.c +++ b/src/main/navigation/navigation.c @@ -107,7 +107,6 @@ PG_RESET_TEMPLATE(navConfig_t, navConfig, .disarm_on_landing = 0, .rth_allow_landing = NAV_RTH_ALLOW_LANDING_ALWAYS, .rth_alt_control_override = 0, //set using nav_rth_alt_control_override - .auto_overrides_motor_stop = 1, .nav_overrides_motor_stop = NOMS_ALL_NAV, }, diff --git a/src/main/navigation/navigation.h b/src/main/navigation/navigation.h index 4efea10dc7b..9457b902ff3 100755 --- a/src/main/navigation/navigation.h +++ b/src/main/navigation/navigation.h @@ -182,8 +182,7 @@ typedef struct navConfig_s { uint8_t rth_allow_landing; // Enable landing as last stage of RTH. Use constants in navRTHAllowLanding_e. uint8_t rth_climb_ignore_emerg; // Option to ignore GPS loss on initial climb stage of RTH uint8_t rth_alt_control_override; // Set RTH preset climb altitude to Current altutude during climb using AltHold mode switch - uint8_t auto_overrides_motor_stop; // Autonomous modes override motor_stop setting and user command to stop motor - uint8_t nav_overrides_motor_stop; // Autonomous modes override motor_stop setting and user command to stop motor + uint8_t nav_overrides_motor_stop; // Autonomous modes override motor_stop setting and user command to stop motor } flags; uint8_t pos_failure_timeout; // Time to wait before switching to emergency landing (0 - disable) From 8f2c2620efd46922614f762f2d19a972195aee7a Mon Sep 17 00:00:00 2001 From: breadoven <56191411+breadoven@users.noreply.github.com> Date: Tue, 17 Nov 2020 21:15:37 +0000 Subject: [PATCH 03/14] Change Control to Pitch Stick Override trigger changed from AlfHold mode to pitch stick input. --- src/main/fc/settings.yaml | 2 +- src/main/navigation/navigation.c | 47 ++++++++++++++---------- src/main/navigation/navigation.h | 2 +- src/main/navigation/navigation_private.h | 1 - 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/main/fc/settings.yaml b/src/main/fc/settings.yaml index 38994493e52..60051e6a784 100644 --- a/src/main/fc/settings.yaml +++ b/src/main/fc/settings.yaml @@ -2137,7 +2137,7 @@ groups: field: general.flags.rth_alt_control_mode table: nav_rth_alt_mode - name: nav_rth_alt_control_override - description: "If set to ON RTH climb will stop and maintain altitude acheived when AltHold mode is switched ON, overriding preset climb altitude" + description: "If set to ON the preset RTH altitude can be overridden during the climb phase, resetting to the current altitude, by holding the pitch stick in the full pitch down position for longer than 1 second" default_value: "OFF" field: general.flags.rth_alt_control_override type: bool diff --git a/src/main/navigation/navigation.c b/src/main/navigation/navigation.c index f42c04fdda9..cba13e7a419 100755 --- a/src/main/navigation/navigation.c +++ b/src/main/navigation/navigation.c @@ -1092,8 +1092,6 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_CRUISE_3D_ADJUSTING(nav static navigationFSMEvent_t navOnEnteringState_NAV_STATE_RTH_INITIALIZE(navigationFSMState_t previousState) { navigationFSMStateFlags_t prevFlags = navGetStateFlags(previousState); - - posControl.flags.canOverrideRTHAlt = false; //prevent unwanted override if AltHold selected at RTH initialize if ((posControl.flags.estHeadingStatus == EST_NONE) || (posControl.flags.estAltStatus == EST_NONE) || (posControl.flags.estPosStatus != EST_TRUSTED) || !STATE(GPS_FIX_HOME)) { // Heading sensor, altitude sensor and HOME fix are mandatory for RTH. If not satisfied - switch to emergency landing @@ -1157,24 +1155,6 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_RTH_INITIALIZE(navigati } } -static void overrideRTHAtitudePreset(void) -{ - if (!navConfig()->general.flags.rth_alt_control_override) { - return; - } - - if (!IS_RC_MODE_ACTIVE(BOXNAVALTHOLD)) { - posControl.flags.canOverrideRTHAlt = true; - } - else { - if (posControl.flags.canOverrideRTHAlt && !posControl.flags.forcedRTHActivated) { - posControl.rthState.rthInitialAltitude = posControl.actualState.abs.pos.z; - posControl.rthState.rthFinalAltitude = posControl.rthState.rthInitialAltitude; - posControl.flags.canOverrideRTHAlt = false; - } - } -} - static navigationFSMEvent_t navOnEnteringState_NAV_STATE_RTH_CLIMB_TO_SAFE_ALT(navigationFSMState_t previousState) { UNUSED(previousState); @@ -2531,6 +2511,33 @@ void updateHomePosition(void) } } +/* ----------------------------------------------------------- + * Override preset RTH altitude to current altitude + *-----------------------------------------------------------*/ +static void overrideRTHAtitudePreset(void) +{ + if (!navConfig()->general.flags.rth_alt_control_override) { + return; + } + + static timeMs_t PitchStickHoldStartTime; + + if (rxGetChannelValue(PITCH) > 1900) { + if (!PitchStickHoldStartTime) { + PitchStickHoldStartTime = millis(); + } else { + timeMs_t currentTime = millis(); + if (currentTime - PitchStickHoldStartTime > 1000 && !posControl.flags.forcedRTHActivated) { + posControl.rthState.rthInitialAltitude = posControl.actualState.abs.pos.z; + posControl.rthState.rthFinalAltitude = posControl.rthState.rthInitialAltitude; + } + } + } else { + PitchStickHoldStartTime = 0; + } + DEBUG_SET(DEBUG_CRUISE, 1, PitchStickHoldStartTime); +} + /*----------------------------------------------------------- * Update flight statistics *-----------------------------------------------------------*/ diff --git a/src/main/navigation/navigation.h b/src/main/navigation/navigation.h index 9457b902ff3..7b9c30606ef 100755 --- a/src/main/navigation/navigation.h +++ b/src/main/navigation/navigation.h @@ -181,7 +181,7 @@ typedef struct navConfig_s { uint8_t disarm_on_landing; // uint8_t rth_allow_landing; // Enable landing as last stage of RTH. Use constants in navRTHAllowLanding_e. uint8_t rth_climb_ignore_emerg; // Option to ignore GPS loss on initial climb stage of RTH - uint8_t rth_alt_control_override; // Set RTH preset climb altitude to Current altutude during climb using AltHold mode switch + uint8_t rth_alt_control_override; // Set RTH preset climb altitude to Current altutude during climb using full down pitch stick uint8_t nav_overrides_motor_stop; // Autonomous modes override motor_stop setting and user command to stop motor } flags; diff --git a/src/main/navigation/navigation_private.h b/src/main/navigation/navigation_private.h index 53583caca11..fcae1b7dedf 100755 --- a/src/main/navigation/navigation_private.h +++ b/src/main/navigation/navigation_private.h @@ -87,7 +87,6 @@ typedef struct navigationFlags_s { bool isTerrainFollowEnabled; // Does iNav use rangefinder for terrain following (adjusting baro altitude target according to rangefinders readings) bool forcedRTHActivated; - bool canOverrideRTHAlt; //RTH climb altitude override is possible } navigationFlags_t; typedef enum { From 011533be5266d6b811d7a8cebc8a576ec371f0f6 Mon Sep 17 00:00:00 2001 From: breadoven <56191411+breadoven@users.noreply.github.com> Date: Tue, 17 Nov 2020 22:10:27 +0000 Subject: [PATCH 04/14] Update navigation.c Fix tabs --- src/main/navigation/navigation.c | 34 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/navigation/navigation.c b/src/main/navigation/navigation.c index cba13e7a419..b27dc60a893 100755 --- a/src/main/navigation/navigation.c +++ b/src/main/navigation/navigation.c @@ -106,7 +106,7 @@ PG_RESET_TEMPLATE(navConfig_t, navConfig, .rth_tail_first = 0, .disarm_on_landing = 0, .rth_allow_landing = NAV_RTH_ALLOW_LANDING_ALWAYS, - .rth_alt_control_override = 0, //set using nav_rth_alt_control_override + .rth_alt_control_override = 0, //Override the preset RTH altitude to the current altitude .nav_overrides_motor_stop = NOMS_ALL_NAV, }, @@ -2520,22 +2520,22 @@ static void overrideRTHAtitudePreset(void) return; } - static timeMs_t PitchStickHoldStartTime; - - if (rxGetChannelValue(PITCH) > 1900) { - if (!PitchStickHoldStartTime) { - PitchStickHoldStartTime = millis(); - } else { - timeMs_t currentTime = millis(); - if (currentTime - PitchStickHoldStartTime > 1000 && !posControl.flags.forcedRTHActivated) { - posControl.rthState.rthInitialAltitude = posControl.actualState.abs.pos.z; - posControl.rthState.rthFinalAltitude = posControl.rthState.rthInitialAltitude; - } - } - } else { - PitchStickHoldStartTime = 0; - } - DEBUG_SET(DEBUG_CRUISE, 1, PitchStickHoldStartTime); + static timeMs_t PitchStickHoldStartTime; + + if (rxGetChannelValue(PITCH) > 1900) { + if (!PitchStickHoldStartTime) { + PitchStickHoldStartTime = millis(); + } else { + timeMs_t currentTime = millis(); + if (currentTime - PitchStickHoldStartTime > 1000 && !posControl.flags.forcedRTHActivated) { + posControl.rthState.rthInitialAltitude = posControl.actualState.abs.pos.z; + posControl.rthState.rthFinalAltitude = posControl.rthState.rthInitialAltitude; + } + } + } else { + PitchStickHoldStartTime = 0; + } + DEBUG_SET(DEBUG_CRUISE, 1, PitchStickHoldStartTime); } /*----------------------------------------------------------- From 7dbc27c81af7216378c84ad8f6031af7d9d0d858 Mon Sep 17 00:00:00 2001 From: breadoven <56191411+breadoven@users.noreply.github.com> Date: Wed, 25 Nov 2020 18:53:16 +0000 Subject: [PATCH 05/14] Update to add RTH Climb First override RTH Climb First override added using roll stick. RTH altitude override - pitch down stick RTH Climb First override - roll right stick Stick hold for > 2 seconds. --- src/main/navigation/navigation.c | 40 ++++++++++++++---------- src/main/navigation/navigation_private.h | 1 + 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/main/navigation/navigation.c b/src/main/navigation/navigation.c index b27dc60a893..067f429e91f 100755 --- a/src/main/navigation/navigation.c +++ b/src/main/navigation/navigation.c @@ -106,7 +106,7 @@ PG_RESET_TEMPLATE(navConfig_t, navConfig, .rth_tail_first = 0, .disarm_on_landing = 0, .rth_allow_landing = NAV_RTH_ALLOW_LANDING_ALWAYS, - .rth_alt_control_override = 0, //Override the preset RTH altitude to the current altitude + .rth_alt_control_override = 0, // Override RTH Altitude and rth_climb_first settings using Pitch and Roll stick .nav_overrides_motor_stop = NOMS_ALL_NAV, }, @@ -229,7 +229,7 @@ static navigationFSMEvent_t nextForNonGeoStates(void); void initializeRTHSanityChecker(const fpVector3_t * pos); bool validateRTHSanityChecker(void); -static void overrideRTHAtitudePreset(void); +static void rthAltControlStickOverrideCheck(unsigned axis); /*************************************************************************************************/ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_IDLE(navigationFSMState_t previousState); @@ -1092,6 +1092,9 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_CRUISE_3D_ADJUSTING(nav static navigationFSMEvent_t navOnEnteringState_NAV_STATE_RTH_INITIALIZE(navigationFSMState_t previousState) { navigationFSMStateFlags_t prevFlags = navGetStateFlags(previousState); + + // reset flag to override RTH climb first + posControl.flags.rthClimbFirstOverride = false; if ((posControl.flags.estHeadingStatus == EST_NONE) || (posControl.flags.estAltStatus == EST_NONE) || (posControl.flags.estPosStatus != EST_TRUSTED) || !STATE(GPS_FIX_HOME)) { // Heading sensor, altitude sensor and HOME fix are mandatory for RTH. If not satisfied - switch to emergency landing @@ -1159,7 +1162,8 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_RTH_CLIMB_TO_SAFE_ALT(n { UNUSED(previousState); - overrideRTHAtitudePreset(); + rthAltControlStickOverrideCheck(PITCH); + rthAltControlStickOverrideCheck(ROLL); if ((posControl.flags.estHeadingStatus == EST_NONE)) { return NAV_FSM_EVENT_SWITCH_TO_EMERGENCY_LANDING; @@ -1176,7 +1180,7 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_RTH_CLIMB_TO_SAFE_ALT(n const float rthAltitudeMargin = MAX(FW_RTH_CLIMB_MARGIN_MIN_CM, (rthClimbMarginPercent/100.0) * fabsf(posControl.rthState.rthInitialAltitude - posControl.rthState.homePosition.pos.z)); // If we reached desired initial RTH altitude or we don't want to climb first - if (((navGetCurrentActualPositionAndVelocity()->pos.z - posControl.rthState.rthInitialAltitude) > -rthAltitudeMargin) || (!navConfig()->general.flags.rth_climb_first)) { + if (((navGetCurrentActualPositionAndVelocity()->pos.z - posControl.rthState.rthInitialAltitude) > -rthAltitudeMargin) || (!navConfig()->general.flags.rth_climb_first) || posControl.flags.rthClimbFirstOverride) { // Delayed initialization for RTH sanity check on airplanes - allow to finish climb first as it can take some distance if (STATE(FIXED_WING_LEGACY)) { @@ -1235,7 +1239,7 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_RTH_HEAD_HOME(navigatio { UNUSED(previousState); - overrideRTHAtitudePreset(); + rthAltControlStickOverrideCheck(PITCH); if ((posControl.flags.estHeadingStatus == EST_NONE)) { return NAV_FSM_EVENT_SWITCH_TO_EMERGENCY_LANDING; @@ -2512,30 +2516,32 @@ void updateHomePosition(void) } /* ----------------------------------------------------------- - * Override preset RTH altitude to current altitude + * Override RTH preset altitude and Climb First option + * Set using Pitch/Roll stick held for > 2 seconds *-----------------------------------------------------------*/ -static void overrideRTHAtitudePreset(void) +static void rthAltControlStickOverrideCheck(unsigned axis) { - if (!navConfig()->general.flags.rth_alt_control_override) { + if (!navConfig()->general.flags.rth_alt_control_override || posControl.flags.forcedRTHActivated) { return; } - static timeMs_t PitchStickHoldStartTime; + static timeMs_t rthOverrideStickHoldStartTime[2]; + timeMs_t currentTime = millis(); - if (rxGetChannelValue(PITCH) > 1900) { - if (!PitchStickHoldStartTime) { - PitchStickHoldStartTime = millis(); - } else { - timeMs_t currentTime = millis(); - if (currentTime - PitchStickHoldStartTime > 1000 && !posControl.flags.forcedRTHActivated) { + if (rxGetChannelValue(axis) > rxConfig()->maxcheck) { + if (!rthOverrideStickHoldStartTime[axis]) { + rthOverrideStickHoldStartTime[axis] = millis(); + } else if (ABS(2500 - (currentTime - rthOverrideStickHoldStartTime[axis])) < 500) { + if (axis == PITCH) { // pitch down to override preset altitude reset to current altitude posControl.rthState.rthInitialAltitude = posControl.actualState.abs.pos.z; posControl.rthState.rthFinalAltitude = posControl.rthState.rthInitialAltitude; + } else { // roll right to override climb first + posControl.flags.rthClimbFirstOverride = true; } } } else { - PitchStickHoldStartTime = 0; + rthOverrideStickHoldStartTime[axis] = 0; } - DEBUG_SET(DEBUG_CRUISE, 1, PitchStickHoldStartTime); } /*----------------------------------------------------------- diff --git a/src/main/navigation/navigation_private.h b/src/main/navigation/navigation_private.h index fcae1b7dedf..5d3818d0557 100755 --- a/src/main/navigation/navigation_private.h +++ b/src/main/navigation/navigation_private.h @@ -87,6 +87,7 @@ typedef struct navigationFlags_s { bool isTerrainFollowEnabled; // Does iNav use rangefinder for terrain following (adjusting baro altitude target according to rangefinders readings) bool forcedRTHActivated; + bool rthClimbFirstOverride; // RTH Climb First override using Roll stick } navigationFlags_t; typedef enum { From 1b3ebd44754064b5199ccc8fa8145053b2b4f366 Mon Sep 17 00:00:00 2001 From: breadoven <56191411+breadoven@users.noreply.github.com> Date: Wed, 25 Nov 2020 19:14:34 +0000 Subject: [PATCH 06/14] Update settings.yaml --- src/main/fc/settings.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/fc/settings.yaml b/src/main/fc/settings.yaml index 60051e6a784..f32ae3b1726 100644 --- a/src/main/fc/settings.yaml +++ b/src/main/fc/settings.yaml @@ -2137,7 +2137,7 @@ groups: field: general.flags.rth_alt_control_mode table: nav_rth_alt_mode - name: nav_rth_alt_control_override - description: "If set to ON the preset RTH altitude can be overridden during the climb phase, resetting to the current altitude, by holding the pitch stick in the full pitch down position for longer than 1 second" + description: "If set to ON RTH altitude and CLIMB FIRST settings can be overridden during the RTH climb phase using full pitch or roll stick held for > 2 seconds. RTH altitude is reset to the current altitude using pitch down stick. RTH CLIMB FIRST is overridden using right roll stick so craft turns and heads directly to home." default_value: "OFF" field: general.flags.rth_alt_control_override type: bool From b3005fbc3c0665128967eebbd392ecdb69d0a05e Mon Sep 17 00:00:00 2001 From: breadoven <56191411+breadoven@users.noreply.github.com> Date: Wed, 25 Nov 2020 22:24:57 +0000 Subject: [PATCH 07/14] Update navigation.c Fix ABS build error --- src/main/navigation/navigation.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/navigation/navigation.c b/src/main/navigation/navigation.c index 067f429e91f..e1bbfdbfd81 100755 --- a/src/main/navigation/navigation.c +++ b/src/main/navigation/navigation.c @@ -2526,12 +2526,14 @@ static void rthAltControlStickOverrideCheck(unsigned axis) } static timeMs_t rthOverrideStickHoldStartTime[2]; - timeMs_t currentTime = millis(); if (rxGetChannelValue(axis) > rxConfig()->maxcheck) { + + timeDelta_t holdTime = millis() - rthOverrideStickHoldStartTime[axis]; + if (!rthOverrideStickHoldStartTime[axis]) { rthOverrideStickHoldStartTime[axis] = millis(); - } else if (ABS(2500 - (currentTime - rthOverrideStickHoldStartTime[axis])) < 500) { + } else if (ABS(2500 - holdTime) < 500) { if (axis == PITCH) { // pitch down to override preset altitude reset to current altitude posControl.rthState.rthInitialAltitude = posControl.actualState.abs.pos.z; posControl.rthState.rthFinalAltitude = posControl.rthState.rthInitialAltitude; From fcedba8618b201c6047c4fe960db4c98d09d0de7 Mon Sep 17 00:00:00 2001 From: breadoven <56191411+breadoven@users.noreply.github.com> Date: Sun, 29 Nov 2020 13:06:29 +0000 Subject: [PATCH 08/14] Improved Code Cleaned up code removing Climb First flag. Tested in flight, works as expected. --- src/main/navigation/navigation.c | 35 ++++++++++++------------ src/main/navigation/navigation.h | 2 +- src/main/navigation/navigation_private.h | 1 - 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/main/navigation/navigation.c b/src/main/navigation/navigation.c index e1bbfdbfd81..cb5c58ddbfc 100755 --- a/src/main/navigation/navigation.c +++ b/src/main/navigation/navigation.c @@ -229,7 +229,7 @@ static navigationFSMEvent_t nextForNonGeoStates(void); void initializeRTHSanityChecker(const fpVector3_t * pos); bool validateRTHSanityChecker(void); -static void rthAltControlStickOverrideCheck(unsigned axis); +static bool rthAltControlStickOverrideCheck(unsigned axis); /*************************************************************************************************/ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_IDLE(navigationFSMState_t previousState); @@ -1092,9 +1092,6 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_CRUISE_3D_ADJUSTING(nav static navigationFSMEvent_t navOnEnteringState_NAV_STATE_RTH_INITIALIZE(navigationFSMState_t previousState) { navigationFSMStateFlags_t prevFlags = navGetStateFlags(previousState); - - // reset flag to override RTH climb first - posControl.flags.rthClimbFirstOverride = false; if ((posControl.flags.estHeadingStatus == EST_NONE) || (posControl.flags.estAltStatus == EST_NONE) || (posControl.flags.estPosStatus != EST_TRUSTED) || !STATE(GPS_FIX_HOME)) { // Heading sensor, altitude sensor and HOME fix are mandatory for RTH. If not satisfied - switch to emergency landing @@ -1161,9 +1158,8 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_RTH_INITIALIZE(navigati static navigationFSMEvent_t navOnEnteringState_NAV_STATE_RTH_CLIMB_TO_SAFE_ALT(navigationFSMState_t previousState) { UNUSED(previousState); - + rthAltControlStickOverrideCheck(PITCH); - rthAltControlStickOverrideCheck(ROLL); if ((posControl.flags.estHeadingStatus == EST_NONE)) { return NAV_FSM_EVENT_SWITCH_TO_EMERGENCY_LANDING; @@ -1180,7 +1176,7 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_RTH_CLIMB_TO_SAFE_ALT(n const float rthAltitudeMargin = MAX(FW_RTH_CLIMB_MARGIN_MIN_CM, (rthClimbMarginPercent/100.0) * fabsf(posControl.rthState.rthInitialAltitude - posControl.rthState.homePosition.pos.z)); // If we reached desired initial RTH altitude or we don't want to climb first - if (((navGetCurrentActualPositionAndVelocity()->pos.z - posControl.rthState.rthInitialAltitude) > -rthAltitudeMargin) || (!navConfig()->general.flags.rth_climb_first) || posControl.flags.rthClimbFirstOverride) { + if (((navGetCurrentActualPositionAndVelocity()->pos.z - posControl.rthState.rthInitialAltitude) > -rthAltitudeMargin) || (!navConfig()->general.flags.rth_climb_first) || rthAltControlStickOverrideCheck(ROLL)) { // Delayed initialization for RTH sanity check on airplanes - allow to finish climb first as it can take some distance if (STATE(FIXED_WING_LEGACY)) { @@ -1238,7 +1234,7 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_RTH_CLIMB_TO_SAFE_ALT(n static navigationFSMEvent_t navOnEnteringState_NAV_STATE_RTH_HEAD_HOME(navigationFSMState_t previousState) { UNUSED(previousState); - + rthAltControlStickOverrideCheck(PITCH); if ((posControl.flags.estHeadingStatus == EST_NONE)) { @@ -2517,33 +2513,36 @@ void updateHomePosition(void) /* ----------------------------------------------------------- * Override RTH preset altitude and Climb First option - * Set using Pitch/Roll stick held for > 2 seconds + * using Pitch/Roll stick held for > 2 seconds *-----------------------------------------------------------*/ -static void rthAltControlStickOverrideCheck(unsigned axis) +static bool rthAltControlStickOverrideCheck(unsigned axis) { if (!navConfig()->general.flags.rth_alt_control_override || posControl.flags.forcedRTHActivated) { - return; + return false; } static timeMs_t rthOverrideStickHoldStartTime[2]; if (rxGetChannelValue(axis) > rxConfig()->maxcheck) { - + timeDelta_t holdTime = millis() - rthOverrideStickHoldStartTime[axis]; - + if (!rthOverrideStickHoldStartTime[axis]) { rthOverrideStickHoldStartTime[axis] = millis(); - } else if (ABS(2500 - holdTime) < 500) { - if (axis == PITCH) { // pitch down to override preset altitude reset to current altitude + } else if (ABS(2500 - holdTime) < 500) { + if (axis == PITCH) { // PITCH down to override preset altitude reset to current altitude posControl.rthState.rthInitialAltitude = posControl.actualState.abs.pos.z; - posControl.rthState.rthFinalAltitude = posControl.rthState.rthInitialAltitude; - } else { // roll right to override climb first - posControl.flags.rthClimbFirstOverride = true; + posControl.rthState.rthFinalAltitude = posControl.rthState.rthInitialAltitude; + return true; + } else if (axis == ROLL) { // ROLL right to override climb first + return true; } } } else { rthOverrideStickHoldStartTime[axis] = 0; } + + return false; } /*----------------------------------------------------------- diff --git a/src/main/navigation/navigation.h b/src/main/navigation/navigation.h index 7b9c30606ef..ac07036442c 100755 --- a/src/main/navigation/navigation.h +++ b/src/main/navigation/navigation.h @@ -181,7 +181,7 @@ typedef struct navConfig_s { uint8_t disarm_on_landing; // uint8_t rth_allow_landing; // Enable landing as last stage of RTH. Use constants in navRTHAllowLanding_e. uint8_t rth_climb_ignore_emerg; // Option to ignore GPS loss on initial climb stage of RTH - uint8_t rth_alt_control_override; // Set RTH preset climb altitude to Current altutude during climb using full down pitch stick + uint8_t rth_alt_control_override; // Override RTH Altitude and Climb First settings using Pitch and Roll stick uint8_t nav_overrides_motor_stop; // Autonomous modes override motor_stop setting and user command to stop motor } flags; diff --git a/src/main/navigation/navigation_private.h b/src/main/navigation/navigation_private.h index 5d3818d0557..fcae1b7dedf 100755 --- a/src/main/navigation/navigation_private.h +++ b/src/main/navigation/navigation_private.h @@ -87,7 +87,6 @@ typedef struct navigationFlags_s { bool isTerrainFollowEnabled; // Does iNav use rangefinder for terrain following (adjusting baro altitude target according to rangefinders readings) bool forcedRTHActivated; - bool rthClimbFirstOverride; // RTH Climb First override using Roll stick } navigationFlags_t; typedef enum { From adf5b38e3d4a13a115039d209cc8afd0cb98aa9b Mon Sep 17 00:00:00 2001 From: breadoven <56191411+breadoven@users.noreply.github.com> Date: Sun, 6 Dec 2020 10:33:42 +0000 Subject: [PATCH 09/14] Update Settings.md --- docs/Settings.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/Settings.md b/docs/Settings.md index 00999bf75a0..9aaa230afe7 100644 --- a/docs/Settings.md +++ b/docs/Settings.md @@ -277,8 +277,8 @@ | nav_fw_max_thr | 1700 | Maximum throttle for flying wing in GPS assisted modes | | nav_fw_min_thr | 1200 | Minimum throttle for flying wing in GPS assisted modes | | nav_fw_pitch2thr | 10 | Amount of throttle applied related to pitch attitude in GPS assisted modes. Throttle = nav_fw_cruise_throttle - (nav_fw_pitch2thr * pitch_angle). (notice that pitch_angle is in degrees and is negative when climbing and positive when diving, and throttle value is constrained between nav_fw_min_thr and nav_fw_max_thr) | -| nav_fw_pitch2thr_smoothing | 0 | How smoothly the autopilot makes pitch to throttle correction inside a deadband defined by pitch_to_throttle_thresh. | -| nav_fw_pitch2thr_threshold | 0 | Threshold from average pitch where momentary pitch_to_throttle correction kicks in. [decidegrees] | +| nav_fw_pitch2thr_smoothing | 6 | How smoothly the autopilot makes pitch to throttle correction inside a deadband defined by pitch_to_throttle_thresh. | +| nav_fw_pitch2thr_threshold | 50 | Threshold from average pitch where momentary pitch_to_throttle correction kicks in. [decidegrees] | | nav_fw_pos_hdg_d | 0 | D gain of heading trajectory PID controller. (Fixedwing, rovers, boats) | | nav_fw_pos_hdg_i | 0 | I gain of heading trajectory PID controller. (Fixedwing, rovers, boats) | | nav_fw_pos_hdg_p | 60 | P gain of heading PID controller. (Fixedwing, rovers, boats) | @@ -324,10 +324,11 @@ | nav_mc_vel_z_i | 50 | I gain of velocity PID controller | | nav_mc_vel_z_p | 100 | P gain of velocity PID controller | | nav_min_rth_distance | 500 | Minimum distance from homepoint when RTH full procedure will be activated [cm]. Below this distance, the mode will activate at the current location and the final phase is executed (loiter / land). Above this distance, the full procedure is activated, which may include initial climb and flying directly to the homepoint before entering the loiter / land phase. | -| nav_overrides_motor_stop | ALL_NAV | When set OFF_ALWAYS the navigation system will not take over the control of the motor if the throttle is low (motor will stop). When set to OFF always the navigation system will not take over the control of the motor if the throttle was low even when failsafe is triggered. When set to AUTO_ONLY the navigation system will only take over the control of the throttle in autonomous navigation modes (NAV WP and NAV RTH). When set to ALL_NAV (default) the navigation system will take over the control of the motor completely and never allow the motor to stop even when the throttle is low. This setting only has an effect combined with MOTOR_STOP and is likely to cause a stall if fw_min_throttle_down_pitch isn't set correctly or the pitch estimation is wrong for fixed wing models when not set to ALL_NAV | +| nav_overrides_motor_stop | ALL_NAV | When set OFF_ALWAYS the navigation system will not take over the control of the motor if the throttle is low (motor will stop). When set to OFF always the navigation system will not take over the control of the motor if the throttle was low even when failsafe is triggered. When set to AUTO_ONLY the navigation system will only take over the control of the throttle in autonomous navigation modes (NAV WP and NAV RTH). When set to ALL_NAV (default) the navigation system will take over the control of the motor completely and never allow the motor to stop even when the throttle is low. This setting only has an effect on NAV modes which take control of the throttle when combined with MOTOR_STOP and is likely to cause a stall if fw_min_throttle_down_pitch isn't set correctly or the pitch estimation is wrong for fixed wing models when not set to ALL_NAV | | nav_position_timeout | 5 | If GPS fails wait for this much seconds before switching to emergency landing mode (0 - disable) | | nav_rth_abort_threshold | 50000 | RTH sanity checking feature will notice if distance to home is increasing during RTH and once amount of increase exceeds the threshold defined by this parameter, instead of continuing RTH machine will enter emergency landing, self-level and go down safely. Default is 500m which is safe enough for both multirotor machines and airplanes. [cm] | | nav_rth_allow_landing | ALWAYS | If set to ON drone will land as a last phase of RTH. | +| nav_rth_alt_control_override | OFF | If set to ON RTH altitude and CLIMB FIRST settings can be overridden during the RTH climb phase using full pitch or roll stick held for > 2 seconds. RTH altitude is reset to the current altitude using pitch down stick. RTH CLIMB FIRST is overridden using right roll stick so craft turns and heads directly to home. | | nav_rth_alt_mode | AT_LEAST | Configure how the aircraft will manage altitude on the way home, see Navigation modes on wiki for more details | | nav_rth_altitude | 1000 | Used in EXTRA, FIXED and AT_LEAST rth alt modes [cm] (Default 1000 means 10 meters) | | nav_rth_climb_first | ON | If set to ON drone will climb to nav_rth_altitude first and head home afterwards. If set to OFF drone will head home instantly and climb on the way. | From 0a93b8b64ad58cded87dbcbe6282995c0835b5b4 Mon Sep 17 00:00:00 2001 From: breadoven <56191411+breadoven@users.noreply.github.com> Date: Wed, 10 Feb 2021 23:20:05 +0000 Subject: [PATCH 10/14] Fix white space --- src/main/fc/settings.yaml | 6 +++--- src/main/navigation/navigation.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/fc/settings.yaml b/src/main/fc/settings.yaml index d04e5013f66..36eabf5f550 100644 --- a/src/main/fc/settings.yaml +++ b/src/main/fc/settings.yaml @@ -2135,12 +2135,12 @@ groups: description: "Configure how the aircraft will manage altitude on the way home, see Navigation modes on wiki for more details" default_value: "AT_LEAST" field: general.flags.rth_alt_control_mode - table: nav_rth_alt_mode + table: nav_rth_alt_mode - name: nav_rth_alt_control_override description: "If set to ON RTH altitude and CLIMB FIRST settings can be overridden during the RTH climb phase using full pitch or roll stick held for > 2 seconds. RTH altitude is reset to the current altitude using pitch down stick. RTH CLIMB FIRST is overridden using right roll stick so craft turns and heads directly to home." default_value: "OFF" - field: general.flags.rth_alt_control_override - type: bool + field: general.flags.rth_alt_control_override + type: bool - name: nav_rth_abort_threshold description: "RTH sanity checking feature will notice if distance to home is increasing during RTH and once amount of increase exceeds the threshold defined by this parameter, instead of continuing RTH machine will enter emergency landing, self-level and go down safely. Default is 500m which is safe enough for both multirotor machines and airplanes. [cm]" default_value: "50000" diff --git a/src/main/navigation/navigation.c b/src/main/navigation/navigation.c index 90786f92a54..5c05bf5e68e 100755 --- a/src/main/navigation/navigation.c +++ b/src/main/navigation/navigation.c @@ -2579,7 +2579,7 @@ static bool rthAltControlStickOverrideCheck(unsigned axis) } else if (ABS(2500 - holdTime) < 500) { if (axis == PITCH) { // PITCH down to override preset altitude reset to current altitude posControl.rthState.rthInitialAltitude = posControl.actualState.abs.pos.z; - posControl.rthState.rthFinalAltitude = posControl.rthState.rthInitialAltitude; + posControl.rthState.rthFinalAltitude = posControl.rthState.rthInitialAltitude; return true; } else if (axis == ROLL) { // ROLL right to override climb first return true; From c0e98e4fc58cae6ca97b9e068a41abe1edbb6b73 Mon Sep 17 00:00:00 2001 From: breadoven <56191411+breadoven@users.noreply.github.com> Date: Sat, 10 Apr 2021 13:46:08 +0100 Subject: [PATCH 11/14] Update settings.yaml --- src/main/fc/settings.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/fc/settings.yaml b/src/main/fc/settings.yaml index 6e4e29da995..875ca28165d 100644 --- a/src/main/fc/settings.yaml +++ b/src/main/fc/settings.yaml @@ -2339,7 +2339,7 @@ groups: table: nav_rth_alt_mode - name: nav_rth_alt_control_override description: "If set to ON RTH altitude and CLIMB FIRST settings can be overridden during the RTH climb phase using full pitch or roll stick held for > 2 seconds. RTH altitude is reset to the current altitude using pitch down stick. RTH CLIMB FIRST is overridden using right roll stick so craft turns and heads directly to home." - default_value: "OFF" + default_value: OFF field: general.flags.rth_alt_control_override type: bool - name: nav_rth_abort_threshold From 2a01175e0eff56e02e9b37ed43e0aab8090bba0c Mon Sep 17 00:00:00 2001 From: breadoven <56191411+breadoven@users.noreply.github.com> Date: Tue, 13 Apr 2021 00:15:09 +0100 Subject: [PATCH 12/14] Update navigation.c --- src/main/navigation/navigation.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/navigation/navigation.c b/src/main/navigation/navigation.c index 2e7588cc7c8..ac5161098a7 100644 --- a/src/main/navigation/navigation.c +++ b/src/main/navigation/navigation.c @@ -2470,7 +2470,7 @@ static bool rthAltControlStickOverrideCheck(unsigned axis) if (!rthOverrideStickHoldStartTime[axis]) { rthOverrideStickHoldStartTime[axis] = millis(); - } else if (ABS(2500 - holdTime) < 500) { + } else if (ABS(2500 - holdTime) < 500) { // 2s delay to activate, activation duration limited to 1 sec if (axis == PITCH) { // PITCH down to override preset altitude reset to current altitude posControl.rthState.rthInitialAltitude = posControl.actualState.abs.pos.z; posControl.rthState.rthFinalAltitude = posControl.rthState.rthInitialAltitude; From e8dc880b5cb1588964eb30563ed7a4a15edfe4a9 Mon Sep 17 00:00:00 2001 From: breadoven <56191411+breadoven@users.noreply.github.com> Date: Tue, 13 Apr 2021 23:16:03 +0100 Subject: [PATCH 13/14] Update navigation.c Reduced stick hold delay time to 1s and limited climb first override to fixed wing only --- src/main/navigation/navigation.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/navigation/navigation.c b/src/main/navigation/navigation.c index ac5161098a7..01f522cb543 100644 --- a/src/main/navigation/navigation.c +++ b/src/main/navigation/navigation.c @@ -2454,24 +2454,23 @@ void updateHomePosition(void) /* ----------------------------------------------------------- * Override RTH preset altitude and Climb First option - * using Pitch/Roll stick held for > 2 seconds + * using Pitch/Roll stick held for > 1 seconds + * Climb First override limited to Fixed Wing only *-----------------------------------------------------------*/ static bool rthAltControlStickOverrideCheck(unsigned axis) { - if (!navConfig()->general.flags.rth_alt_control_override || posControl.flags.forcedRTHActivated) { + if (!navConfig()->general.flags.rth_alt_control_override || posControl.flags.forcedRTHActivated || (axis == ROLL && STATE(MULTIROTOR))) { return false; } - static timeMs_t rthOverrideStickHoldStartTime[2]; if (rxGetChannelValue(axis) > rxConfig()->maxcheck) { - timeDelta_t holdTime = millis() - rthOverrideStickHoldStartTime[axis]; if (!rthOverrideStickHoldStartTime[axis]) { rthOverrideStickHoldStartTime[axis] = millis(); - } else if (ABS(2500 - holdTime) < 500) { // 2s delay to activate, activation duration limited to 1 sec - if (axis == PITCH) { // PITCH down to override preset altitude reset to current altitude + } else if (ABS(1500 - holdTime) < 500) { // 1s delay to activate, activation duration limited to 1 sec + if (axis == PITCH) { // PITCH down to override preset altitude reset to current altitude posControl.rthState.rthInitialAltitude = posControl.actualState.abs.pos.z; posControl.rthState.rthFinalAltitude = posControl.rthState.rthInitialAltitude; return true; From f55edbea27bd739ab4f3f591faa91ef4c856b1ef Mon Sep 17 00:00:00 2001 From: breadoven <56191411+breadoven@users.noreply.github.com> Date: Tue, 13 Apr 2021 23:57:23 +0100 Subject: [PATCH 14/14] Update Settings --- docs/Settings.md | 2 +- src/main/fc/settings.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/Settings.md b/docs/Settings.md index 0b531d23e0a..b24760adcc4 100644 --- a/docs/Settings.md +++ b/docs/Settings.md @@ -356,7 +356,7 @@ | nav_position_timeout | 5 | If GPS fails wait for this much seconds before switching to emergency landing mode (0 - disable) | | nav_rth_abort_threshold | 50000 | RTH sanity checking feature will notice if distance to home is increasing during RTH and once amount of increase exceeds the threshold defined by this parameter, instead of continuing RTH machine will enter emergency landing, self-level and go down safely. Default is 500m which is safe enough for both multirotor machines and airplanes. [cm] | | nav_rth_allow_landing | ALWAYS | If set to ON drone will land as a last phase of RTH. | -| nav_rth_alt_control_override | OFF | If set to ON RTH altitude and CLIMB FIRST settings can be overridden during the RTH climb phase using full pitch or roll stick held for > 2 seconds. RTH altitude is reset to the current altitude using pitch down stick. RTH CLIMB FIRST is overridden using right roll stick so craft turns and heads directly to home. | +| nav_rth_alt_control_override | OFF | If set to ON RTH altitude and CLIMB FIRST settings can be overridden during the RTH climb phase using full pitch or roll stick held for > 1 second. RTH altitude is reset to the current altitude using pitch down stick. RTH CLIMB FIRST is overridden using right roll stick so craft turns and heads directly to home (CLIMB FIRST override only works for fixed wing) | | nav_rth_alt_mode | AT_LEAST | Configure how the aircraft will manage altitude on the way home, see Navigation modes on wiki for more details | | nav_rth_altitude | 1000 | Used in EXTRA, FIXED and AT_LEAST rth alt modes [cm] (Default 1000 means 10 meters) | | nav_rth_climb_first | ON | If set to ON or ON_FW_SPIRAL aircraft will climb to nav_rth_altitude first before turning to head home. If set to OFF aircraft will turn and head home immediately climbing on the way. For a fixed wing ON will use a linear climb, ON_FW_SPIRAL will use a loiter turning climb with climb rate set by nav_auto_climb_rate, turn rate set by nav_fw_loiter_radius (ON_FW_SPIRAL is a fixed wing setting and behaves the same as ON for a multirotor) | diff --git a/src/main/fc/settings.yaml b/src/main/fc/settings.yaml index 884ac0a2aaa..c475c5d72da 100644 --- a/src/main/fc/settings.yaml +++ b/src/main/fc/settings.yaml @@ -2341,7 +2341,7 @@ groups: field: general.flags.rth_alt_control_mode table: nav_rth_alt_mode - name: nav_rth_alt_control_override - description: "If set to ON RTH altitude and CLIMB FIRST settings can be overridden during the RTH climb phase using full pitch or roll stick held for > 2 seconds. RTH altitude is reset to the current altitude using pitch down stick. RTH CLIMB FIRST is overridden using right roll stick so craft turns and heads directly to home." + description: "If set to ON RTH altitude and CLIMB FIRST settings can be overridden during the RTH climb phase using full pitch or roll stick held for > 1 second. RTH altitude is reset to the current altitude using pitch down stick. RTH CLIMB FIRST is overridden using right roll stick so craft turns and heads directly to home (CLIMB FIRST override only works for fixed wing)" default_value: OFF field: general.flags.rth_alt_control_override type: bool