From 46ef17d0f66462af001dbb61cab19c16fb40d83f Mon Sep 17 00:00:00 2001 From: bkleiner Date: Sun, 11 Aug 2024 18:29:11 +0200 Subject: [PATCH] bb: introduce debug flags --- src/config/config.h | 31 ++++++++++++------------------- src/core/profile.c | 5 ++++- src/core/profile.h | 2 ++ src/flight/sixaxis.c | 2 +- src/io/blackbox.c | 7 +++++-- src/io/blackbox.h | 43 ++++++++++++++++++++++++------------------- 6 files changed, 48 insertions(+), 42 deletions(-) diff --git a/src/config/config.h b/src/config/config.h index e5929e640..15614e905 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -1,17 +1,3 @@ - - -// Universal pids are already loaded for 5" brushless by default. Adjust pids in pid.c file for your build. - -//********************************************************************************************************************** -//***********************************************HARDWARE SELECTION***************************************************** - -//********************************************************************************************************************** -//***********************************************NEW STUFF TO PLAY WITH***************************************************** - -#define THROTTLE_D_ATTENUATION -#define TDA_BREAKPOINT 0.35f -#define TDA_PERCENT 0.80f - //********************************************************************************************************************** //***********************************************RATES & EXPO SETTINGS************************************************** @@ -74,6 +60,11 @@ // ************* expo for throttle with the zero crossing at THROTTLE_MID #define THROTTLE_EXPO 0.0f +// ************* throttle d-term attenuation +#define THROTTLE_D_ATTENUATION +#define TDA_BREAKPOINT 0.35f +#define TDA_PERCENT 0.80f + //********************************************************************************************************************** //***********************************************RECEIVER SETTINGS****************************************************** @@ -121,6 +112,10 @@ // *************RRD/LLD stick gesture aux start up state. Gesture aux is AUX_CHANNEL_GESTURE // #define GESTURE_AUX_START_ON +// *************failsafe time in uS +#define FAILSAFE_TIME_US 1000000 +#define FAILSAFE_LOCK_TIME_MS 5000 + //********************************************************************************************************************** //***********************************************VOLTAGE SETTINGS******************************************************* @@ -258,10 +253,6 @@ // ############################################################################################################################# // ############################################################################################################################# -// failsafe time in uS -#define FAILSAFE_TIME_US 1000000 -#define FAILSAFE_LOCK_TIME_MS 5000 - // debug things ( debug struct and other) // #define DEBUG // #define DEBUG_LOGGING @@ -274,4 +265,6 @@ // #define NOMOTORS // change mixer to a plus configuration -// #define MOTOR_PLUS_CONFIGURATION \ No newline at end of file +// #define MOTOR_PLUS_CONFIGURATION + +// #define BLACKBOX_DEBUG_FLAGS BBOX_DEBUG_DYN_NOTCH \ No newline at end of file diff --git a/src/core/profile.c b/src/core/profile.c index 4a3a591eb..465bb7e5c 100644 --- a/src/core/profile.c +++ b/src/core/profile.c @@ -472,7 +472,10 @@ const profile_t default_profile = { }, }, .blackbox = { - // Initialized by profile_set_defaults(), so nothing to do here +#ifdef BLACKBOX_DEBUG_FLAGS + .debug_flags = BLACKBOX_DEBUG_FLAGS, +#endif + // rest is initialized by profile_set_defaults() }, }; diff --git a/src/core/profile.h b/src/core/profile.h index db7da7bc8..ad4d653ce 100644 --- a/src/core/profile.h +++ b/src/core/profile.h @@ -334,12 +334,14 @@ typedef struct { typedef struct { uint32_t field_flags; + uint32_t debug_flags; uint32_t sample_rate_hz; } profile_blackbox_t; #define BLACKBOX_MEMBERS \ START_STRUCT(profile_blackbox_t) \ MEMBER(field_flags, uint32_t) \ + MEMBER(debug_flags, uint32_t) \ MEMBER(sample_rate_hz, uint32_t) \ END_STRUCT() diff --git a/src/flight/sixaxis.c b/src/flight/sixaxis.c index 3b7c46eee..34d7059cd 100644 --- a/src/flight/sixaxis.c +++ b/src/flight/sixaxis.c @@ -183,7 +183,7 @@ void sixaxis_read() { if (profile.filter.gyro_dynamic_notch_enable) { for (uint32_t p = 0; p < SDFT_PEAKS; p++) { - blackbox_set_debug(i * SDFT_PEAKS + p, gyro_sdft[i].notch_hz[p]); + blackbox_set_debug(BBOX_DEBUG_DYN_NOTCH, i * SDFT_PEAKS + p, gyro_sdft[i].notch_hz[p]); state.gyro.axis[i] = filter_biquad_notch_step(¬ch_filter[i][p], ¬ch_filter_state[i][p], state.gyro.axis[i]); } } diff --git a/src/io/blackbox.c b/src/io/blackbox.c index c36766b0d..8be6c9d5e 100644 --- a/src/io/blackbox.c +++ b/src/io/blackbox.c @@ -78,10 +78,13 @@ void blackbox_init() { blackbox_device_init(); } -void blackbox_set_debug(uint8_t index, int16_t data) { +void blackbox_set_debug(blackbox_debug_flag_t flag, uint8_t index, int16_t data) { if (index >= BLACKBOX_DEBUG_SIZE) { return; } + if ((profile.blackbox.field_flags & flag) != flag) { + return; + } blackbox.debug[index] = data; } @@ -146,6 +149,6 @@ void blackbox_update() { } #else void blackbox_init() {} -void blackbox_set_debug(uint8_t index, int16_t data) {} +void blackbox_set_debug(blackbox_debug_flag_t flag, uint8_t index, int16_t data) {} void blackbox_update() {} #endif \ No newline at end of file diff --git a/src/io/blackbox.h b/src/io/blackbox.h index a49e14cb6..376d9066f 100644 --- a/src/io/blackbox.h +++ b/src/io/blackbox.h @@ -5,6 +5,29 @@ #define BLACKBOX_SCALE 1000 #define BLACKBOX_DEBUG_SIZE 10 +typedef enum { + BBOX_FIELD_LOOP, + BBOX_FIELD_TIME, + BBOX_FIELD_PID_P_TERM, + BBOX_FIELD_PID_I_TERM, + BBOX_FIELD_PID_D_TERM, + BBOX_FIELD_RX, + BBOX_FIELD_SETPOINT, + BBOX_FIELD_ACCEL_RAW, + BBOX_FIELD_ACCEL_FILTER, + BBOX_FIELD_GYRO_RAW, + BBOX_FIELD_GYRO_FILTER, + BBOX_FIELD_MOTOR, + BBOX_FIELD_CPU_LOAD, + BBOX_FIELD_DEBUG, + + BBOX_FIELD_MAX, +} blackbox_field_t; + +typedef enum { + BBOX_DEBUG_DYN_NOTCH = 0x1 << 0, +} blackbox_debug_flag_t; + typedef struct { uint32_t loop; uint32_t time; @@ -30,27 +53,9 @@ typedef struct { } blackbox_t; // Blackbox fields (should align with above structure) -typedef enum { - BBOX_FIELD_LOOP, - BBOX_FIELD_TIME, - BBOX_FIELD_PID_P_TERM, - BBOX_FIELD_PID_I_TERM, - BBOX_FIELD_PID_D_TERM, - BBOX_FIELD_RX, - BBOX_FIELD_SETPOINT, - BBOX_FIELD_ACCEL_RAW, - BBOX_FIELD_ACCEL_FILTER, - BBOX_FIELD_GYRO_RAW, - BBOX_FIELD_GYRO_FILTER, - BBOX_FIELD_MOTOR, - BBOX_FIELD_CPU_LOAD, - BBOX_FIELD_DEBUG, - - BBOX_FIELD_MAX, -} blackbox_field_t; cbor_result_t cbor_encode_blackbox_t(cbor_value_t *enc, const blackbox_t *b, const uint32_t field_flags); void blackbox_init(); -void blackbox_set_debug(uint8_t index, int16_t data); +void blackbox_set_debug(blackbox_debug_flag_t flag, uint8_t index, int16_t data); void blackbox_update(); \ No newline at end of file