From 0164149c891f98a483d1177771d19ee8832d4dd9 Mon Sep 17 00:00:00 2001 From: egonl Date: Fri, 17 May 2024 22:00:10 +0200 Subject: [PATCH 1/2] Added adjustments for accelerometer trim --- src/main/fc/rc_adjustments.c | 18 ++++++++++++++++++ src/main/fc/rc_adjustments.h | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/src/main/fc/rc_adjustments.c b/src/main/fc/rc_adjustments.c index a23b2ccaf2..f18d656d3b 100644 --- a/src/main/fc/rc_adjustments.c +++ b/src/main/fc/rc_adjustments.c @@ -56,6 +56,8 @@ #include "rx/rx.h" +#include "sensors/acceleration.h" + #include "rc_adjustments.h" PG_REGISTER_ARRAY(adjustmentRange_t, MAX_ADJUSTMENT_RANGE_COUNT, adjustmentRanges, PG_ADJUSTMENT_RANGE_CONFIG, 3); @@ -155,6 +157,9 @@ static const adjustmentConfig_t adjustmentConfigs[ADJUSTMENT_FUNCTION_COUNT] = ADJ_CONFIG(CROSS_COUPLING_GAIN, PROF, 0, 250), ADJ_CONFIG(CROSS_COUPLING_RATIO, PROF, 0, 200), ADJ_CONFIG(CROSS_COUPLING_CUTOFF, PROF, 1, 250), + + ADJ_CONFIG(ACC_TRIM_PITCH, ACC, -300, 300), + ADJ_CONFIG(ACC_TRIM_ROLL, ACC, -300, 300), }; @@ -356,6 +361,12 @@ static int getAdjustmentValue(uint8_t adjFunc) case ADJUSTMENT_CROSS_COUPLING_CUTOFF: value = currentPidProfile->cyclic_cross_coupling_cutoff; break; + case ADJUSTMENT_ACC_TRIM_PITCH: + value = accelerometerConfig()->accelerometerTrims.values.pitch; + break; + case ADJUSTMENT_ACC_TRIM_ROLL: + value = accelerometerConfig()->accelerometerTrims.values.roll; + break; } return value; @@ -557,6 +568,12 @@ static void setAdjustmentValue(uint8_t adjFunc, int value) case ADJUSTMENT_CROSS_COUPLING_CUTOFF: currentPidProfile->cyclic_cross_coupling_cutoff = value; break; + case ADJUSTMENT_ACC_TRIM_PITCH: + accelerometerConfigMutable()->accelerometerTrims.values.pitch = value; + break; + case ADJUSTMENT_ACC_TRIM_ROLL: + accelerometerConfigMutable()->accelerometerTrims.values.roll = value; + break; } } @@ -693,6 +710,7 @@ void processRcAdjustments(void) if (changed & ADJUSTMENT_TYPE_MIX) { mixerInitConfig(); } + // ADJUSTMENT_TYPE_ACC doesn't need an initialization. } if (!changed) { diff --git a/src/main/fc/rc_adjustments.h b/src/main/fc/rc_adjustments.h index b917c0eb1d..55892b3931 100644 --- a/src/main/fc/rc_adjustments.h +++ b/src/main/fc/rc_adjustments.h @@ -122,6 +122,10 @@ typedef enum { ADJUSTMENT_CROSS_COUPLING_RATIO = 62, ADJUSTMENT_CROSS_COUPLING_CUTOFF = 63, + // Accelerometer + ADJUSTMENT_ACC_TRIM_PITCH = 64, + ADJUSTMENT_ACC_TRIM_ROLL = 65, + ADJUSTMENT_FUNCTION_COUNT } adjustmentFunction_e; @@ -131,6 +135,7 @@ typedef enum { ADJUSTMENT_TYPE_PROF = BIT(1), ADJUSTMENT_TYPE_GOV = BIT(2), ADJUSTMENT_TYPE_MIX = BIT(3), + ADJUSTMENT_TYPE_ACC = BIT(4), } adjustmentType_e; typedef struct { From 496ebb1e1989a6e9ca02ca40da88c36b0caf1101 Mon Sep 17 00:00:00 2001 From: egonl Date: Mon, 20 May 2024 17:02:05 +0200 Subject: [PATCH 2/2] Removed redundant ADJUSTMENT_TYPE_ACC --- src/main/fc/rc_adjustments.c | 5 ++--- src/main/fc/rc_adjustments.h | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/fc/rc_adjustments.c b/src/main/fc/rc_adjustments.c index f18d656d3b..99772d52de 100644 --- a/src/main/fc/rc_adjustments.c +++ b/src/main/fc/rc_adjustments.c @@ -158,8 +158,8 @@ static const adjustmentConfig_t adjustmentConfigs[ADJUSTMENT_FUNCTION_COUNT] = ADJ_CONFIG(CROSS_COUPLING_RATIO, PROF, 0, 200), ADJ_CONFIG(CROSS_COUPLING_CUTOFF, PROF, 1, 250), - ADJ_CONFIG(ACC_TRIM_PITCH, ACC, -300, 300), - ADJ_CONFIG(ACC_TRIM_ROLL, ACC, -300, 300), + ADJ_CONFIG(ACC_TRIM_PITCH, NONE, -300, 300), + ADJ_CONFIG(ACC_TRIM_ROLL, NONE, -300, 300), }; @@ -710,7 +710,6 @@ void processRcAdjustments(void) if (changed & ADJUSTMENT_TYPE_MIX) { mixerInitConfig(); } - // ADJUSTMENT_TYPE_ACC doesn't need an initialization. } if (!changed) { diff --git a/src/main/fc/rc_adjustments.h b/src/main/fc/rc_adjustments.h index 55892b3931..7d564837e7 100644 --- a/src/main/fc/rc_adjustments.h +++ b/src/main/fc/rc_adjustments.h @@ -135,7 +135,6 @@ typedef enum { ADJUSTMENT_TYPE_PROF = BIT(1), ADJUSTMENT_TYPE_GOV = BIT(2), ADJUSTMENT_TYPE_MIX = BIT(3), - ADJUSTMENT_TYPE_ACC = BIT(4), } adjustmentType_e; typedef struct {