From 5ffb3b5068568d49eba97ec023040ca10cea6a7e Mon Sep 17 00:00:00 2001 From: borisbstyle Date: Wed, 4 May 2016 00:00:04 +0200 Subject: [PATCH] Revert "Merge pull request #372 from aughey/betaflight" This reverts commit a6a5f50ffbd470175e8dae9e17e4d5f4424996f9, reversing changes made to 9cc55038516f52896ece099b6959a3413c25891f. --- src/main/common/maths.c | 20 ++++++++++++++++++++ src/main/common/maths.h | 22 ---------------------- src/main/config/config.c | 7 ------- src/main/flight/mixer.c | 9 +++------ src/main/main.c | 19 +++++-------------- src/main/sensors/initialisation.c | 11 ++--------- 6 files changed, 30 insertions(+), 58 deletions(-) diff --git a/src/main/common/maths.c b/src/main/common/maths.c index 888847e075..3be8eff722 100644 --- a/src/main/common/maths.c +++ b/src/main/common/maths.c @@ -111,6 +111,26 @@ int32_t applyDeadband(int32_t value, int32_t deadband) return value; } +inline int constrain(int amt, int low, int high) +{ + if (amt < low) + return low; + else if (amt > high) + return high; + else + return amt; +} + +inline float constrainf(float amt, float low, float high) +{ + if (amt < low) + return low; + else if (amt > high) + return high; + else + return amt; +} + void devClear(stdev_t *dev) { dev->m_n = 0; diff --git a/src/main/common/maths.h b/src/main/common/maths.h index 95f0ee8583..4a32e282c0 100644 --- a/src/main/common/maths.h +++ b/src/main/common/maths.h @@ -116,25 +116,3 @@ void arraySubInt32(int32_t *dest, int32_t *array1, int32_t *array2, int count); int16_t qPercent(fix12_t q); int16_t qMultiply(fix12_t q, int16_t input); fix12_t qConstruct(int16_t num, int16_t den); - -// Defining constrain and constrainf as inline in the include file -// because these functions are used universally and should be fast. -inline int constrain(int amt, int low, int high) -{ - if (amt < low) - return low; - else if (amt > high) - return high; - else - return amt; -} - -inline float constrainf(float amt, float low, float high) -{ - if (amt < low) - return low; - else if (amt > high) - return high; - else - return amt; -} diff --git a/src/main/config/config.c b/src/main/config/config.c index 7844c0795b..4d6c046128 100755 --- a/src/main/config/config.c +++ b/src/main/config/config.c @@ -124,15 +124,8 @@ void useRcControlsConfig(modeActivationCondition_t *modeActivationConditions, es #define FLASH_TO_RESERVE_FOR_CONFIG 0x1000 #endif -// use the last flash pages for storage -#ifdef CUSTOM_FLASH_MEMORY_ADDRESS -size_t custom_flash_memory_address = 0; -#define CONFIG_START_FLASH_ADDRESS (custom_flash_memory_address) -#else // use the last flash pages for storage #define CONFIG_START_FLASH_ADDRESS (0x08000000 + (uint32_t)((FLASH_PAGE_SIZE * FLASH_PAGE_COUNT) - FLASH_TO_RESERVE_FOR_CONFIG)) -#endif - master_t masterConfig; // master config struct with data independent from profiles profile_t *currentProfile; diff --git a/src/main/flight/mixer.c b/src/main/flight/mixer.c index 813ec50f58..802e7e780e 100755 --- a/src/main/flight/mixer.c +++ b/src/main/flight/mixer.c @@ -753,11 +753,6 @@ void mixTable(void) uint32_t i; fix12_t vbatCompensationFactor; static fix12_t mixReduction; - bool use_vbat_compensation = false; - if (batteryConfig && batteryConfig->vbatPidCompensation) { - use_vbat_compensation = true; - vbatCompensationFactor = calculateVbatPidCompensation(); - } bool isFailsafeActive = failsafeIsActive(); // TODO - Find out if failsafe checks are really needed here in mixer code @@ -771,6 +766,8 @@ void mixTable(void) int16_t rollPitchYawMixMax = 0; // assumption: symetrical about zero. int16_t rollPitchYawMixMin = 0; + if (batteryConfig->vbatPidCompensation) vbatCompensationFactor = calculateVbatPidCompensation(); // Calculate voltage compensation + // Find roll/pitch/yaw desired output for (i = 0; i < motorCount; i++) { rollPitchYawMix[i] = @@ -778,7 +775,7 @@ void mixTable(void) axisPID[ROLL] * currentMixer[i].roll + -mixerConfig->yaw_motor_direction * axisPID[YAW] * currentMixer[i].yaw; - if (use_vbat_compensation) rollPitchYawMix[i] = qMultiply(vbatCompensationFactor, rollPitchYawMix[i]); // Add voltage compensation + if (batteryConfig->vbatPidCompensation) rollPitchYawMix[i] = qMultiply(vbatCompensationFactor, rollPitchYawMix[i]); // Add voltage compensation if (rollPitchYawMix[i] > rollPitchYawMixMax) rollPitchYawMixMax = rollPitchYawMix[i]; if (rollPitchYawMix[i] < rollPitchYawMixMin) rollPitchYawMixMin = rollPitchYawMix[i]; diff --git a/src/main/main.c b/src/main/main.c index 56e9077d4e..49fc7c2466 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -26,6 +26,7 @@ #include "common/axis.h" #include "common/color.h" +#include "common/atomic.h" #include "common/maths.h" #include "drivers/nvic.h" @@ -657,7 +658,7 @@ void processLoopback(void) { #define processLoopback() #endif -void main_init(void) { +int main(void) { init(); /* Setup scheduler */ @@ -728,22 +729,12 @@ void main_init(void) { #ifdef USE_BST setTaskEnabled(TASK_BST_MASTER_PROCESS, true); #endif -} -void main_step(void) { - scheduler(); - processLoopback(); -} - -#ifndef NOMAIN -int main(void) -{ - main_init(); - while(1) { - main_step(); + while (1) { + scheduler(); + processLoopback(); } } -#endif #ifdef DEBUG_HARDFAULTS //from: https://mcuoneclipse.com/2012/11/24/debugging-hard-faults-on-arm-cortex-m/ diff --git a/src/main/sensors/initialisation.c b/src/main/sensors/initialisation.c index 415ebbc4a4..9c49090d4f 100755 --- a/src/main/sensors/initialisation.c +++ b/src/main/sensors/initialisation.c @@ -214,7 +214,6 @@ const extiConfig_t *selectMPUIntExtiConfig(void) } #ifdef USE_FAKE_GYRO -int16_t fake_gyro_values[XYZ_AXIS_COUNT] = { 0,0,0 }; static void fakeGyroInit(uint16_t lpf) { UNUSED(lpf); @@ -222,9 +221,7 @@ static void fakeGyroInit(uint16_t lpf) static bool fakeGyroRead(int16_t *gyroADC) { - for (int i = 0; i < XYZ_AXIS_COUNT; ++i) { - gyroADC[i] = fake_gyro_values[i]; - } + memset(gyroADC, 0, sizeof(int16_t[XYZ_AXIS_COUNT])); return true; } @@ -244,13 +241,9 @@ bool fakeGyroDetect(gyro_t *gyro) #endif #ifdef USE_FAKE_ACC -int16_t fake_acc_values[XYZ_AXIS_COUNT] = {0,0,0}; - static void fakeAccInit(void) {} static bool fakeAccRead(int16_t *accData) { - for(int i=0;i