1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-26 01:35:35 +03:00

Update navigation.c

This commit is contained in:
breadoven 2022-12-06 22:40:18 +00:00
parent f1e945493d
commit f3ced380ea

View file

@ -2911,12 +2911,14 @@ void updateClimbRateToAltitudeController(float desiredClimbRate, climbRateToAlti
float timeDelta = US2S(currentTimeUs - lastUpdateTimeUs);
if (timeDelta <= HZ2S(MIN_POSITION_UPDATE_RATE_HZ) && desiredClimbRate) {
/* Only update target altitude when actual altitude within 5m of target in required direction of change
* otherwise hold target altitude and wait for actual altitude to catch up */
float targetAlt = posControl.desiredState.pos.z + desiredClimbRate * timeDelta;
if ((desiredClimbRate > 0 && targetAlt < altitudeToUse + 500) || (desiredClimbRate < 0 && targetAlt > altitudeToUse - 500)) {
posControl.desiredState.pos.z = targetAlt;
static bool targetHoldActive = false;
// Update target altitude only if actual altitude moving in same direction and lagging by < 5 m, otherwise hold target
if (navGetCurrentActualPositionAndVelocity()->vel.z * desiredClimbRate >= 0 && fabsf(posControl.desiredState.pos.z - altitudeToUse) < 500) {
posControl.desiredState.pos.z += desiredClimbRate * timeDelta;
targetHoldActive = false;
} else if (!targetHoldActive) { // Reset and hold target to actual + climb rate boost until actual catches up
posControl.desiredState.pos.z = altitudeToUse + desiredClimbRate;
targetHoldActive = true;
}
}
}