1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-21 15:25:36 +03:00

Fix Blackbox P interval (#5645)

This commit is contained in:
Míguel Ángel Mulero Martínez 2018-04-09 14:35:54 +02:00 committed by Michael Keller
parent 4b3ada82bf
commit 802edf236b
6 changed files with 57 additions and 54 deletions

View file

@ -82,7 +82,7 @@
PG_REGISTER_WITH_RESET_TEMPLATE(blackboxConfig_t, blackboxConfig, PG_BLACKBOX_CONFIG, 1);
PG_RESET_TEMPLATE(blackboxConfig_t, blackboxConfig,
.p_denom = 32,
.p_ratio = 32,
.device = DEFAULT_BLACKBOX_DEVICE,
.record_acc = 1,
.mode = BLACKBOX_MODE_NORMAL
@ -384,7 +384,7 @@ bool blackboxMayEditConfig(void)
static bool blackboxIsOnlyLoggingIntraframes(void)
{
return blackboxConfig()->p_denom == 0;
return blackboxConfig()->p_ratio == 0;
}
static bool testBlackboxConditionUncached(FlightLogFieldCondition condition)
@ -442,7 +442,7 @@ static bool testBlackboxConditionUncached(FlightLogFieldCondition condition)
return rxConfig()->rssi_channel > 0 || feature(FEATURE_RSSI_ADC);
case FLIGHT_LOG_FIELD_CONDITION_NOT_LOGGING_EVERY_FRAME:
return blackboxConfig()->p_denom != 1;
return blackboxConfig()->p_ratio != 1;
case FLIGHT_LOG_FIELD_CONDITION_ACC:
return sensors(SENSOR_ACC) && blackboxConfig()->record_acc;
@ -1196,8 +1196,8 @@ static bool blackboxWriteSysinfo(void)
BLACKBOX_PRINT_HEADER_LINE("Log start datetime", "%s", blackboxGetStartDateTime(buf));
BLACKBOX_PRINT_HEADER_LINE("Craft name", "%s", pilotConfig()->name);
BLACKBOX_PRINT_HEADER_LINE("I interval", "%d", blackboxIInterval);
BLACKBOX_PRINT_HEADER_LINE("P interval", "%d/%d", blackboxGetRateNum(), blackboxGetRateDenom());
BLACKBOX_PRINT_HEADER_LINE("P denom", "%d", blackboxConfig()->p_denom);
BLACKBOX_PRINT_HEADER_LINE("P interval", "%d", blackboxPInterval);
BLACKBOX_PRINT_HEADER_LINE("P ratio", "%d", blackboxConfig()->p_ratio);
BLACKBOX_PRINT_HEADER_LINE("minthrottle", "%d", motorConfig()->minthrottle);
BLACKBOX_PRINT_HEADER_LINE("maxthrottle", "%d", motorConfig()->maxthrottle);
BLACKBOX_PRINT_HEADER_LINE("gyro_scale","0x%x", castFloatBytesToInt(1.0f));
@ -1397,7 +1397,7 @@ static void blackboxCheckAndLogFlightMode(void)
STATIC_UNIT_TESTED bool blackboxShouldLogPFrame(void)
{
return blackboxPFrameIndex == 0 && blackboxConfig()->p_denom != 0;
return blackboxPFrameIndex == 0 && blackboxConfig()->p_ratio != 0;
}
STATIC_UNIT_TESTED bool blackboxShouldLogIFrame(void)
@ -1695,14 +1695,10 @@ int blackboxCalculatePDenom(int rateNum, int rateDenom)
return blackboxIInterval * rateNum / rateDenom;
}
uint8_t blackboxGetRateNum(void)
{
return blackboxGetRateDenom() * blackboxConfig()->p_denom / blackboxIInterval;
}
uint8_t blackboxGetRateDenom(void)
{
return gcd(blackboxIInterval, blackboxPInterval);
return blackboxPInterval;
}
/**
@ -1721,14 +1717,14 @@ void blackboxInit(void)
} else {
blackboxIInterval = (uint16_t)(32 * 1000 / gyro.targetLooptime);
}
// by default p_denom is 32 and a P-frame is written every 1ms
// if p_denom is zero then no P-frames are logged
if (blackboxConfig()->p_denom == 0) {
blackboxPInterval = 0; // blackboxPInterval not used when p_denom is zero, so just set it to zero
} else if (blackboxConfig()->p_denom > blackboxIInterval && blackboxIInterval >= 32) {
// by default p_ratio is 32 and a P-frame is written every 1ms
// if p_ratio is zero then no P-frames are logged
if (blackboxConfig()->p_ratio == 0) {
blackboxPInterval = 0; // blackboxPInterval not used when p_ratio is zero, so just set it to zero
} else if (blackboxConfig()->p_ratio > blackboxIInterval && blackboxIInterval >= 32) {
blackboxPInterval = 1;
} else {
blackboxPInterval = blackboxIInterval / blackboxConfig()->p_denom;
blackboxPInterval = blackboxIInterval / blackboxConfig()->p_ratio;
}
if (blackboxConfig()->device) {
blackboxSetState(BLACKBOX_STATE_STOPPED);