From f09a71a76dd151f0f855871a621b74c08dde58a8 Mon Sep 17 00:00:00 2001 From: ctzsnooze Date: Mon, 14 Oct 2024 12:12:06 +1100 Subject: [PATCH] allow user to fly without mag only if they reverse the default --- src/main/blackbox/blackbox.c | 3 ++- src/main/cli/settings.c | 3 ++- src/main/fc/core.c | 3 ++- src/main/fc/parameter_names.h | 4 ++++ src/main/flight/pos_hold.c | 6 ++++++ src/main/flight/pos_hold.h | 1 + src/main/pg/pos_hold.c | 2 +- src/main/pg/pos_hold.h | 2 +- 8 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/blackbox/blackbox.c b/src/main/blackbox/blackbox.c index ca58d25e73..2c13a13db0 100644 --- a/src/main/blackbox/blackbox.c +++ b/src/main/blackbox/blackbox.c @@ -70,6 +70,7 @@ #include "flight/mixer.h" #include "flight/pid.h" #include "flight/position.h" +#include "flight/pos_hold.h" #include "flight/rpm_filter.h" #include "flight/servos.h" #include "flight/imu.h" @@ -1818,7 +1819,7 @@ static bool blackboxWriteSysinfo(void) #endif #ifdef USE_POS_HOLD_MODE - // nothing at present + BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_POS_HOLD_WITHOUT_MAG, "%d", posHoldConfig()->pos_hold_without_mag); #endif #ifdef USE_WING diff --git a/src/main/cli/settings.c b/src/main/cli/settings.c index 458093a430..4c3fe09096 100644 --- a/src/main/cli/settings.c +++ b/src/main/cli/settings.c @@ -64,6 +64,7 @@ #include "flight/mixer.h" #include "flight/pid.h" #include "flight/position.h" +#include "flight/pos_hold.h" #include "flight/rpm_filter.h" #include "flight/servos.h" @@ -1113,7 +1114,7 @@ const clivalue_t valueTable[] = { #endif #ifdef USE_POS_HOLD_MODE - // nothing at present + { PARAM_NAME_POS_HOLD_WITHOUT_MAG, VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_POSHOLD_CONFIG, offsetof(posHoldConfig_t, pos_hold_without_mag) }, #endif // PG_PID_CONFIG diff --git a/src/main/fc/core.c b/src/main/fc/core.c index ade5a4e52f..da6eab11f0 100644 --- a/src/main/fc/core.c +++ b/src/main/fc/core.c @@ -1064,7 +1064,8 @@ void processRxModes(timeUs_t currentTimeUs) // and we have Acc for self-levelling && sensors(SENSOR_ACC) // and we have altitude data - // TO DO: handle No Mag data depending on user choice to proceed with or without mag + && sensors(SENSOR_MAG || allowPosHoldWithoutMag()) + // Need Mag unless a BRAVE user tries it without && isAltitudeAvailable() // prevent activation until after takeoff && wasThrottleRaised()) { diff --git a/src/main/fc/parameter_names.h b/src/main/fc/parameter_names.h index 1821fcdbb9..04ad4edc3b 100644 --- a/src/main/fc/parameter_names.h +++ b/src/main/fc/parameter_names.h @@ -251,6 +251,10 @@ #define PARAM_NAME_ALT_HOLD_ADJUST_RATE "alt_hold_adjust_rate" #endif // USE_ALT_HOLD_MODE +#ifdef USE_POS_HOLD_MODE +#define PARAM_NAME_POS_HOLD_WITHOUT_MAG "position_hold_without_mag" +#endif // USE_POS_HOLD_MODE + #define PARAM_NAME_IMU_DCM_KP "imu_dcm_kp" #define PARAM_NAME_IMU_DCM_KI "imu_dcm_ki" #define PARAM_NAME_IMU_SMALL_ANGLE "small_angle" diff --git a/src/main/flight/pos_hold.c b/src/main/flight/pos_hold.c index b94cd58e82..f48ded974e 100644 --- a/src/main/flight/pos_hold.c +++ b/src/main/flight/pos_hold.c @@ -104,4 +104,10 @@ bool showPosHoldWarning(void) { return (posHold.isPosHoldRequested && !posHold.posHoldIsOK); } +bool allowPosHoldWithoutMag(void) { + return (posHoldConfig()->pos_hold_without_mag); +} + + + #endif // USE_POS_HOLD diff --git a/src/main/flight/pos_hold.h b/src/main/flight/pos_hold.h index 9945a9c4d1..dd62b60141 100644 --- a/src/main/flight/pos_hold.h +++ b/src/main/flight/pos_hold.h @@ -36,5 +36,6 @@ void posHoldInit(void); void updatePosHoldState(timeUs_t currentTimeUs); bool showPosHoldWarning(void); +bool allowPosHoldWithoutMag(void); #endif diff --git a/src/main/pg/pos_hold.c b/src/main/pg/pos_hold.c index efc156656a..861833f4fe 100644 --- a/src/main/pg/pos_hold.c +++ b/src/main/pg/pos_hold.c @@ -32,6 +32,6 @@ PG_REGISTER_WITH_RESET_TEMPLATE(posHoldConfig_t, posHoldConfig, PG_POSHOLD_CONFIG, 1); PG_RESET_TEMPLATE(posHoldConfig_t, posHoldConfig, - .unused = 33, // position hold within this percentage stick deflection + .pos_hold_without_mag = false, // position hold within this percentage stick deflection ); #endif diff --git a/src/main/pg/pos_hold.h b/src/main/pg/pos_hold.h index dac6a3c6de..65d49ae25b 100644 --- a/src/main/pg/pos_hold.h +++ b/src/main/pg/pos_hold.h @@ -25,7 +25,7 @@ #include "pg/pg.h" typedef struct posHoldConfig_s { - uint8_t unused; + bool pos_hold_without_mag; } posHoldConfig_t; PG_DECLARE(posHoldConfig_t, posHoldConfig);