From 003979a2eb34a0c41ac60ed75a373cfebe181ad3 Mon Sep 17 00:00:00 2001 From: Bruce Luckcuck Date: Wed, 31 Jan 2018 22:28:47 -0500 Subject: [PATCH 1/2] Change airmode activation to be throttle percent based to fix 3D mode The previous logic used an absolute throttle value of 1350us which won't work in 3D mode and resulted in airmode being activated on arming. Renamed the parameter to airmode_start_throttle_percent and set the default to 32 (equivalent to what the previous setting of 1350 when min_check is taken into account). To preserve MSP functionality the value is transformed to/from microsecond values (32 becomes 1320) when interfaced. --- src/main/fc/fc_core.c | 10 +++++----- src/main/interface/msp.c | 4 ++-- src/main/interface/settings.c | 2 +- src/main/rx/rx.c | 2 +- src/main/rx/rx.h | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/fc/fc_core.c b/src/main/fc/fc_core.c index c00bdfdc2..14e962234 100644 --- a/src/main/fc/fc_core.c +++ b/src/main/fc/fc_core.c @@ -97,8 +97,6 @@ enum { #define GYRO_WATCHDOG_DELAY 80 // delay for gyro sync -#define AIRMODE_THOTTLE_THRESHOLD 1350 // Make configurable in the future. ~35% throttle should be fine - #ifdef USE_RUNAWAY_TAKEOFF #define RUNAWAY_TAKEOFF_DEACTIVATE_STICK_PERCENT 15 // 15% - minimum stick deflection during deactivation phase #define RUNAWAY_TAKEOFF_DEACTIVATE_PIDSUM_LIMIT 100 // 10.0% - pidSum limit during deactivation phase @@ -446,6 +444,7 @@ bool areSticksActive(uint8_t stickPercentLimit) } return false; } +#endif // calculate the throttle stick percent - integer math is good enough here. @@ -470,7 +469,7 @@ uint8_t calculateThrottlePercent(void) } return ret; } -#endif + /* * processRx called from taskUpdateRxMain @@ -498,9 +497,10 @@ bool processRx(timeUs_t currentTimeUs) failsafeUpdateState(); const throttleStatus_e throttleStatus = calculateThrottleStatus(); + const uint8_t throttlePercent = calculateThrottlePercent(); if (isAirmodeActive() && ARMING_FLAG(ARMED)) { - if (rcData[THROTTLE] >= rxConfig()->airModeActivateThreshold) { + if (throttlePercent >= rxConfig()->airModeActivateThreshold) { airmodeIsActivated = true; // Prevent Iterm from being reset } } else { @@ -538,7 +538,7 @@ bool processRx(timeUs_t currentTimeUs) // - pidSum on all axis is less then runaway_takeoff_deactivate_pidlimit bool inStableFlight = false; if (!feature(FEATURE_MOTOR_STOP) || isAirmodeActive() || (throttleStatus != THROTTLE_LOW)) { // are motors running? - if ((calculateThrottlePercent() >= pidConfig()->runaway_takeoff_deactivate_throttle) + if ((throttlePercent >= pidConfig()->runaway_takeoff_deactivate_throttle) && areSticksActive(RUNAWAY_TAKEOFF_DEACTIVATE_STICK_PERCENT) && (fabsf(axisPIDSum[FD_PITCH]) < RUNAWAY_TAKEOFF_DEACTIVATE_PIDSUM_LIMIT) && (fabsf(axisPIDSum[FD_ROLL]) < RUNAWAY_TAKEOFF_DEACTIVATE_PIDSUM_LIMIT) diff --git a/src/main/interface/msp.c b/src/main/interface/msp.c index b8827dcca..1bdbc03d2 100644 --- a/src/main/interface/msp.c +++ b/src/main/interface/msp.c @@ -1013,7 +1013,7 @@ static bool mspProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst) sbufWriteU16(dst, rxConfig()->rx_max_usec); sbufWriteU8(dst, rxConfig()->rcInterpolation); sbufWriteU8(dst, rxConfig()->rcInterpolationInterval); - sbufWriteU16(dst, rxConfig()->airModeActivateThreshold); + sbufWriteU16(dst, (rxConfig()->airModeActivateThreshold * 10) + 1000); sbufWriteU8(dst, rxConfig()->rx_spi_protocol); sbufWriteU32(dst, rxConfig()->rx_spi_id); sbufWriteU8(dst, rxConfig()->rx_spi_rf_channel_count); @@ -1872,7 +1872,7 @@ static mspResult_e mspProcessInCommand(uint8_t cmdMSP, sbuf_t *src) if (sbufBytesRemaining(src) >= 4) { rxConfigMutable()->rcInterpolation = sbufReadU8(src); rxConfigMutable()->rcInterpolationInterval = sbufReadU8(src); - rxConfigMutable()->airModeActivateThreshold = sbufReadU16(src); + rxConfigMutable()->airModeActivateThreshold = ((sbufReadU16(src) - 1000) / 10); } if (sbufBytesRemaining(src) >= 6) { rxConfigMutable()->rx_spi_protocol = sbufReadU8(src); diff --git a/src/main/interface/settings.c b/src/main/interface/settings.c index 9dcf2bc34..503cd1dda 100644 --- a/src/main/interface/settings.c +++ b/src/main/interface/settings.c @@ -421,7 +421,7 @@ const clivalue_t valueTable[] = { { "spektrum_sat_bind", VAR_UINT8 | MASTER_VALUE, .config.minmax = { SPEKTRUM_SAT_BIND_DISABLED, SPEKTRUM_SAT_BIND_MAX}, PG_RX_CONFIG, offsetof(rxConfig_t, spektrum_sat_bind) }, { "spektrum_sat_bind_autoreset",VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_RX_CONFIG, offsetof(rxConfig_t, spektrum_sat_bind_autoreset) }, #endif - { "airmode_start_throttle", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 1000, 2000 }, PG_RX_CONFIG, offsetof(rxConfig_t, airModeActivateThreshold) }, + { "airmode_start_throttle_percent", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 100 }, PG_RX_CONFIG, offsetof(rxConfig_t, airModeActivateThreshold) }, { "rx_min_usec", VAR_UINT16 | MASTER_VALUE, .config.minmax = { PWM_PULSE_MIN, PWM_PULSE_MAX }, PG_RX_CONFIG, offsetof(rxConfig_t, rx_min_usec) }, { "rx_max_usec", VAR_UINT16 | MASTER_VALUE, .config.minmax = { PWM_PULSE_MIN, PWM_PULSE_MAX }, PG_RX_CONFIG, offsetof(rxConfig_t, rx_max_usec) }, { "serialrx_halfduplex", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_RX_CONFIG, offsetof(rxConfig_t, halfDuplex) }, diff --git a/src/main/rx/rx.c b/src/main/rx/rx.c index dceef40d8..cf4cdf313 100644 --- a/src/main/rx/rx.c +++ b/src/main/rx/rx.c @@ -150,7 +150,7 @@ void pgResetFn_rxConfig(rxConfig_t *rxConfig) .rcInterpolationChannels = 0, .rcInterpolationInterval = 19, .fpvCamAngleDegrees = 0, - .airModeActivateThreshold = 1350, + .airModeActivateThreshold = 32, .max_aux_channel = DEFAULT_AUX_CHANNEL_COUNT ); diff --git a/src/main/rx/rx.h b/src/main/rx/rx.h index 99c7d71a3..221a8a7e3 100644 --- a/src/main/rx/rx.h +++ b/src/main/rx/rx.h @@ -139,7 +139,7 @@ typedef struct rxConfig_s { uint8_t rcInterpolationChannels; uint8_t rcInterpolationInterval; uint8_t fpvCamAngleDegrees; // Camera angle to be scaled into rc commands - uint16_t airModeActivateThreshold; // Throttle setpoint where airmode gets activated + uint8_t airModeActivateThreshold; // Throttle setpoint percent where airmode gets activated uint16_t rx_min_usec; uint16_t rx_max_usec; From bed1c03f700cdaf1337e8b4902fc10eb836b320e Mon Sep 17 00:00:00 2001 From: Bruce Luckcuck Date: Thu, 1 Feb 2018 06:50:11 -0500 Subject: [PATCH 2/2] Airmode 3D activation fix requested changes Formatting changes and correction to update the PG version. --- src/main/interface/msp.c | 4 ++-- src/main/rx/rx.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/interface/msp.c b/src/main/interface/msp.c index 1bdbc03d2..67c9211ab 100644 --- a/src/main/interface/msp.c +++ b/src/main/interface/msp.c @@ -1013,7 +1013,7 @@ static bool mspProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst) sbufWriteU16(dst, rxConfig()->rx_max_usec); sbufWriteU8(dst, rxConfig()->rcInterpolation); sbufWriteU8(dst, rxConfig()->rcInterpolationInterval); - sbufWriteU16(dst, (rxConfig()->airModeActivateThreshold * 10) + 1000); + sbufWriteU16(dst, rxConfig()->airModeActivateThreshold * 10 + 1000); sbufWriteU8(dst, rxConfig()->rx_spi_protocol); sbufWriteU32(dst, rxConfig()->rx_spi_id); sbufWriteU8(dst, rxConfig()->rx_spi_rf_channel_count); @@ -1872,7 +1872,7 @@ static mspResult_e mspProcessInCommand(uint8_t cmdMSP, sbuf_t *src) if (sbufBytesRemaining(src) >= 4) { rxConfigMutable()->rcInterpolation = sbufReadU8(src); rxConfigMutable()->rcInterpolationInterval = sbufReadU8(src); - rxConfigMutable()->airModeActivateThreshold = ((sbufReadU16(src) - 1000) / 10); + rxConfigMutable()->airModeActivateThreshold = (sbufReadU16(src) - 1000) / 10; } if (sbufBytesRemaining(src) >= 6) { rxConfigMutable()->rx_spi_protocol = sbufReadU8(src); diff --git a/src/main/rx/rx.c b/src/main/rx/rx.c index cf4cdf313..61f33cb1b 100644 --- a/src/main/rx/rx.c +++ b/src/main/rx/rx.c @@ -126,7 +126,7 @@ static uint8_t rcSampleIndex = 0; #define BINDPLUG_PIN NONE #endif -PG_REGISTER_WITH_RESET_FN(rxConfig_t, rxConfig, PG_RX_CONFIG, 1); +PG_REGISTER_WITH_RESET_FN(rxConfig_t, rxConfig, PG_RX_CONFIG, 2); void pgResetFn_rxConfig(rxConfig_t *rxConfig) { RESET_CONFIG_2(rxConfig_t, rxConfig,