1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-26 17:55:30 +03:00

Add (e)RPM field to blackbox logs (#12823)

* Add RPM black box field

* Fix settings table spacing

* Move RPM field to end of FlightLogFieldSelect enum

* Fix various RPM logging related bugs

- change eRPM I frame encoding to UNSIGNED_VB (was SIGNED_VB)
- change eRPM P frame prediction to PREVIOUS (was AVERAGE_2)
- change eRPM log field name to 'eRPM(/100)' (was 'RPM')
- rename rpm field in blackboxMainState_s to erpm
- minor formatting fixes to BlackBoxMainFields spacing and some if clauses

* Remove superfluous parentheses in blackbox.c
This commit is contained in:
tbolin 2023-06-20 01:41:39 +02:00 committed by GitHub
parent 8308540932
commit 96c788c87f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 4 deletions

View file

@ -48,6 +48,9 @@
#include "drivers/compass/compass.h" #include "drivers/compass/compass.h"
#include "drivers/sensor.h" #include "drivers/sensor.h"
#include "drivers/time.h" #include "drivers/time.h"
#ifdef USE_DSHOT_TELEMETRY
#include "drivers/dshot.h"
#endif
#include "fc/board_info.h" #include "fc/board_info.h"
#include "fc/controlrate_profile.h" #include "fc/controlrate_profile.h"
@ -247,7 +250,18 @@ static const blackboxDeltaFieldDefinition_t blackboxMainFields[] = {
{"motor", 7, UNSIGNED, .Ipredict = PREDICT(MOTOR_0), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_MOTORS_8)}, {"motor", 7, UNSIGNED, .Ipredict = PREDICT(MOTOR_0), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_MOTORS_8)},
/* Tricopter tail servo */ /* Tricopter tail servo */
{"servo", 5, UNSIGNED, .Ipredict = PREDICT(1500), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(PREVIOUS), .Pencode = ENCODING(SIGNED_VB), CONDITION(TRICOPTER)} {"servo", 5, UNSIGNED, .Ipredict = PREDICT(1500), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(PREVIOUS), .Pencode = ENCODING(SIGNED_VB), CONDITION(TRICOPTER)},
#ifdef USE_DSHOT_TELEMETRY
{"eRPM(/100)", 0, UNSIGNED, .Ipredict = PREDICT(0), .Iencode = ENCODING(UNSIGNED_VB), .Ppredict = PREDICT(PREVIOUS), .Pencode = ENCODING(SIGNED_VB), CONDITION(MOTOR_1_HAS_RPM)},
{"eRPM(/100)", 1, UNSIGNED, .Ipredict = PREDICT(0), .Iencode = ENCODING(UNSIGNED_VB), .Ppredict = PREDICT(PREVIOUS), .Pencode = ENCODING(SIGNED_VB), CONDITION(MOTOR_2_HAS_RPM)},
{"eRPM(/100)", 2, UNSIGNED, .Ipredict = PREDICT(0), .Iencode = ENCODING(UNSIGNED_VB), .Ppredict = PREDICT(PREVIOUS), .Pencode = ENCODING(SIGNED_VB), CONDITION(MOTOR_3_HAS_RPM)},
{"eRPM(/100)", 3, UNSIGNED, .Ipredict = PREDICT(0), .Iencode = ENCODING(UNSIGNED_VB), .Ppredict = PREDICT(PREVIOUS), .Pencode = ENCODING(SIGNED_VB), CONDITION(MOTOR_4_HAS_RPM)},
{"eRPM(/100)", 4, UNSIGNED, .Ipredict = PREDICT(0), .Iencode = ENCODING(UNSIGNED_VB), .Ppredict = PREDICT(PREVIOUS), .Pencode = ENCODING(SIGNED_VB), CONDITION(MOTOR_5_HAS_RPM)},
{"eRPM(/100)", 5, UNSIGNED, .Ipredict = PREDICT(0), .Iencode = ENCODING(UNSIGNED_VB), .Ppredict = PREDICT(PREVIOUS), .Pencode = ENCODING(SIGNED_VB), CONDITION(MOTOR_6_HAS_RPM)},
{"eRPM(/100)", 6, UNSIGNED, .Ipredict = PREDICT(0), .Iencode = ENCODING(UNSIGNED_VB), .Ppredict = PREDICT(PREVIOUS), .Pencode = ENCODING(SIGNED_VB), CONDITION(MOTOR_7_HAS_RPM)},
{"eRPM(/100)", 7, UNSIGNED, .Ipredict = PREDICT(0), .Iencode = ENCODING(UNSIGNED_VB), .Ppredict = PREDICT(PREVIOUS), .Pencode = ENCODING(SIGNED_VB), CONDITION(MOTOR_8_HAS_RPM)},
#endif /* USE_DSHOT_TELEMETRY */
}; };
#ifdef USE_GPS #ifdef USE_GPS
@ -314,6 +328,9 @@ typedef struct blackboxMainState_s {
int16_t debug[DEBUG16_VALUE_COUNT]; int16_t debug[DEBUG16_VALUE_COUNT];
int16_t motor[MAX_SUPPORTED_MOTORS]; int16_t motor[MAX_SUPPORTED_MOTORS];
int16_t servo[MAX_SUPPORTED_SERVOS]; int16_t servo[MAX_SUPPORTED_SERVOS];
#ifdef USE_DSHOT_TELEMETRY
int16_t erpm[MAX_SUPPORTED_MOTORS];
#endif
uint16_t vbatLatest; uint16_t vbatLatest;
int32_t amperageLatest; int32_t amperageLatest;
@ -366,7 +383,7 @@ static struct {
} xmitState; } xmitState;
// Cache for FLIGHT_LOG_FIELD_CONDITION_* test results: // Cache for FLIGHT_LOG_FIELD_CONDITION_* test results:
static uint32_t blackboxConditionCache; static uint64_t blackboxConditionCache;
STATIC_ASSERT((sizeof(blackboxConditionCache) * 8) >= FLIGHT_LOG_FIELD_CONDITION_LAST, too_many_flight_log_conditions); STATIC_ASSERT((sizeof(blackboxConditionCache) * 8) >= FLIGHT_LOG_FIELD_CONDITION_LAST, too_many_flight_log_conditions);
@ -436,6 +453,18 @@ static bool testBlackboxConditionUncached(FlightLogFieldCondition condition)
case CONDITION(AT_LEAST_MOTORS_8): case CONDITION(AT_LEAST_MOTORS_8):
return (getMotorCount() >= condition - FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_MOTORS_1 + 1) && isFieldEnabled(FIELD_SELECT(MOTOR)); return (getMotorCount() >= condition - FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_MOTORS_1 + 1) && isFieldEnabled(FIELD_SELECT(MOTOR));
#ifdef USE_DSHOT_TELEMETRY
case CONDITION(MOTOR_1_HAS_RPM):
case CONDITION(MOTOR_2_HAS_RPM):
case CONDITION(MOTOR_3_HAS_RPM):
case CONDITION(MOTOR_4_HAS_RPM):
case CONDITION(MOTOR_5_HAS_RPM):
case CONDITION(MOTOR_6_HAS_RPM):
case CONDITION(MOTOR_7_HAS_RPM):
case CONDITION(MOTOR_8_HAS_RPM):
return (getMotorCount() >= condition - CONDITION(MOTOR_1_HAS_RPM) + 1) && (motorConfig()->dev.useDshotTelemetry) && isFieldEnabled(FIELD_SELECT(RPM));
#endif
case CONDITION(TRICOPTER): case CONDITION(TRICOPTER):
return (mixerConfig()->mixerMode == MIXER_TRI || mixerConfig()->mixerMode == MIXER_CUSTOM_TRI) && isFieldEnabled(FIELD_SELECT(MOTOR)); return (mixerConfig()->mixerMode == MIXER_TRI || mixerConfig()->mixerMode == MIXER_CUSTOM_TRI) && isFieldEnabled(FIELD_SELECT(MOTOR));
@ -508,14 +537,14 @@ static void blackboxBuildConditionCache(void)
blackboxConditionCache = 0; blackboxConditionCache = 0;
for (FlightLogFieldCondition cond = FLIGHT_LOG_FIELD_CONDITION_FIRST; cond <= FLIGHT_LOG_FIELD_CONDITION_LAST; cond++) { for (FlightLogFieldCondition cond = FLIGHT_LOG_FIELD_CONDITION_FIRST; cond <= FLIGHT_LOG_FIELD_CONDITION_LAST; cond++) {
if (testBlackboxConditionUncached(cond)) { if (testBlackboxConditionUncached(cond)) {
blackboxConditionCache |= 1 << cond; blackboxConditionCache |= (uint64_t) 1 << cond;
} }
} }
} }
static bool testBlackboxCondition(FlightLogFieldCondition condition) static bool testBlackboxCondition(FlightLogFieldCondition condition)
{ {
return (blackboxConditionCache & (1 << condition)) != 0; return (blackboxConditionCache & (uint64_t) 1 << condition) != 0;
} }
static void blackboxSetState(BlackboxState newState) static void blackboxSetState(BlackboxState newState)
@ -656,6 +685,17 @@ static void writeIntraframe(void)
} }
} }
#ifdef USE_DSHOT_TELEMETRY
if (isFieldEnabled(FIELD_SELECT(RPM))) {
const int motorCount = getMotorCount();
for (int x = 0; x < motorCount; x++) {
if (testBlackboxCondition(CONDITION(MOTOR_1_HAS_RPM) + x)) {
blackboxWriteUnsignedVB(blackboxCurrent->erpm[x]);
}
}
}
#endif
//Rotate our history buffers: //Rotate our history buffers:
//The current state becomes the new "before" state //The current state becomes the new "before" state
@ -796,6 +836,16 @@ static void writeInterframe(void)
blackboxWriteSignedVB(blackboxCurrent->servo[5] - blackboxLast->servo[5]); blackboxWriteSignedVB(blackboxCurrent->servo[5] - blackboxLast->servo[5]);
} }
} }
#ifdef USE_DSHOT_TELEMETRY
if (isFieldEnabled(FIELD_SELECT(RPM))) {
const int motorCount = getMotorCount();
for (int x = 0; x < motorCount; x++) {
if (testBlackboxCondition(CONDITION(MOTOR_1_HAS_RPM) + x)) {
blackboxWriteSignedVB(blackboxCurrent->erpm[x] - blackboxLast->erpm[x]);
}
}
}
#endif
//Rotate our history buffers //Rotate our history buffers
blackboxHistory[2] = blackboxHistory[1]; blackboxHistory[2] = blackboxHistory[1];
@ -1097,6 +1147,12 @@ static void loadMainState(timeUs_t currentTimeUs)
blackboxCurrent->motor[i] = lrintf(motor[i]); blackboxCurrent->motor[i] = lrintf(motor[i]);
} }
#ifdef USE_DSHOT_TELEMETRY
for (int i = 0; i < motorCount; i++) {
blackboxCurrent->erpm[i] = getDshotTelemetry(i);
}
#endif
blackboxCurrent->vbatLatest = getBatteryVoltageLatest(); blackboxCurrent->vbatLatest = getBatteryVoltageLatest();
blackboxCurrent->amperageLatest = getAmperageLatest(); blackboxCurrent->amperageLatest = getAmperageLatest();

