// Feature flag for FMUV3 target #if defined(USE_ADAPTIVE_BLACKBOX) && defined(FLASH_M25P16) #define USE_ADAPTIVE_BLACKBOX_FEATURE #endif Add to src/main/target/MATEKF405/target.h :
// Configuration structure typedef struct adaptive_bb_s { uint8_t resolution; // 0=low, 1=normal, 2=high uint8_t auto_erase; // auto-erase oldest logs uint8_t priority_mode; // 0=quality, 1=duration uint16_t max_log_seconds; uint8_t dynamic_rate; // adjust rate based on flash remaining } adaptive_bb_t;
if(strcmp(arg, "adaptive_bb") == 0) { char *subcmd = strtok(NULL, " "); if(subcmd == NULL) { // Show status cliPrintLinef("Adaptive Blackbox Status:"); cliPrintLinef("Flash total: %u bytes", flash_status.total_bytes); cliPrintLinef("Free: %u bytes (%u%%)", flash_status.free_bytes, 100 - flash_status.percent_used); cliPrintLinef("Est. recording: %d seconds", flash_status.estimated_log_seconds); cliPrintLinef("Resolution: %s", adaptive_bb_config.resolution == 0 ? "Low" : adaptive_bb_config.resolution == 1 ? "Normal" : "High"); cliPrintLinef("Auto erase: %s", adaptive_bb_config.auto_erase ? "ON" : "OFF"); cliPrintLinef("Dynamic rate: %s", adaptive_bb_config.dynamic_rate ? "ON" : "OFF"); } else if(strcmp(subcmd, "resolution") == 0) { uint8_t val = atoi(strtok(NULL, " ")); if(val <= 2) { adaptive_bb_config.resolution = val; cliPrintLinef("Resolution set to %d", val); } } else if(strcmp(subcmd, "auto_erase") == 0) { adaptive_bb_config.auto_erase = atoi(strtok(NULL, " ")); cliPrintLinef("Auto erase set to %d", adaptive_bb_config.auto_erase); } else if(strcmp(subcmd, "max_time") == 0) { adaptive_bb_config.max_log_seconds = atoi(strtok(NULL, " ")); cliPrintLinef("Max log time set to %d seconds", adaptive_bb_config.max_log_seconds); } else if(strcmp(subcmd, "dynamic") == 0) { adaptive_bb_config.dynamic_rate = atoi(strtok(NULL, " ")); cliPrintLinef("Dynamic rate set to %d", adaptive_bb_config.dynamic_rate); } } } 2m flash - use fmuv3 firmware
// Check if flash is 2MB (typical FMUV3 boards) if(flash_status.total_bytes == 2 * 1024 * 1024) { // Configure for 2M flash blackboxConfig()->rate_num = 1; blackboxConfig()->rate_denom = 1; // Auto-admit settings if(flash_status.percent_used > 90) { smart_erase_oldest(); } // Set max log size uint16_t max_seconds = adaptive_bb_config.max_log_seconds; if(max_seconds > 0) { uint32_t max_bytes = max_seconds * 2000; // 2KB/sec estimate if(max_bytes < flash_status.free_bytes) { blackboxConfig()->max_log_size_kb = max_bytes / 1024; } } // Apply dynamic rate uint8_t dyn_rate = calculate_dynamic_rate(); if(dyn_rate == 0) { blackboxConfig()->rate_num = 1; blackboxConfig()->rate_denom = 2; // 500Hz } else if(dyn_rate == 1) { blackboxConfig()->rate_num = 1; blackboxConfig()->rate_denom = 1; // 1kHz } else { blackboxConfig()->rate_num = 2; blackboxConfig()->rate_denom = 1; // 2kHz } }
return flash_status.free_bytes / bytes_per_second; } "Normal" : "High")
static adaptive_bb_t adaptive_bb_config = { .resolution = 1, .auto_erase = 1, .priority_mode = 0, .max_log_seconds = 180, // 3 minutes max by default .dynamic_rate = 1 };
// Rate calculation: 1kHz = ~2KB/sec (gyro+accel+debug) switch(adaptive_bb_config.resolution) { case 0: // Low (500Hz gyro, no accel) bytes_per_second = 800; break; case 1: // Normal (1kHz gyro, 1kHz accel) bytes_per_second = 2000; break; case 2: // High (2kHz gyro, 1kHz accel, debug) bytes_per_second = 4000; break; default: bytes_per_second = 2000; } cliPrintLinef("Auto erase: %s"
static flash_status_t flash_status;