mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 20:35:33 +03:00
Merge remote-tracking branch 'multiwii/master'
Conflicts: src/flight_imu.c src/mw.c
This commit is contained in:
commit
c004e48a87
2 changed files with 20 additions and 18 deletions
|
@ -415,24 +415,27 @@ 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
|
||||||
|
error = constrain(AltHold - EstAlt, -500, 500);
|
||||||
|
error = applyDeadband(error, 10); // remove small P parametr to reduce noise near zero position
|
||||||
|
setVel = constrain((currentProfile.pidProfile.P8[PIDALT] * error / 128), -300, +300); // limit velocity to +/- 3 m/s
|
||||||
|
|
||||||
// Altitude P-Controller
|
// Velocity PID-Controller
|
||||||
error = constrain(AltHold - EstAlt, -500, 500);
|
// P
|
||||||
error = applyDeadband(error, 10); // remove small P parametr to reduce noise near zero position
|
error = setVel - vel_tmp;
|
||||||
setVel = constrain((currentProfile.pidProfile.P8[PIDALT] * error / 128), -300, +300); // limit velocity to +/- 3 m/s
|
BaroPID = constrain((currentProfile.pidProfile.P8[PIDVEL] * error / 32), -300, +300);
|
||||||
|
|
||||||
// Velocity PID-Controller
|
// I
|
||||||
// P
|
errorAltitudeI += (currentProfile.pidProfile.I8[PIDVEL] * error) / 8;
|
||||||
error = setVel - vel_tmp;
|
errorAltitudeI = constrain(errorAltitudeI, -(1024 * 200), (1024 * 200));
|
||||||
BaroPID = constrain((currentProfile.pidProfile.P8[PIDVEL] * error / 32), -300, +300);
|
BaroPID += errorAltitudeI / 1024; // I in range +/-200
|
||||||
|
|
||||||
// I
|
// D
|
||||||
errorAltitudeI += (currentProfile.pidProfile.I8[PIDVEL] * error) / 8;
|
BaroPID -= constrain(currentProfile.pidProfile.D8[PIDVEL] * (accZ_tmp + accZ_old) / 64, -150, 150);
|
||||||
errorAltitudeI = constrain(errorAltitudeI, -(1024 * 200), (1024 * 200));
|
} else {
|
||||||
BaroPID += errorAltitudeI / 1024; // I in range +/-200
|
BaroPID = 0;
|
||||||
|
}
|
||||||
// D
|
|
||||||
BaroPID -= constrain(currentProfile.pidProfile.D8[PIDVEL] * (accZ_tmp + accZ_old) / 64, -150, 150);
|
|
||||||
accZ_old = accZ_tmp;
|
accZ_old = accZ_tmp;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
5
src/mw.c
5
src/mw.c
|
@ -587,7 +587,7 @@ void loop(void)
|
||||||
AltHold = EstAlt;
|
AltHold = EstAlt;
|
||||||
isAltHoldChanged = 0;
|
isAltHoldChanged = 0;
|
||||||
}
|
}
|
||||||
rcCommand[THROTTLE] = initialThrottleHold + BaroPID;
|
rcCommand[THROTTLE] = constrain(initialThrottleHold + BaroPID, masterConfig.escAndServoConfig.minthrottle + 100, masterConfig.escAndServoConfig.maxthrottle);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// slow alt changes for apfags
|
// slow alt changes for apfags
|
||||||
|
@ -602,8 +602,7 @@ void loop(void)
|
||||||
AltHoldCorr = 0;
|
AltHoldCorr = 0;
|
||||||
isAltHoldChanged = 0;
|
isAltHoldChanged = 0;
|
||||||
}
|
}
|
||||||
rcCommand[THROTTLE] = initialThrottleHold + BaroPID;
|
rcCommand[THROTTLE] = constrain(initialThrottleHold + BaroPID, masterConfig.escAndServoConfig.minthrottle + 100, masterConfig.escAndServoConfig.maxthrottle);
|
||||||
rcCommand[THROTTLE] = constrain(rcCommand[THROTTLE], masterConfig.escAndServoConfig.minthrottle + 150, masterConfig.escAndServoConfig.maxthrottle);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// handle fixedwing-related althold. UNTESTED! and probably wrong
|
// handle fixedwing-related althold. UNTESTED! and probably wrong
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue