Skip to content

Commit 9591dee

Browse files
Merge pull request #10866 from breadoven/abo_mc_ph_atti_mode_change
Use Nav max bank angle for multirotor ATTI mode
2 parents 91dad48 + a8b9208 commit 9591dee

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

src/main/flight/pid.c

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -596,38 +596,45 @@ int16_t angleFreefloatDeadband(int16_t deadband, flight_dynamics_index_t axis)
596596

597597
static float computePidLevelTarget(flight_dynamics_index_t axis) {
598598
// This is ROLL/PITCH, run ANGLE/HORIZON controllers
599+
600+
// Limit max bank angle for multirotor during Nav mode Angle controlled position adjustment
601+
uint16_t maxBankAngle = STATE(MULTIROTOR) && navConfig()->general.flags.user_control_mode == NAV_GPS_ATTI && isAdjustingPosition() ?
602+
DEGREES_TO_DECIDEGREES(navConfig()->mc.max_bank_angle) : pidProfile()->max_angle_inclination[axis];
603+
599604
#ifdef USE_PROGRAMMING_FRAMEWORK
600-
float angleTarget = pidRcCommandToAngle(getRcCommandOverride(rcCommand, axis), pidProfile()->max_angle_inclination[axis]);
605+
float angleTarget = pidRcCommandToAngle(getRcCommandOverride(rcCommand, axis), maxBankAngle);
601606
#else
602-
float angleTarget = pidRcCommandToAngle(rcCommand[axis], pidProfile()->max_angle_inclination[axis]);
607+
float angleTarget = pidRcCommandToAngle(rcCommand[axis], maxBankAngle);
603608
#endif
604609

605-
// Automatically pitch down if the throttle is manually controlled and reduced bellow cruise throttle
610+
if (STATE(AIRPLANE)) {
611+
// Automatically pitch down if the throttle is manually controlled and reduced below cruise throttle
606612
#ifdef USE_FW_AUTOLAND
607-
if ((axis == FD_PITCH) && STATE(AIRPLANE) && FLIGHT_MODE(ANGLE_MODE) && !navigationIsControllingThrottle() && !FLIGHT_MODE(NAV_FW_AUTOLAND)) {
613+
if (axis == FD_PITCH && FLIGHT_MODE(ANGLE_MODE) && !navigationIsControllingThrottle() && !FLIGHT_MODE(NAV_FW_AUTOLAND)) {
608614
#else
609-
if ((axis == FD_PITCH) && STATE(AIRPLANE) && FLIGHT_MODE(ANGLE_MODE) && !navigationIsControllingThrottle()) {
615+
if (axis == FD_PITCH && FLIGHT_MODE(ANGLE_MODE) && !navigationIsControllingThrottle()) {
610616
#endif
611-
angleTarget += scaleRange(MAX(0, currentBatteryProfile->nav.fw.cruise_throttle - rcCommand[THROTTLE]), 0, currentBatteryProfile->nav.fw.cruise_throttle - PWM_RANGE_MIN, 0, navConfig()->fw.minThrottleDownPitchAngle);
612-
}
613-
614-
//PITCH trim applied by a AutoLevel flight mode and manual pitch trimming
615-
if (axis == FD_PITCH && STATE(AIRPLANE)) {
616-
DEBUG_SET(DEBUG_AUTOLEVEL, 0, angleTarget * 10);
617-
DEBUG_SET(DEBUG_AUTOLEVEL, 1, fixedWingLevelTrim * 10);
618-
DEBUG_SET(DEBUG_AUTOLEVEL, 2, getEstimatedActualVelocity(Z));
619-
620-
/*
621-
* fixedWingLevelTrim has opposite sign to rcCommand.
622-
* Positive rcCommand means nose should point downwards
623-
* Negative rcCommand mean nose should point upwards
624-
* This is counter intuitive and a natural way suggests that + should mean UP
625-
* This is why fixedWingLevelTrim has opposite sign to rcCommand
626-
* Positive fixedWingLevelTrim means nose should point upwards
627-
* Negative fixedWingLevelTrim means nose should point downwards
628-
*/
629-
angleTarget -= DEGREES_TO_DECIDEGREES(fixedWingLevelTrim);
630-
DEBUG_SET(DEBUG_AUTOLEVEL, 3, angleTarget * 10);
617+
angleTarget += scaleRange(MAX(0, currentBatteryProfile->nav.fw.cruise_throttle - rcCommand[THROTTLE]), 0, currentBatteryProfile->nav.fw.cruise_throttle - PWM_RANGE_MIN, 0, navConfig()->fw.minThrottleDownPitchAngle);
618+
}
619+
620+
//PITCH trim applied by a AutoLevel flight mode and manual pitch trimming
621+
if (axis == FD_PITCH) {
622+
DEBUG_SET(DEBUG_AUTOLEVEL, 0, angleTarget * 10);
623+
DEBUG_SET(DEBUG_AUTOLEVEL, 1, fixedWingLevelTrim * 10);
624+
DEBUG_SET(DEBUG_AUTOLEVEL, 2, getEstimatedActualVelocity(Z));
625+
626+
/*
627+
* fixedWingLevelTrim has opposite sign to rcCommand.
628+
* Positive rcCommand means nose should point downwards
629+
* Negative rcCommand mean nose should point upwards
630+
* This is counter intuitive and a natural way suggests that + should mean UP
631+
* This is why fixedWingLevelTrim has opposite sign to rcCommand
632+
* Positive fixedWingLevelTrim means nose should point upwards
633+
* Negative fixedWingLevelTrim means nose should point downwards
634+
*/
635+
angleTarget -= DEGREES_TO_DECIDEGREES(fixedWingLevelTrim);
636+
DEBUG_SET(DEBUG_AUTOLEVEL, 3, angleTarget * 10);
637+
}
631638
}
632639

633640
return angleTarget;

0 commit comments

Comments
 (0)