View file

@ -32,6 +32,17 @@ typedef enum FlightLogFieldCondition {
FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_MOTORS_8, FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_MOTORS_8,
FLIGHT_LOG_FIELD_CONDITION_TRICOPTER, FLIGHT_LOG_FIELD_CONDITION_TRICOPTER,
#ifdef USE_DSHOT_TELEMETRY
FLIGHT_LOG_FIELD_CONDITION_MOTOR_1_HAS_RPM,
FLIGHT_LOG_FIELD_CONDITION_MOTOR_2_HAS_RPM,
FLIGHT_LOG_FIELD_CONDITION_MOTOR_3_HAS_RPM,
FLIGHT_LOG_FIELD_CONDITION_MOTOR_4_HAS_RPM,
FLIGHT_LOG_FIELD_CONDITION_MOTOR_5_HAS_RPM,
FLIGHT_LOG_FIELD_CONDITION_MOTOR_6_HAS_RPM,
FLIGHT_LOG_FIELD_CONDITION_MOTOR_7_HAS_RPM,
FLIGHT_LOG_FIELD_CONDITION_MOTOR_8_HAS_RPM,
#endif
FLIGHT_LOG_FIELD_CONDITION_MAG, FLIGHT_LOG_FIELD_CONDITION_MAG,
FLIGHT_LOG_FIELD_CONDITION_BARO, FLIGHT_LOG_FIELD_CONDITION_BARO,
FLIGHT_LOG_FIELD_CONDITION_VBAT, FLIGHT_LOG_FIELD_CONDITION_VBAT,
@ -72,6 +83,7 @@ typedef enum FlightLogFieldSelect_e { // no more than 32
FLIGHT_LOG_FIELD_SELECT_DEBUG_LOG, FLIGHT_LOG_FIELD_SELECT_DEBUG_LOG,
FLIGHT_LOG_FIELD_SELECT_MOTOR, FLIGHT_LOG_FIELD_SELECT_MOTOR,
FLIGHT_LOG_FIELD_SELECT_GPS, FLIGHT_LOG_FIELD_SELECT_GPS,
FLIGHT_LOG_FIELD_SELECT_RPM,
FLIGHT_LOG_FIELD_SELECT_COUNT FLIGHT_LOG_FIELD_SELECT_COUNT
} FlightLogFieldSelect_e; } FlightLogFieldSelect_e;

