From d0519d3667a5a5b632a33e225ec7767fedcc7660 Mon Sep 17 00:00:00 2001 From: rmaia <9812730+rmaia3d@users.noreply.github.com> Date: Tue, 25 Jun 2024 23:31:51 -0300 Subject: [PATCH 1/2] - Change NAV_FW_CRUISE_THR adjustment handling logic Change to a fixed offset based on adjustment channel position, where any value above midpoint is added to default throttle setting, and any value below midpoint, subtracted (reduces throttle). --- src/main/fc/rc_adjustments.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/fc/rc_adjustments.c b/src/main/fc/rc_adjustments.c index 37c338fed..df5cdff6c 100644 --- a/src/main/fc/rc_adjustments.c +++ b/src/main/fc/rc_adjustments.c @@ -644,7 +644,12 @@ static void applySelectAdjustment(uint8_t adjustmentFunction, uint8_t position) void processRcAdjustments(controlRateConfig_t *controlRateConfig, bool canUseRxData) { + static uint16_t default_fw_cruise_thr = 0U; // Initialize to zero const uint32_t now = millis(); + if (default_fw_cruise_thr == 0U && now > 1000U) { + // Wait at least 1 second before updating to value to avoid any initialization errors + default_fw_cruise_thr = currentBatteryProfileMutable->nav.fw.cruise_throttle; + } for (int adjustmentIndex = 0; adjustmentIndex < MAX_SIMULTANEOUS_ADJUSTMENT_COUNT; adjustmentIndex++) { adjustmentState_t * const adjustmentState = &adjustmentStates[adjustmentIndex]; @@ -671,7 +676,15 @@ void processRcAdjustments(controlRateConfig_t *controlRateConfig, bool canUseRxD const uint8_t channelIndex = NON_AUX_CHANNEL_COUNT + adjustmentState->auxChannelIndex; - if (adjustmentState->config->mode == ADJUSTMENT_MODE_STEP) { + // Different adjustment handling for ADJUSTMENT_NAV_FW_CRUISE_THR + if (adjustmentFunction == ADJUSTMENT_NAV_FW_CRUISE_THR) { + // Get adjustment value directly from adjustment channel distance from mid-point + int16_t adj_value = rxGetChannelValue(channelIndex) - PWM_RANGE_MIDDLE; + int16_t new_value = default_fw_cruise_thr + adj_value; + new_value = constrain(new_value, SETTING_NAV_FW_CRUISE_THR_MIN, SETTING_NAV_FW_CRUISE_THR_MAX); + currentBatteryProfileMutable->nav.fw.cruise_throttle = new_value; + blackboxLogInflightAdjustmentEvent(adjustmentFunction, new_value); + } else if (adjustmentState->config->mode == ADJUSTMENT_MODE_STEP) { int delta; if (rxGetChannelValue(channelIndex) > PWM_RANGE_MIDDLE + 200) { delta = adjustmentState->config->data.stepConfig.step; From b80b6d9a88794855ce96a33008feb32a0868a4f1 Mon Sep 17 00:00:00 2001 From: rmaia <9812730+rmaia3d@users.noreply.github.com> Date: Thu, 27 Jun 2024 18:13:22 -0300 Subject: [PATCH 2/2] - Move adjustment code to a dedicated function and constrain adjusted value to configured cruise throttle max and min --- src/main/fc/rc_adjustments.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/main/fc/rc_adjustments.c b/src/main/fc/rc_adjustments.c index df5cdff6c..b87a323b0 100644 --- a/src/main/fc/rc_adjustments.c +++ b/src/main/fc/rc_adjustments.c @@ -619,6 +619,23 @@ static void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t }; } +static void adjustFwCruiseThrFromChPosition(uint8_t ch_index) +{ + static uint16_t default_fw_cruise_thr = 0U; // Initialize to zero + const uint32_t now = millis(); + if (default_fw_cruise_thr == 0U && now > 1000U) { + // Wait at least 1 second before updating the value to avoid any initialization errors + default_fw_cruise_thr = currentBatteryProfileMutable->nav.fw.cruise_throttle; + } + + // Get adjustment value directly from adjustment channel distance from mid-point + int16_t adj_value = rxGetChannelValue(ch_index) - PWM_RANGE_MIDDLE; + int16_t new_value = default_fw_cruise_thr + adj_value; + new_value = constrain(new_value, currentBatteryProfileMutable->nav.fw.min_throttle, currentBatteryProfileMutable->nav.fw.max_throttle); + currentBatteryProfileMutable->nav.fw.cruise_throttle = new_value; + blackboxLogInflightAdjustmentEvent(ADJUSTMENT_NAV_FW_CRUISE_THR, new_value); +} + #ifdef USE_INFLIGHT_PROFILE_ADJUSTMENT static void applySelectAdjustment(uint8_t adjustmentFunction, uint8_t position) { @@ -644,12 +661,7 @@ static void applySelectAdjustment(uint8_t adjustmentFunction, uint8_t position) void processRcAdjustments(controlRateConfig_t *controlRateConfig, bool canUseRxData) { - static uint16_t default_fw_cruise_thr = 0U; // Initialize to zero const uint32_t now = millis(); - if (default_fw_cruise_thr == 0U && now > 1000U) { - // Wait at least 1 second before updating to value to avoid any initialization errors - default_fw_cruise_thr = currentBatteryProfileMutable->nav.fw.cruise_throttle; - } for (int adjustmentIndex = 0; adjustmentIndex < MAX_SIMULTANEOUS_ADJUSTMENT_COUNT; adjustmentIndex++) { adjustmentState_t * const adjustmentState = &adjustmentStates[adjustmentIndex]; @@ -676,14 +688,9 @@ void processRcAdjustments(controlRateConfig_t *controlRateConfig, bool canUseRxD const uint8_t channelIndex = NON_AUX_CHANNEL_COUNT + adjustmentState->auxChannelIndex; - // Different adjustment handling for ADJUSTMENT_NAV_FW_CRUISE_THR if (adjustmentFunction == ADJUSTMENT_NAV_FW_CRUISE_THR) { - // Get adjustment value directly from adjustment channel distance from mid-point - int16_t adj_value = rxGetChannelValue(channelIndex) - PWM_RANGE_MIDDLE; - int16_t new_value = default_fw_cruise_thr + adj_value; - new_value = constrain(new_value, SETTING_NAV_FW_CRUISE_THR_MIN, SETTING_NAV_FW_CRUISE_THR_MAX); - currentBatteryProfileMutable->nav.fw.cruise_throttle = new_value; - blackboxLogInflightAdjustmentEvent(adjustmentFunction, new_value); + // Different adjustment handling for ADJUSTMENT_NAV_FW_CRUISE_THR + adjustFwCruiseThrFromChPosition(channelIndex); } else if (adjustmentState->config->mode == ADJUSTMENT_MODE_STEP) { int delta; if (rxGetChannelValue(channelIndex) > PWM_RANGE_MIDDLE + 200) {