1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-17 13:25:30 +03:00

Changes from review

Used HZ_TO_INTERVAL_US() instead of hardcoded 500us.

Moved tests into a dedicated function.
This commit is contained in:
Bruce Luckcuck 2018-07-29 17:16:01 -04:00
parent f411b82eb6
commit 25c6b038d9
5 changed files with 9 additions and 4 deletions

View file

@ -60,6 +60,7 @@
#include "sensors/acceleration.h" #include "sensors/acceleration.h"
#include "sensors/battery.h" #include "sensors/battery.h"
#include "sensors/gyro.h" #include "sensors/gyro.h"
#include "sensors/gyroanalyse.h"
#ifndef USE_OSD_SLAVE #ifndef USE_OSD_SLAVE
pidProfile_t *currentPidProfile; pidProfile_t *currentPidProfile;
@ -410,10 +411,12 @@ static void validateAndFixConfig(void)
#ifndef USE_OSD_SLAVE #ifndef USE_OSD_SLAVE
void validateAndFixGyroConfig(void) void validateAndFixGyroConfig(void)
{ {
#ifdef USE_GYRO_DATA_ANALYSE
// Disable dynamic filter if gyro loop is less than 2KHz // Disable dynamic filter if gyro loop is less than 2KHz
if (gyro.targetLooptime > GYRO_LOOPTIME_2KHZ) { if (!dynamicFilterAllowed()) {
featureClear(FEATURE_DYNAMIC_FILTER); featureClear(FEATURE_DYNAMIC_FILTER);
} }
#endif
// Prevent invalid notch cutoff // Prevent invalid notch cutoff
if (gyroConfig()->gyro_soft_notch_cutoff_1 >= gyroConfig()->gyro_soft_notch_hz_1) { if (gyroConfig()->gyro_soft_notch_cutoff_1 >= gyroConfig()->gyro_soft_notch_hz_1) {

View file

@ -743,7 +743,7 @@ static void gyroInitFilterNotch2(gyroSensor_t *gyroSensor, uint16_t notchHz, uin
#ifdef USE_GYRO_DATA_ANALYSE #ifdef USE_GYRO_DATA_ANALYSE
static bool isDynamicFilterActive(void) static bool isDynamicFilterActive(void)
{ {
return feature(FEATURE_DYNAMIC_FILTER) && (gyro.targetLooptime <= GYRO_LOOPTIME_2KHZ); return feature(FEATURE_DYNAMIC_FILTER) && dynamicFilterAllowed();
} }
static void gyroInitFilterDynamicNotch(gyroSensor_t *gyroSensor) static void gyroInitFilterDynamicNotch(gyroSensor_t *gyroSensor)

View file

@ -26,8 +26,6 @@
#include "drivers/bus.h" #include "drivers/bus.h"
#include "drivers/sensor.h" #include "drivers/sensor.h"
#define GYRO_LOOPTIME_2KHZ 500
typedef enum { typedef enum {
GYRO_NONE = 0, GYRO_NONE = 0,
GYRO_DEFAULT, GYRO_DEFAULT,

View file

@ -304,4 +304,7 @@ static FAST_CODE_NOINLINE void gyroDataAnalyseUpdate(gyroAnalyseState_t *state,
state->updateStep = (state->updateStep + 1) % STEP_COUNT; state->updateStep = (state->updateStep + 1) % STEP_COUNT;
} }
bool dynamicFilterAllowed(void) {
return (gyro.targetLooptime <= HZ_TO_INTERVAL_US(2000));
}
#endif // USE_GYRO_DATA_ANALYSE #endif // USE_GYRO_DATA_ANALYSE

View file

@ -61,3 +61,4 @@ void gyroDataAnalyseInit(void);
void gyroDataAnalyseStateInit(gyroAnalyseState_t *gyroAnalyse, uint32_t targetLooptime); void gyroDataAnalyseStateInit(gyroAnalyseState_t *gyroAnalyse, uint32_t targetLooptime);
void gyroDataAnalysePush(gyroAnalyseState_t *gyroAnalyse, int axis, float sample); void gyroDataAnalysePush(gyroAnalyseState_t *gyroAnalyse, int axis, float sample);
void gyroDataAnalyse(gyroAnalyseState_t *gyroAnalyse, biquadFilter_t *notchFilterDyn); void gyroDataAnalyse(gyroAnalyseState_t *gyroAnalyse, biquadFilter_t *notchFilterDyn);
bool dynamicFilterAllowed(void);