From fb7cfffdebb403ae244350552eeb52e14b15d724 Mon Sep 17 00:00:00 2001 From: borisbstyle Date: Wed, 25 May 2016 23:51:10 +0200 Subject: [PATCH] Anti Desync feature for ESC's // Experimental --- src/main/config/config.c | 3 ++- src/main/flight/mixer.c | 9 +++++++++ src/main/io/escservo.h | 1 + src/main/io/serial_cli.c | 1 + 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/config/config.c b/src/main/config/config.c index 081084c07..4ac6984a6 100755 --- a/src/main/config/config.c +++ b/src/main/config/config.c @@ -140,7 +140,7 @@ static uint32_t activeFeaturesLatch = 0; static uint8_t currentControlRateProfileIndex = 0; controlRateConfig_t *currentControlRateProfile; -static const uint8_t EEPROM_CONF_VERSION = 137; +static const uint8_t EEPROM_CONF_VERSION = 138; static void resetAccelerometerTrims(flightDynamicsTrims_t *accelerometerTrims) { @@ -236,6 +236,7 @@ void resetEscAndServoConfig(escAndServoConfig_t *escAndServoConfig) escAndServoConfig->maxthrottle = 1850; escAndServoConfig->mincommand = 1000; escAndServoConfig->servoCenterPulse = 1500; + escAndServoConfig->escDesyncProtection = 0; } void resetFlight3DConfig(flight3DConfig_t *flight3DConfig) diff --git a/src/main/flight/mixer.c b/src/main/flight/mixer.c index 87ee5f187..f305ded59 100755 --- a/src/main/flight/mixer.c +++ b/src/main/flight/mixer.c @@ -854,6 +854,15 @@ void mixTable(void) motor[i] = escAndServoConfig->mincommand; } } + + // Experimental Code. Anti Desync feature for ESC's + if (escAndServoConfig->escDesyncProtection) { + const int16_t maxThrottleStep = escAndServoConfig->escDesyncProtection / (1000 / targetPidLooptime); + static int16_t motorPrevious[MAX_SUPPORTED_MOTORS]; + + motor[i] = constrain(motor[i], motorPrevious[i] - maxThrottleStep, motorPrevious[i] + maxThrottleStep); + motorPrevious[i] = motor[i]; + } } // Disarmed mode diff --git a/src/main/io/escservo.h b/src/main/io/escservo.h index 66cd7db59..b73f9920f 100644 --- a/src/main/io/escservo.h +++ b/src/main/io/escservo.h @@ -24,4 +24,5 @@ typedef struct escAndServoConfig_s { uint16_t maxthrottle; // This is the maximum value for the ESCs at full power this value can be increased up to 2000 uint16_t mincommand; // This is the value for the ESCs when they are not armed. In some cases, this value must be lowered down to 900 for some specific ESCs uint16_t servoCenterPulse; // This is the value for servos when they should be in the middle. e.g. 1500. + uint16_t escDesyncProtection; // Value that a motor is allowed to increase or decrease in a period of 1ms } escAndServoConfig_t; diff --git a/src/main/io/serial_cli.c b/src/main/io/serial_cli.c index 56d143a0d..a400d7509 100644 --- a/src/main/io/serial_cli.c +++ b/src/main/io/serial_cli.c @@ -565,6 +565,7 @@ const clivalue_t valueTable[] = { { "min_throttle", VAR_UINT16 | MASTER_VALUE, &masterConfig.escAndServoConfig.minthrottle, .config.minmax = { PWM_RANGE_ZERO, PWM_RANGE_MAX } }, { "max_throttle", VAR_UINT16 | MASTER_VALUE, &masterConfig.escAndServoConfig.maxthrottle, .config.minmax = { PWM_RANGE_ZERO, PWM_RANGE_MAX } }, { "min_command", VAR_UINT16 | MASTER_VALUE, &masterConfig.escAndServoConfig.mincommand, .config.minmax = { PWM_RANGE_ZERO, PWM_RANGE_MAX } }, + { "anti_desync_power_step", VAR_UINT16 | MASTER_VALUE, &masterConfig.escAndServoConfig.escDesyncProtection, .config.minmax = { 0, 2000 } }, { "servo_center_pulse", VAR_UINT16 | MASTER_VALUE, &masterConfig.escAndServoConfig.servoCenterPulse, .config.minmax = { PWM_RANGE_ZERO, PWM_RANGE_MAX } }, { "3d_deadband_low", VAR_UINT16 | MASTER_VALUE, &masterConfig.flight3DConfig.deadband3d_low, .config.minmax = { PWM_RANGE_ZERO, PWM_RANGE_MAX } }, // FIXME upper limit should match code in the mixer, 1500 currently -- 2.11.4.GIT