Skip to content

Commit

Permalink
bb: introduce debug flags
Browse files Browse the repository at this point in the history
  • Loading branch information
bkleiner committed Aug 11, 2024
1 parent 5335a4e commit ae470c5
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 42 deletions.
31 changes: 12 additions & 19 deletions src/config/config.h
Original file line number Diff line number Diff line change
@@ -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**************************************************

Expand Down Expand Up @@ -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******************************************************

Expand Down Expand Up @@ -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*******************************************************

Expand Down Expand Up @@ -256,10 +251,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
Expand All @@ -272,4 +263,6 @@
// #define NOMOTORS

// change mixer to a plus configuration
// #define MOTOR_PLUS_CONFIGURATION
// #define MOTOR_PLUS_CONFIGURATION

// #define BLACKBOX_DEBUG_FLAGS BBOX_DEBUG_DYN_NOTCH
5 changes: 4 additions & 1 deletion src/core/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,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()
},
};

Expand Down
2 changes: 2 additions & 0 deletions src/core/profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion src/flight/sixaxis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(&notch_filter[i][p], &notch_filter_state[i][p], state.gyro.axis[i]);
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/io/blackbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
43 changes: 24 additions & 19 deletions src/io/blackbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

0 comments on commit ae470c5

Please sign in to comment.