diff --git a/src/main/navigation/navigation.c b/src/main/navigation/navigation.c index 3a27d7dfd3..240897f90f 100755 --- a/src/main/navigation/navigation.c +++ b/src/main/navigation/navigation.c @@ -2762,7 +2762,7 @@ rthState_e getStateOfForcedRTH(void) bool navigationIsControllingThrottle(void) { navigationFSMStateFlags_t stateFlags = navGetCurrentStateFlags(); - return (stateFlags & (NAV_CTL_ALT | NAV_CTL_EMERG | NAV_CTL_LAUNCH | NAV_CTL_LAND)) || (STATE(FIXED_WING) && (stateFlags & (NAV_CTL_POS))); + return (stateFlags & (NAV_CTL_ALT | NAV_CTL_EMERG | NAV_CTL_LAUNCH | NAV_CTL_LAND)); } bool navigationIsFlyingAutonomousMode(void) diff --git a/src/main/navigation/navigation_fixedwing.c b/src/main/navigation/navigation_fixedwing.c index 8244ebe1dd..0e874c70a4 100755 --- a/src/main/navigation/navigation_fixedwing.c +++ b/src/main/navigation/navigation_fixedwing.c @@ -412,28 +412,24 @@ int16_t applyFixedWingMinSpeedController(timeUs_t currentTimeUs) void applyFixedWingPitchRollThrottleController(navigationFSMStateFlags_t navStateFlags, timeUs_t currentTimeUs) { - int16_t pitchCorrection = 0; // >0 climb, <0 dive - int16_t rollCorrection = 0; // >0 right, <0 left - int16_t throttleCorrection = 0; // raw throttle - int16_t minThrottleCorrection = navConfig()->fw.min_throttle - navConfig()->fw.cruise_throttle; int16_t maxThrottleCorrection = navConfig()->fw.max_throttle - navConfig()->fw.cruise_throttle; - // Mix Pitch/Roll/Throttle if (isRollAdjustmentValid && (navStateFlags & NAV_CTL_POS)) { - rollCorrection += posControl.rcAdjustment[ROLL]; + // ROLL >0 right, <0 left + int16_t rollCorrection = constrain(posControl.rcAdjustment[ROLL], -DEGREES_TO_DECIDEGREES(navConfig()->fw.max_bank_angle), DEGREES_TO_DECIDEGREES(navConfig()->fw.max_bank_angle)); + rcCommand[ROLL] = pidAngleToRcCommand(rollCorrection, pidProfile()->max_angle_inclination[FD_ROLL]); } if (isPitchAdjustmentValid && (navStateFlags & NAV_CTL_ALT)) { - pitchCorrection += posControl.rcAdjustment[PITCH]; - throttleCorrection += DECIDEGREES_TO_DEGREES(pitchCorrection) * navConfig()->fw.pitch_to_throttle; + // PITCH >0 dive, <0 climb + int16_t pitchCorrection = constrain(posControl.rcAdjustment[PITCH], -DEGREES_TO_DECIDEGREES(navConfig()->fw.max_dive_angle), DEGREES_TO_DECIDEGREES(navConfig()->fw.max_climb_angle)); + rcCommand[PITCH] = -pidAngleToRcCommand(pitchCorrection, pidProfile()->max_angle_inclination[FD_PITCH]); + int16_t throttleCorrection = DECIDEGREES_TO_DEGREES(pitchCorrection) * navConfig()->fw.pitch_to_throttle; #ifdef NAV_FIXED_WING_LANDING if (navStateFlags & NAV_CTL_LAND) { - /* - * During LAND we do not allow to raise THROTTLE when nose is up - * to reduce speed - */ + // During LAND we do not allow to raise THROTTLE when nose is up to reduce speed throttleCorrection = constrain(throttleCorrection, minThrottleCorrection, 0); } else { #endif @@ -441,28 +437,13 @@ void applyFixedWingPitchRollThrottleController(navigationFSMStateFlags_t navStat #ifdef NAV_FIXED_WING_LANDING } #endif - } - // Speed controller - only apply in POS mode when NOT NAV_CTL_LAND - if ((navStateFlags & NAV_CTL_POS) && !(navStateFlags & NAV_CTL_LAND)) { - throttleCorrection += applyFixedWingMinSpeedController(currentTimeUs); - throttleCorrection = constrain(throttleCorrection, minThrottleCorrection, maxThrottleCorrection); - } + // Speed controller - only apply in POS mode when NOT NAV_CTL_LAND + if ((navStateFlags & NAV_CTL_POS) && !(navStateFlags & NAV_CTL_LAND)) { + throttleCorrection += applyFixedWingMinSpeedController(currentTimeUs); + throttleCorrection = constrain(throttleCorrection, minThrottleCorrection, maxThrottleCorrection); + } - // Limit and apply - if (isPitchAdjustmentValid && (navStateFlags & NAV_CTL_ALT)) { - // PITCH correction is measured according to altitude: <0 - dive/lose altitude, >0 - climb/gain altitude - // PITCH angle is measured in opposite direction ( >0 - dive, <0 - climb) - pitchCorrection = constrain(pitchCorrection, -DEGREES_TO_DECIDEGREES(navConfig()->fw.max_dive_angle), DEGREES_TO_DECIDEGREES(navConfig()->fw.max_climb_angle)); - rcCommand[PITCH] = -pidAngleToRcCommand(pitchCorrection, pidProfile()->max_angle_inclination[FD_PITCH]); - } - - if (isRollAdjustmentValid && (navStateFlags & NAV_CTL_POS)) { - rollCorrection = constrain(rollCorrection, -DEGREES_TO_DECIDEGREES(navConfig()->fw.max_bank_angle), DEGREES_TO_DECIDEGREES(navConfig()->fw.max_bank_angle)); - rcCommand[ROLL] = pidAngleToRcCommand(rollCorrection, pidProfile()->max_angle_inclination[FD_ROLL]); - } - - if ((navStateFlags & NAV_CTL_ALT) || (navStateFlags & NAV_CTL_POS)) { uint16_t correctedThrottleValue = constrain(navConfig()->fw.cruise_throttle + throttleCorrection, navConfig()->fw.min_throttle, navConfig()->fw.max_throttle); rcCommand[THROTTLE] = constrain(correctedThrottleValue, motorConfig()->minthrottle, motorConfig()->maxthrottle); } @@ -475,23 +456,15 @@ void applyFixedWingPitchRollThrottleController(navigationFSMStateFlags_t navStat if (navStateFlags & NAV_CTL_LAND) { if ( ((posControl.flags.estAltStatus >= EST_USABLE) && (navGetCurrentActualPositionAndVelocity()->pos.z <= navConfig()->general.land_slowdown_minalt)) || ((posControl.flags.estAglStatus == EST_TRUSTED) && (posControl.actualState.agl.pos.z <= navConfig()->general.land_slowdown_minalt)) ) { - /* - * Set motor to min. throttle and stop it when MOTOR_STOP feature is enabled - */ + + // Set motor to min. throttle and stop it when MOTOR_STOP feature is enabled rcCommand[THROTTLE] = motorConfig()->minthrottle; ENABLE_STATE(NAV_MOTOR_STOP_OR_IDLE); - /* - * Stabilize ROLL axis on 0 degrees banking regardless of loiter radius and position - */ + // Stabilize ROLL axis on 0 degrees banking regardless of loiter radius and position rcCommand[ROLL] = 0; - /* - * Stabilize PITCH angle into shallow dive as specified by the - * nav_fw_land_dive_angle setting (default value is 2 - defined - * in navigation.c). - * PITCH angle is measured: >0 - dive, <0 - climb) - */ + // Stabilize PITCH angle into shallow dive as specified by the nav_fw_land_dive_angle setting (default value is 2 - defined in navigation.c). rcCommand[PITCH] = pidAngleToRcCommand(DEGREES_TO_DECIDEGREES(navConfig()->fw.land_dive_angle), pidProfile()->max_angle_inclination[FD_PITCH]); } }