1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-16 04:45:24 +03:00

Blackbox: Enable logging when mode switch is active

This commit is contained in:
Alexander Fedorov 2015-07-13 16:14:14 +02:00 committed by Nicholas Sherlock
parent 7af3d57606
commit 01632998a3
5 changed files with 46 additions and 25 deletions

View file

@ -27,6 +27,7 @@ auxillary receiver channels and other events such as failsafe detection.
| 20 | 19 | TELEMETRY | Enable telemetry via switch | | 20 | 19 | TELEMETRY | Enable telemetry via switch |
| 21 | 20 | AUTOTUNE | Autotune Pitch/Roll PIDs | | 21 | 20 | AUTOTUNE | Autotune Pitch/Roll PIDs |
| 22 | 21 | SONAR | Altitude hold mode (sonar sensor only) | | 22 | 21 | SONAR | Altitude hold mode (sonar sensor only) |
| 26 | 25 | BLACKBOX | Enable BlackBox logging |
## Mode details ## Mode details

View file

@ -349,6 +349,8 @@ static blackboxMainState_t blackboxHistoryRing[3];
// These point into blackboxHistoryRing, use them to know where to store history of a given age (0, 1 or 2 generations old) // These point into blackboxHistoryRing, use them to know where to store history of a given age (0, 1 or 2 generations old)
static blackboxMainState_t* blackboxHistory[3]; static blackboxMainState_t* blackboxHistory[3];
static bool blackboxModeActivationConditionPresent = false;
static bool testBlackboxConditionUncached(FlightLogFieldCondition condition) static bool testBlackboxConditionUncached(FlightLogFieldCondition condition)
{ {
switch (condition) { switch (condition) {
@ -771,6 +773,7 @@ static void validateBlackboxConfig()
*/ */
void startBlackbox(void) void startBlackbox(void)
{ {
blackboxModeActivationConditionPresent = isModeActivationConditionPresent(currentProfile->modeActivationConditions, BOXBLACKBOX);
if (blackboxState == BLACKBOX_STATE_STOPPED) { if (blackboxState == BLACKBOX_STATE_STOPPED) {
validateBlackboxConfig(); validateBlackboxConfig();
@ -1176,7 +1179,7 @@ static bool blackboxShouldLogPFrame(uint32_t pFrameIndex)
} }
// Called once every FC loop in order to log the current state // Called once every FC loop in order to log the current state
static void blackboxLogIteration() static void blackboxLogIteration(bool writeFrames)
{ {
// Write a keyframe every BLACKBOX_I_INTERVAL frames so we can resynchronise upon missing frames // Write a keyframe every BLACKBOX_I_INTERVAL frames so we can resynchronise upon missing frames
if (blackboxPFrameIndex == 0) { if (blackboxPFrameIndex == 0) {
@ -1184,25 +1187,25 @@ static void blackboxLogIteration()
* Don't log a slow frame if the slow data didn't change ("I" frames are already large enough without adding * Don't log a slow frame if the slow data didn't change ("I" frames are already large enough without adding
* an additional item to write at the same time) * an additional item to write at the same time)
*/ */
writeSlowFrameIfNeeded(false); if (writeFrames) {
writeSlowFrameIfNeeded(false);
loadMainState(); loadMainState();
writeIntraframe(); writeIntraframe();
}
} else { } else {
blackboxCheckAndLogArmingBeep(); blackboxCheckAndLogArmingBeep();
if (blackboxShouldLogPFrame(blackboxPFrameIndex)) { if (blackboxShouldLogPFrame(blackboxPFrameIndex) && writeFrames) {
/* /*
* We assume that slow frames are only interesting in that they aid the interpretation of the main data stream. * We assume that slow frames are only interesting in that they aid the interpretation of the main data stream.
* So only log slow frames during loop iterations where we log a main frame. * So only log slow frames during loop iterations where we log a main frame.
*/ */
writeSlowFrameIfNeeded(true); writeSlowFrameIfNeeded(true);
loadMainState(); loadMainState();
writeInterframe(); writeInterframe();
} }
#ifdef GPS #ifdef GPS
if (feature(FEATURE_GPS)) { if (feature(FEATURE_GPS) && writeFrames) {
/* /*
* If the GPS home point has been updated, or every 128 intraframes (~10 seconds), write the * If the GPS home point has been updated, or every 128 intraframes (~10 seconds), write the
* GPS home position. * GPS home position.
@ -1307,8 +1310,16 @@ void handleBlackbox(void)
break; break;
case BLACKBOX_STATE_RUNNING: case BLACKBOX_STATE_RUNNING:
// On entry to this state, blackboxIteration, blackboxPFrameIndex and blackboxIFrameIndex are reset to 0 // On entry to this state, blackboxIteration, blackboxPFrameIndex and blackboxIFrameIndex are reset to 0
if (blackboxModeActivationConditionPresent) {
blackboxLogIteration(); if (IS_RC_MODE_ACTIVE(BOXBLACKBOX)) {
blackboxLogIteration(true);
} else {
// Log only first I frame
blackboxLogIteration(blackboxIteration == 0);
}
} else {
blackboxLogIteration(true);
}
break; break;
case BLACKBOX_STATE_SHUTTING_DOWN: case BLACKBOX_STATE_SHUTTING_DOWN:
//On entry of this state, startTime is set and a flush is performed //On entry of this state, startTime is set and a flush is performed

View file

@ -310,6 +310,17 @@ void processRcStickPositions(rxConfig_t *rxConfig, throttleStatus_e throttleStat
} }
bool isModeActivationConditionPresent(modeActivationCondition_t *modeActivationConditions, boxId_e modeId)
{
uint8_t index;
for (index = 0; index < MAX_MODE_ACTIVATION_CONDITION_COUNT; index++) {
modeActivationCondition_t *modeActivationCondition = &modeActivationConditions[index];
if (modeActivationCondition->modeId == modeId && IS_RANGE_USABLE(&modeActivationCondition->range)) return true;
}
return false;
}
bool isRangeActive(uint8_t auxChannelIndex, channelRange_t *range) { bool isRangeActive(uint8_t auxChannelIndex, channelRange_t *range) {
if (!IS_RANGE_USABLE(range)) { if (!IS_RANGE_USABLE(range)) {
return false; return false;
@ -732,20 +743,10 @@ int32_t getRcStickDeflection(int32_t axis, uint16_t midrc) {
void useRcControlsConfig(modeActivationCondition_t *modeActivationConditions, escAndServoConfig_t *escAndServoConfigToUse, pidProfile_t *pidProfileToUse) void useRcControlsConfig(modeActivationCondition_t *modeActivationConditions, escAndServoConfig_t *escAndServoConfigToUse, pidProfile_t *pidProfileToUse)
{ {
uint8_t index;
escAndServoConfig = escAndServoConfigToUse; escAndServoConfig = escAndServoConfigToUse;
pidProfile = pidProfileToUse; pidProfile = pidProfileToUse;
isUsingSticksToArm = true; isUsingSticksToArm = !isModeActivationConditionPresent(modeActivationConditions, BOXARM);
for (index = 0; index < MAX_MODE_ACTIVATION_CONDITION_COUNT; index++) {
modeActivationCondition_t *modeActivationCondition = &modeActivationConditions[index];
if (modeActivationCondition->modeId == BOXARM && IS_RANGE_USABLE(&modeActivationCondition->range)) {
isUsingSticksToArm = false;
break;
}
}
} }
void resetAdjustmentStates(void) void resetAdjustmentStates(void)

View file

@ -46,6 +46,7 @@ typedef enum {
BOXSERVO1, BOXSERVO1,
BOXSERVO2, BOXSERVO2,
BOXSERVO3, BOXSERVO3,
BOXBLACKBOX,
CHECKBOX_ITEM_COUNT CHECKBOX_ITEM_COUNT
} boxId_e; } boxId_e;
@ -239,3 +240,4 @@ void processRcAdjustments(controlRateConfig_t *controlRateConfig, rxConfig_t *rx
bool isUsingSticksForArming(void); bool isUsingSticksForArming(void);
int32_t getRcStickDeflection(int32_t axis, uint16_t midrc); int32_t getRcStickDeflection(int32_t axis, uint16_t midrc);
bool isModeActivationConditionPresent(modeActivationCondition_t *modeActivationConditions, boxId_e modeId);

View file

@ -341,7 +341,7 @@ static const box_t boxes[CHECKBOX_ITEM_COUNT + 1] = {
{ BOXSERVO1, "SERVO1;", 23 }, { BOXSERVO1, "SERVO1;", 23 },
{ BOXSERVO2, "SERVO2;", 24 }, { BOXSERVO2, "SERVO2;", 24 },
{ BOXSERVO3, "SERVO3;", 25 }, { BOXSERVO3, "SERVO3;", 25 },
{ BOXBLACKBOX, "BLACKBOX;", 26 },
{ CHECKBOX_ITEM_COUNT, NULL, 0xFF } { CHECKBOX_ITEM_COUNT, NULL, 0xFF }
}; };
@ -680,6 +680,7 @@ void mspInit(serialConfig_t *serialConfig)
activeBoxIds[activeBoxIdCount++] = BOXSONAR; activeBoxIds[activeBoxIdCount++] = BOXSONAR;
} }
#ifdef USE_SERVOS #ifdef USE_SERVOS
if (masterConfig.mixerMode == MIXER_CUSTOM_AIRPLANE) { if (masterConfig.mixerMode == MIXER_CUSTOM_AIRPLANE) {
activeBoxIds[activeBoxIdCount++] = BOXSERVO1; activeBoxIds[activeBoxIdCount++] = BOXSERVO1;
@ -687,7 +688,11 @@ void mspInit(serialConfig_t *serialConfig)
activeBoxIds[activeBoxIdCount++] = BOXSERVO3; activeBoxIds[activeBoxIdCount++] = BOXSERVO3;
} }
#endif #endif
#ifdef BLACKBOX
if (feature(FEATURE_BLACKBOX)){
activeBoxIds[activeBoxIdCount++] = BOXBLACKBOX;
}
#endif
memset(mspPorts, 0x00, sizeof(mspPorts)); memset(mspPorts, 0x00, sizeof(mspPorts));
mspAllocateSerialPorts(serialConfig); mspAllocateSerialPorts(serialConfig);
} }
@ -808,7 +813,8 @@ static bool processOutCommand(uint8_t cmdMSP)
IS_ENABLED(IS_RC_MODE_ACTIVE(BOXTELEMETRY)) << BOXTELEMETRY | IS_ENABLED(IS_RC_MODE_ACTIVE(BOXTELEMETRY)) << BOXTELEMETRY |
IS_ENABLED(IS_RC_MODE_ACTIVE(BOXAUTOTUNE)) << BOXAUTOTUNE | IS_ENABLED(IS_RC_MODE_ACTIVE(BOXAUTOTUNE)) << BOXAUTOTUNE |
IS_ENABLED(FLIGHT_MODE(SONAR_MODE)) << BOXSONAR | IS_ENABLED(FLIGHT_MODE(SONAR_MODE)) << BOXSONAR |
IS_ENABLED(ARMING_FLAG(ARMED)) << BOXARM; IS_ENABLED(ARMING_FLAG(ARMED)) << BOXARM |
IS_ENABLED(IS_RC_MODE_ACTIVE(BOXBLACKBOX)) << BOXBLACKBOX;
for (i = 0; i < activeBoxIdCount; i++) { for (i = 0; i < activeBoxIdCount; i++) {
int flag = (tmp & (1 << activeBoxIds[i])); int flag = (tmp & (1 << activeBoxIds[i]));
if (flag) if (flag)