From 0f1e7bae2c9ade0c47130092e45aa405e5d1df7e Mon Sep 17 00:00:00 2001 From: ctzsnooze Date: Tue, 29 Oct 2024 08:49:00 +1100 Subject: [PATCH] warn if posHold mode requested but throttle not above airmode activation point --- src/main/fc/core.c | 7 ++----- src/main/flight/autopilot.c | 5 +++++ src/main/flight/pid.c | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/fc/core.c b/src/main/fc/core.c index a93fc699c6..aa47df4bd3 100644 --- a/src/main/fc/core.c +++ b/src/main/fc/core.c @@ -1064,11 +1064,8 @@ void processRxModes(timeUs_t currentTimeUs) // and we have Acc for self-levelling && sensors(SENSOR_ACC) // Need Mag unless a BRAVE user tries it without - && (sensors(SENSOR_MAG) || allowPosHoldWithoutMag()) - // and we have altitude data - && isAltitudeAvailable() - // prevent activation until after takeoff - && wasThrottleRaised()) { + && (sensors(SENSOR_MAG) || allowPosHoldWithoutMag())) + { if (!FLIGHT_MODE(POS_HOLD_MODE)) { ENABLE_FLIGHT_MODE(POS_HOLD_MODE); // this is just a 'request to initiate' the function diff --git a/src/main/flight/autopilot.c b/src/main/flight/autopilot.c index 2941f6640f..a68993c186 100644 --- a/src/main/flight/autopilot.c +++ b/src/main/flight/autopilot.c @@ -24,6 +24,7 @@ #include "build/debug.h" #include "common/filter.h" #include "common/maths.h" +#include "fc/core.h" #include "fc/rc.h" #include "fc/runtime_config.h" @@ -218,6 +219,10 @@ bool positionControl(void) { ) { return false; } + + if (!wasThrottleRaised()) { + return false; + } if (isNewDataForPosHold()) { posHold.gpsDataIntervalS = getGpsDataIntervalSeconds(); // interval for current GPS data value 0.01s to 1.0s diff --git a/src/main/flight/pid.c b/src/main/flight/pid.c index e3c807b103..a34c3fe717 100644 --- a/src/main/flight/pid.c +++ b/src/main/flight/pid.c @@ -581,7 +581,7 @@ STATIC_UNIT_TESTED FAST_CODE_NOINLINE float pidLevel(int axis, const pidProfile_ // earthRef code here takes about 76 cycles, if conditional on angleEarthRef it takes about 100. sin_approx costs most of those cycles. float sinAngle = sin_approx(DEGREES_TO_RADIANS(pidRuntime.angleTarget[axis == FD_ROLL ? FD_PITCH : FD_ROLL])); sinAngle *= (axis == FD_ROLL) ? -1.0f : 1.0f; // must be negative for Roll - const float earthRefGain = FLIGHT_MODE(GPS_RESCUE_MODE | ALT_HOLD_MODE | POS_HOLD_MODE) ? 1.0f : pidRuntime.angleEarthRef; + const float earthRefGain = FLIGHT_MODE(GPS_RESCUE_MODE | ALT_HOLD_MODE ) ? 1.0f : pidRuntime.angleEarthRef; angleRate += pidRuntime.angleYawSetpoint * sinAngle * earthRefGain; pidRuntime.angleTarget[axis] = angleTarget; // set target for alternate axis to current axis, for use in preceding calculation