Skip to content

Commit

Permalink
Dynamic notch refactoring
Browse files Browse the repository at this point in the history
+ added new parameter group for Dyn Notch
  • Loading branch information
KarateBrot authored and mikeller committed Sep 1, 2021
1 parent 4c9eb21 commit 8649f10
Show file tree
Hide file tree
Showing 19 changed files with 300 additions and 243 deletions.
4 changes: 2 additions & 2 deletions make/source.mk
Expand Up @@ -91,7 +91,7 @@ COMMON_SRC = \
flight/position.c \
flight/failsafe.c \
flight/gps_rescue.c \
flight/gyroanalyse.c \
flight/dyn_notch_filter.c \
flight/imu.c \
flight/feedforward.c \
flight/mixer.c \
Expand Down Expand Up @@ -257,7 +257,7 @@ SPEED_OPTIMISED_SRC := $(SPEED_OPTIMISED_SRC) \
fc/rc.c \
fc/rc_controls.c \
fc/runtime_config.c \
flight/gyroanalyse.c \
flight/dyn_notch_filter.c \
flight/imu.c \
flight/mixer.c \
flight/pid.c \
Expand Down
10 changes: 5 additions & 5 deletions src/main/blackbox/blackbox.c
Expand Up @@ -1419,11 +1419,11 @@ static bool blackboxWriteSysinfo(void)
BLACKBOX_PRINT_HEADER_LINE("gyro_notch_cutoff", "%d,%d", gyroConfig()->gyro_soft_notch_cutoff_1,
gyroConfig()->gyro_soft_notch_cutoff_2);
BLACKBOX_PRINT_HEADER_LINE("gyro_to_use", "%d", gyroConfig()->gyro_to_use);
#ifdef USE_GYRO_DATA_ANALYSE
BLACKBOX_PRINT_HEADER_LINE("dyn_notch_max_hz", "%d", gyroConfig()->dyn_notch_max_hz);
BLACKBOX_PRINT_HEADER_LINE("dyn_notch_count", "%d", gyroConfig()->dyn_notch_count);
BLACKBOX_PRINT_HEADER_LINE("dyn_notch_q", "%d", gyroConfig()->dyn_notch_q);
BLACKBOX_PRINT_HEADER_LINE("dyn_notch_min_hz", "%d", gyroConfig()->dyn_notch_min_hz);
#ifdef USE_DYN_NOTCH_FILTER
BLACKBOX_PRINT_HEADER_LINE("dyn_notch_max_hz", "%d", dynNotchConfig()->dyn_notch_max_hz);
BLACKBOX_PRINT_HEADER_LINE("dyn_notch_count", "%d", dynNotchConfig()->dyn_notch_count);
BLACKBOX_PRINT_HEADER_LINE("dyn_notch_q", "%d", dynNotchConfig()->dyn_notch_q);
BLACKBOX_PRINT_HEADER_LINE("dyn_notch_min_hz", "%d", dynNotchConfig()->dyn_notch_min_hz);
#endif
#ifdef USE_DSHOT_TELEMETRY
BLACKBOX_PRINT_HEADER_LINE("dshot_bidir", "%d", motorConfig()->dev.useDshotTelemetry);
Expand Down
13 changes: 7 additions & 6 deletions src/main/cli/settings.c
Expand Up @@ -81,6 +81,7 @@
#include "pg/bus_i2c.h"
#include "pg/dashboard.h"
#include "pg/displayport_profiles.h"
#include "pg/dyn_notch.h"
#include "pg/flash.h"
#include "pg/gyrodev.h"
#include "pg/max7456.h"
Expand Down Expand Up @@ -660,11 +661,11 @@ const clivalue_t valueTable[] = {
#ifdef USE_MULTI_GYRO
{ "gyro_to_use", VAR_UINT8 | HARDWARE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_GYRO }, PG_GYRO_CONFIG, offsetof(gyroConfig_t, gyro_to_use) },
#endif
#if defined(USE_GYRO_DATA_ANALYSE)
{ "dyn_notch_count", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 1, DYN_NOTCH_COUNT_MAX }, PG_GYRO_CONFIG, offsetof(gyroConfig_t, dyn_notch_count) },
{ "dyn_notch_q", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 1, 1000 }, PG_GYRO_CONFIG, offsetof(gyroConfig_t, dyn_notch_q) },
{ "dyn_notch_min_hz", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 60, 250 }, PG_GYRO_CONFIG, offsetof(gyroConfig_t, dyn_notch_min_hz) },
{ "dyn_notch_max_hz", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 200, 1000 }, PG_GYRO_CONFIG, offsetof(gyroConfig_t, dyn_notch_max_hz) },
#if defined(USE_DYN_NOTCH_FILTER)
{ "dyn_notch_count", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 1, DYN_NOTCH_COUNT_MAX }, PG_DYN_NOTCH_CONFIG, offsetof(dynNotchConfig_t, dyn_notch_count) },
{ "dyn_notch_q", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 1, 1000 }, PG_DYN_NOTCH_CONFIG, offsetof(dynNotchConfig_t, dyn_notch_q) },
{ "dyn_notch_min_hz", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 60, 250 }, PG_DYN_NOTCH_CONFIG, offsetof(dynNotchConfig_t, dyn_notch_min_hz) },
{ "dyn_notch_max_hz", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 200, 1000 }, PG_DYN_NOTCH_CONFIG, offsetof(dynNotchConfig_t, dyn_notch_max_hz) },
#endif
#ifdef USE_DYN_LPF
{ "dyn_lpf_gyro_min_hz", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 0, DYN_LPF_FILTER_FREQUENCY_MAX }, PG_GYRO_CONFIG, offsetof(gyroConfig_t, dyn_lpf_gyro_min_hz) },
Expand Down Expand Up @@ -1434,7 +1435,7 @@ const clivalue_t valueTable[] = {
{ "osd_stat_max_esc_rpm", VAR_UINT32 | MASTER_VALUE | MODE_BITSET, .config.bitpos = OSD_STAT_MAX_ESC_RPM, PG_OSD_CONFIG, offsetof(osdConfig_t, enabled_stats)},
{ "osd_stat_min_link_quality", VAR_UINT32 | MASTER_VALUE | MODE_BITSET, .config.bitpos = OSD_STAT_MIN_LINK_QUALITY,PG_OSD_CONFIG, offsetof(osdConfig_t, enabled_stats)},
{ "osd_stat_flight_dist", VAR_UINT32 | MASTER_VALUE | MODE_BITSET, .config.bitpos = OSD_STAT_FLIGHT_DISTANCE, PG_OSD_CONFIG, offsetof(osdConfig_t, enabled_stats)},
#ifdef USE_GYRO_DATA_ANALYSE
#ifdef USE_DYN_NOTCH_FILTER
{ "osd_stat_max_fft", VAR_UINT32 | MASTER_VALUE | MODE_BITSET, .config.bitpos = OSD_STAT_MAX_FFT, PG_OSD_CONFIG, offsetof(osdConfig_t, enabled_stats)},
#endif
#ifdef USE_PERSISTENT_STATS
Expand Down
32 changes: 16 additions & 16 deletions src/main/cms/cms_menu_imu.c
Expand Up @@ -752,11 +752,11 @@ static CMS_Menu cmsx_menuFilterGlobal = {
.entries = cmsx_menuFilterGlobalEntries,
};

#if (defined(USE_GYRO_DATA_ANALYSE) || defined(USE_DYN_LPF)) && defined(USE_EXTENDED_CMS_MENUS)
#if (defined(USE_DYN_NOTCH_FILTER) || defined(USE_DYN_LPF)) && defined(USE_EXTENDED_CMS_MENUS)

#ifdef USE_GYRO_DATA_ANALYSE
#ifdef USE_DYN_NOTCH_FILTER
static uint16_t dynFiltNotchMaxHz;
static uint8_t dynFiltCount;
static uint8_t dynFiltNotchCount;
static uint16_t dynFiltNotchQ;
static uint16_t dynFiltNotchMinHz;
#endif
Expand All @@ -773,11 +773,11 @@ static const void *cmsx_menuDynFilt_onEnter(displayPort_t *pDisp)
{
UNUSED(pDisp);

#ifdef USE_GYRO_DATA_ANALYSE
dynFiltNotchMaxHz = gyroConfig()->dyn_notch_max_hz;
dynFiltCount = gyroConfig()->dyn_notch_count;
dynFiltNotchQ = gyroConfig()->dyn_notch_q;
dynFiltNotchMinHz = gyroConfig()->dyn_notch_min_hz;
#ifdef USE_DYN_NOTCH_FILTER
dynFiltNotchMaxHz = dynNotchConfig()->dyn_notch_max_hz;
dynFiltNotchCount = dynNotchConfig()->dyn_notch_count;
dynFiltNotchQ = dynNotchConfig()->dyn_notch_q;
dynFiltNotchMinHz = dynNotchConfig()->dyn_notch_min_hz;
#endif
#ifdef USE_DYN_LPF
const pidProfile_t *pidProfile = pidProfiles(pidProfileIndex);
Expand All @@ -797,11 +797,11 @@ static const void *cmsx_menuDynFilt_onExit(displayPort_t *pDisp, const OSD_Entry
UNUSED(pDisp);
UNUSED(self);

#ifdef USE_GYRO_DATA_ANALYSE
gyroConfigMutable()->dyn_notch_max_hz = dynFiltNotchMaxHz;
gyroConfigMutable()->dyn_notch_count = dynFiltCount;
gyroConfigMutable()->dyn_notch_q = dynFiltNotchQ;
gyroConfigMutable()->dyn_notch_min_hz = dynFiltNotchMinHz;
#ifdef USE_DYN_NOTCH_FILTER
dynNotchConfigMutable()->dyn_notch_max_hz = dynFiltNotchMaxHz;
dynNotchConfigMutable()->dyn_notch_count = dynFiltNotchCount;
dynNotchConfigMutable()->dyn_notch_q = dynFiltNotchQ;
dynNotchConfigMutable()->dyn_notch_min_hz = dynFiltNotchMinHz;
#endif
#ifdef USE_DYN_LPF
pidProfile_t *pidProfile = currentPidProfile;
Expand All @@ -820,8 +820,8 @@ static const OSD_Entry cmsx_menuDynFiltEntries[] =
{
{ "-- DYN FILT --", OME_Label, NULL, NULL, 0 },

#ifdef USE_GYRO_DATA_ANALYSE
{ "NOTCH COUNT", OME_UINT8, NULL, &(OSD_UINT8_t) { &dynFiltCount, 1, DYN_NOTCH_COUNT_MAX, 1 }, 0 },
#ifdef USE_DYN_NOTCH_FILTER
{ "NOTCH COUNT", OME_UINT8, NULL, &(OSD_UINT8_t) { &dynFiltNotchCount, 1, DYN_NOTCH_COUNT_MAX, 1 }, 0 },
{ "NOTCH Q", OME_UINT16, NULL, &(OSD_UINT16_t) { &dynFiltNotchQ, 1, 1000, 1 }, 0 },
{ "NOTCH MIN HZ", OME_UINT16, NULL, &(OSD_UINT16_t) { &dynFiltNotchMinHz, 0, 1000, 1 }, 0 },
{ "NOTCH MAX HZ", OME_UINT16, NULL, &(OSD_UINT16_t) { &dynFiltNotchMaxHz, 0, 1000, 1 }, 0 },
Expand Down Expand Up @@ -1006,7 +1006,7 @@ static const OSD_Entry cmsx_menuImuEntries[] =
{"RATE", OME_Submenu, cmsMenuChange, &cmsx_menuRateProfile, 0},

{"FILT GLB", OME_Submenu, cmsMenuChange, &cmsx_menuFilterGlobal, 0},
#if (defined(USE_GYRO_DATA_ANALYSE) || defined(USE_DYN_LPF)) && defined(USE_EXTENDED_CMS_MENUS)
#if (defined(USE_DYN_NOTCH_FILTER) || defined(USE_DYN_LPF)) && defined(USE_EXTENDED_CMS_MENUS)
{"DYN FILT", OME_Submenu, cmsMenuChange, &cmsx_menuDynFilt, 0},
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/main/config/config.c
Expand Up @@ -466,7 +466,7 @@ static void validateAndFixConfig(void)
featureDisableImmediate(FEATURE_ESC_SENSOR);
#endif

#ifndef USE_GYRO_DATA_ANALYSE
#ifndef USE_DYN_NOTCH_FILTER
featureDisableImmediate(FEATURE_DYNAMIC_FILTER);
#endif

Expand Down Expand Up @@ -682,7 +682,7 @@ void validateAndFixGyroConfig(void)
}
}

#ifdef USE_GYRO_DATA_ANALYSE
#ifdef USE_DYN_NOTCH_FILTER
// Disable dynamic filter if gyro loop is less than 2KHz
const uint32_t configuredLooptime = (gyro.sampleRateHz > 0) ? (pidConfig()->pid_process_denom * 1e6 / gyro.sampleRateHz) : 0;
if (configuredLooptime > DYNAMIC_FILTER_MAX_SUPPORTED_LOOP_TIME) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/fc/core.c
Expand Up @@ -61,8 +61,8 @@
#include "flight/failsafe.h"
#include "flight/gps_rescue.h"

#if defined(USE_GYRO_DATA_ANALYSE)
#include "flight/gyroanalyse.h"
#if defined(USE_DYN_NOTCH_FILTER)
#include "flight/dyn_notch_filter.h"
#endif

#include "flight/imu.h"
Expand Down Expand Up @@ -550,7 +550,7 @@ void tryArm(void)
}
imuQuaternionHeadfreeOffsetSet();

#if defined(USE_GYRO_DATA_ANALYSE)
#if defined(USE_DYN_NOTCH_FILTER)
resetMaxFFT();
#endif

Expand Down

0 comments on commit 8649f10

Please sign in to comment.