View file

@ -826,6 +826,9 @@ const clivalue_t valueTable[] = {
#endif #endif
{ "blackbox_disable_debug", VAR_UINT32 | MASTER_VALUE | MODE_BITSET, .config.bitpos = FLIGHT_LOG_FIELD_SELECT_DEBUG_LOG, PG_BLACKBOX_CONFIG, offsetof(blackboxConfig_t, fields_disabled_mask) }, { "blackbox_disable_debug", VAR_UINT32 | MASTER_VALUE | MODE_BITSET, .config.bitpos = FLIGHT_LOG_FIELD_SELECT_DEBUG_LOG, PG_BLACKBOX_CONFIG, offsetof(blackboxConfig_t, fields_disabled_mask) },
{ "blackbox_disable_motors", VAR_UINT32 | MASTER_VALUE | MODE_BITSET, .config.bitpos = FLIGHT_LOG_FIELD_SELECT_MOTOR, PG_BLACKBOX_CONFIG, offsetof(blackboxConfig_t, fields_disabled_mask) }, { "blackbox_disable_motors", VAR_UINT32 | MASTER_VALUE | MODE_BITSET, .config.bitpos = FLIGHT_LOG_FIELD_SELECT_MOTOR, PG_BLACKBOX_CONFIG, offsetof(blackboxConfig_t, fields_disabled_mask) },
#ifdef USE_DSHOT_TELEMETRY
{ "blackbox_disable_rpm", VAR_UINT32 | MASTER_VALUE | MODE_BITSET, .config.bitpos = FLIGHT_LOG_FIELD_SELECT_RPM, PG_BLACKBOX_CONFIG, offsetof(blackboxConfig_t, fields_disabled_mask) },
#endif
#ifdef USE_GPS #ifdef USE_GPS
{ "blackbox_disable_gps", VAR_UINT32 | MASTER_VALUE | MODE_BITSET, .config.bitpos = FLIGHT_LOG_FIELD_SELECT_GPS, PG_BLACKBOX_CONFIG, offsetof(blackboxConfig_t, fields_disabled_mask) }, { "blackbox_disable_gps", VAR_UINT32 | MASTER_VALUE | MODE_BITSET, .config.bitpos = FLIGHT_LOG_FIELD_SELECT_GPS, PG_BLACKBOX_CONFIG, offsetof(blackboxConfig_t, fields_disabled_mask) },
#endif #endif