Merge pull request #101 from luggi/althold-flipable

make flipping the quad safe with althold engaged
This commit is contained in:
dongie 2014-05-04 22:50:50 +09:00
commit ac4835ef67
2 changed files with 23 additions and 18 deletions

View File

@ -392,6 +392,7 @@ int getEstimatedAltitude(void)
// set vario // set vario
vario = applyDeadband(vel_tmp, 5); vario = applyDeadband(vel_tmp, 5);
if (abs(angle[ROLL]) < 800 && abs(angle[PITCH]) < 800) { // only calculate pid if the copters thrust is facing downwards(<80deg)
// Altitude P-Controller // Altitude P-Controller
error = constrain(AltHold - EstAlt, -500, 500); error = constrain(AltHold - EstAlt, -500, 500);
error = applyDeadband(error, 10); // remove small P parametr to reduce noise near zero position error = applyDeadband(error, 10); // remove small P parametr to reduce noise near zero position
@ -409,6 +410,11 @@ int getEstimatedAltitude(void)
// D // D
BaroPID -= constrain(cfg.D8[PIDVEL] * (accZ_tmp + accZ_old) / 64, -150, 150); BaroPID -= constrain(cfg.D8[PIDVEL] * (accZ_tmp + accZ_old) / 64, -150, 150);
} else {
BaroPID = 0;
}
accZ_old = accZ_tmp; accZ_old = accZ_tmp;
return 1; return 1;

View File

@ -854,7 +854,7 @@ void loop(void)
AltHold = EstAlt; AltHold = EstAlt;
isAltHoldChanged = 0; isAltHoldChanged = 0;
} }
rcCommand[THROTTLE] = initialThrottleHold + BaroPID; rcCommand[THROTTLE] = constrain(initialThrottleHold + BaroPID, mcfg.minthrottle + 100, mcfg.maxthrottle);
} }
} else { } else {
// slow alt changes for apfags // slow alt changes for apfags
@ -869,8 +869,7 @@ void loop(void)
AltHoldCorr = 0; AltHoldCorr = 0;
isAltHoldChanged = 0; isAltHoldChanged = 0;
} }
rcCommand[THROTTLE] = initialThrottleHold + BaroPID; rcCommand[THROTTLE] = constrain(initialThrottleHold + BaroPID, mcfg.minthrottle + 100, mcfg.maxthrottle);
rcCommand[THROTTLE] = constrain(rcCommand[THROTTLE], mcfg.minthrottle + 150, mcfg.maxthrottle);
} }
} else { } else {
// handle fixedwing-related althold. UNTESTED! and probably wrong // handle fixedwing-related althold. UNTESTED! and probably wrong