From 188cd2649209c9055e29f00c177462471c43e00b Mon Sep 17 00:00:00 2001 From: borisbstyle Date: Mon, 1 Aug 2016 16:14:11 +0200 Subject: [PATCH 1/5] Fix motor spinning issue on save for multishot / oneshot42 --- src/main/config/config.c | 7 ++----- src/main/version.h | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/config/config.c b/src/main/config/config.c index 330561d7e8..7debf0f162 100755 --- a/src/main/config/config.c +++ b/src/main/config/config.c @@ -1060,11 +1060,8 @@ void handleOneshotFeatureChangeOnRestart(void) { // Shutdown PWM on all motors prior to soft restart StopPwmAllMotors(); - delay(50); - // Apply additional delay when OneShot125 feature changed from on to off state - if (feature(FEATURE_ONESHOT125) && !featureConfigured(FEATURE_ONESHOT125)) { - delay(ONESHOT_FEATURE_CHANGED_DELAY_ON_BOOT_MS); - } + // Apply additional delay + delay(ONESHOT_FEATURE_CHANGED_DELAY_ON_BOOT_MS); } void latchActiveFeatures() diff --git a/src/main/version.h b/src/main/version.h index 5ec30cdd32..eb4d3b0450 100644 --- a/src/main/version.h +++ b/src/main/version.h @@ -17,7 +17,7 @@ #define FC_VERSION_MAJOR 2 // increment when a major release is made (big new feature, etc) #define FC_VERSION_MINOR 9 // increment when a minor release is made (small new feature, change etc) -#define FC_VERSION_PATCH_LEVEL 0 // increment when a bug is fixed +#define FC_VERSION_PATCH_LEVEL 1 // increment when a bug is fixed #define STR_HELPER(x) #x #define STR(x) STR_HELPER(x) From 2e0433c78f9195346bec9eb434a8444374a3ec1f Mon Sep 17 00:00:00 2001 From: borisbstyle Date: Mon, 1 Aug 2016 16:45:03 +0200 Subject: [PATCH 2/5] Cleanup MSP --- src/main/io/serial_msp.c | 27 +++++++++------------------ src/main/io/serial_msp.h | 11 ++++------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/main/io/serial_msp.c b/src/main/io/serial_msp.c index ab195fa8fd..f59a5e2882 100644 --- a/src/main/io/serial_msp.c +++ b/src/main/io/serial_msp.c @@ -859,7 +859,7 @@ static bool processOutCommand(uint8_t cmdMSP) serialize16((uint16_t)targetLooptime); break; case MSP_RC_TUNING: - headSerialReply(11); + headSerialReply(12); serialize8(currentControlRateProfile->rcRate8); serialize8(currentControlRateProfile->rcExpo8); for (i = 0 ; i < 3; i++) { @@ -870,6 +870,7 @@ static bool processOutCommand(uint8_t cmdMSP) serialize8(currentControlRateProfile->thrExpo8); serialize16(currentControlRateProfile->tpa_breakpoint); serialize8(currentControlRateProfile->rcYawExpo8); + serialize8(currentControlRateProfile->rcYawRate8); break; case MSP_PID: headSerialReply(3 * PID_ITEM_COUNT); @@ -1244,7 +1245,7 @@ static bool processOutCommand(uint8_t cmdMSP) serialize8(masterConfig.sensorAlignmentConfig.acc_align); serialize8(masterConfig.sensorAlignmentConfig.mag_align); break; - case MSP_PID_ADVANCED_CONFIG : + case MSP_ADVANCED_CONFIG : headSerialReply(6); serialize8(masterConfig.gyro_sync_denom); serialize8(masterConfig.pid_process_denom); @@ -1258,7 +1259,7 @@ static bool processOutCommand(uint8_t cmdMSP) serialize16(currentProfile->pidProfile.dterm_lpf_hz); serialize16(currentProfile->pidProfile.yaw_lpf_hz); break; - case MSP_ADVANCED_TUNING: + case MSP_PID_ADVANCED: headSerialReply(3 * 2 + 2); serialize16(currentProfile->pidProfile.rollPitchItermIgnoreRate); serialize16(currentProfile->pidProfile.yawItermIgnoreRate); @@ -1266,13 +1267,6 @@ static bool processOutCommand(uint8_t cmdMSP) serialize8(currentProfile->pidProfile.deltaMethod); serialize8(masterConfig.batteryConfig.vbatPidCompensation); break; - case MSP_SPECIAL_PARAMETERS: - headSerialReply(1 + 2 + 1 + 2); - serialize8(currentControlRateProfile->rcYawRate8); - serialize16(masterConfig.rxConfig.airModeActivateThreshold); - serialize8(masterConfig.rxConfig.rcSmoothInterval); - serialize16(masterConfig.escAndServoConfig.escDesyncProtection); - break; case MSP_SENSOR_CONFIG: headSerialReply(3); serialize8(masterConfig.acc_hardware); @@ -1407,6 +1401,9 @@ static bool processInCommand(void) if (currentPort->dataSize >= 11) { currentControlRateProfile->rcYawExpo8 = read8(); } + if (currentPort->dataSize >= 12) { + currentControlRateProfile->rcYawRate8 = read8(); + } } else { headSerialError(0); } @@ -1792,7 +1789,7 @@ static bool processInCommand(void) break; #endif - case MSP_SET_PID_ADVANCED_CONFIG : + case MSP_SET_ADVANCED_CONFIG : masterConfig.gyro_sync_denom = read8(); masterConfig.pid_process_denom = read8(); masterConfig.use_unsyncedPwm = read8(); @@ -1804,19 +1801,13 @@ static bool processInCommand(void) currentProfile->pidProfile.dterm_lpf_hz = read16(); currentProfile->pidProfile.yaw_lpf_hz = read16(); break; - case MSP_SET_ADVANCED_TUNING: + case MSP_SET_PID_ADVANCED: currentProfile->pidProfile.rollPitchItermIgnoreRate = read16(); currentProfile->pidProfile.yawItermIgnoreRate = read16(); currentProfile->pidProfile.yaw_p_limit = read16(); currentProfile->pidProfile.deltaMethod = read8(); masterConfig.batteryConfig.vbatPidCompensation = read8(); break; - case MSP_SET_SPECIAL_PARAMETERS: - currentControlRateProfile->rcYawRate8 = read8(); - masterConfig.rxConfig.airModeActivateThreshold = read16(); - masterConfig.rxConfig.rcSmoothInterval = read8(); - masterConfig.escAndServoConfig.escDesyncProtection = read16(); - break; case MSP_SET_SENSOR_CONFIG: masterConfig.acc_hardware = read8(); masterConfig.baro_hardware = read8(); diff --git a/src/main/io/serial_msp.h b/src/main/io/serial_msp.h index ca165ef8ec..8946bb1c66 100644 --- a/src/main/io/serial_msp.h +++ b/src/main/io/serial_msp.h @@ -185,22 +185,19 @@ static const char * const boardIdentifier = TARGET_BOARD_IDENTIFIER; #define MSP_BF_BUILD_INFO 69 //out message build date as well as some space for future expansion // Betaflight Additional Commands -#define MSP_PID_ADVANCED_CONFIG 90 -#define MSP_SET_PID_ADVANCED_CONFIG 91 +#define MSP_ADVANCED_CONFIG 90 +#define MSP_SET_ADVANCED_CONFIG 91 #define MSP_FILTER_CONFIG 92 #define MSP_SET_FILTER_CONFIG 93 -#define MSP_ADVANCED_TUNING 94 -#define MSP_SET_ADVANCED_TUNING 95 +#define MSP_PID_ADVANCED 94 +#define MSP_SET_PID_ADVANCED 95 #define MSP_SENSOR_CONFIG 96 #define MSP_SET_SENSOR_CONFIG 97 -#define MSP_SPECIAL_PARAMETERS 98 // Temporary betaflight parameters before cleanup and keep CF compatibility -#define MSP_SET_SPECIAL_PARAMETERS 99 // Temporary betaflight parameters before cleanup and keep CF compatibility -// // Multwii original MSP commands // From 571b9ba99187c7bef5b5bec21bdd41fe420f84e4 Mon Sep 17 00:00:00 2001 From: borisbstyle Date: Tue, 2 Aug 2016 21:01:34 +0200 Subject: [PATCH 3/5] Add CPU load in MSP_STATUS_EX --- src/main/io/serial_msp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/io/serial_msp.c b/src/main/io/serial_msp.c index f59a5e2882..e2157be0bf 100644 --- a/src/main/io/serial_msp.c +++ b/src/main/io/serial_msp.c @@ -740,7 +740,7 @@ static bool processOutCommand(uint8_t cmdMSP) break; case MSP_STATUS_EX: - headSerialReply(12); + headSerialReply(13); serialize16(cycleTime); #ifdef USE_I2C serialize16(i2cGetErrorCounter()); @@ -750,7 +750,7 @@ static bool processOutCommand(uint8_t cmdMSP) serialize16(sensors(SENSOR_ACC) | sensors(SENSOR_BARO) << 1 | sensors(SENSOR_MAG) << 2 | sensors(SENSOR_GPS) << 3 | sensors(SENSOR_SONAR) << 4); serialize32(packFlightModeFlags()); serialize8(masterConfig.current_profile_index); - //serialize16(averageSystemLoadPercent); + serialize16(constrain(averageSystemLoadPercent, 0, 100)); break; case MSP_STATUS: From 3cd6ed42452392bada7b9aab321f6a1afc250b89 Mon Sep 17 00:00:00 2001 From: borisbstyle Date: Tue, 2 Aug 2016 23:13:59 +0200 Subject: [PATCH 4/5] Fix oneshot timer overflow by @nathansoi --- src/main/drivers/pwm_output.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/drivers/pwm_output.c b/src/main/drivers/pwm_output.c index 9a49661a51..7f928891e8 100644 --- a/src/main/drivers/pwm_output.c +++ b/src/main/drivers/pwm_output.c @@ -170,18 +170,18 @@ void pwmEnableMotors(void) void pwmCompleteOneshotMotorUpdate(uint8_t motorCount) { - uint8_t index; - TIM_TypeDef *lastTimerPtr = NULL; - - for(index = 0; index < motorCount; index++){ - - // Force the timer to overflow if it's the first motor to output, or if we change timers - if(motors[index]->tim != lastTimerPtr){ - lastTimerPtr = motors[index]->tim; - - timerForceOverflow(motors[index]->tim); + for (int index = 0; index < motorCount; index++) { + bool overflowed = false; + // If we have not already overflowed this timer + for (int j = 0; j < index; j++) { + if (motors[j]->tim == motors[index]->tim) { + overflowed = true; + break; + } + } + if (!overflowed) { + timerForceOverflow(motors[index]->tim); } - // Set the compare register to 0, which stops the output pulsing if the timer overflows before the main loop completes again. // This compare register will be set to the output value on the next main loop. *motors[index]->ccr = 0; From 0ef6c3d6f66b6d371041d56b9a0bd6ed81dbfa53 Mon Sep 17 00:00:00 2001 From: borisbstyle Date: Tue, 2 Aug 2016 23:30:33 +0200 Subject: [PATCH 5/5] Fix gyro_lpf visualisation in configurator --- src/main/io/serial_msp.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/io/serial_msp.c b/src/main/io/serial_msp.c index e2157be0bf..63a18299d4 100644 --- a/src/main/io/serial_msp.c +++ b/src/main/io/serial_msp.c @@ -1247,8 +1247,13 @@ static bool processOutCommand(uint8_t cmdMSP) break; case MSP_ADVANCED_CONFIG : headSerialReply(6); - serialize8(masterConfig.gyro_sync_denom); - serialize8(masterConfig.pid_process_denom); + if (masterConfig.gyro_lpf) { + serialize8(8); // If gyro_lpf != OFF then looptime is set to 1000 + serialize8(1); + } else { + serialize8(masterConfig.gyro_sync_denom); + serialize8(masterConfig.pid_process_denom); + } serialize8(masterConfig.use_unsyncedPwm); serialize8(masterConfig.fast_pwm_protocol); serialize16(masterConfig.motor_pwm_rate);