Skip to content

Commit

Permalink
Add temperatures to Blackbox
Browse files Browse the repository at this point in the history
  • Loading branch information
pmattila committed Jan 2, 2024
1 parent 321baac commit 360ea93
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/main/blackbox/blackbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@
#include "rx/rx.h"

#include "sensors/acceleration.h"
#include "sensors/adcinternal.h"
#include "sensors/barometer.h"
#include "sensors/battery.h"
#include "sensors/compass.h"
#include "sensors/esc_sensor.h"
#include "sensors/gyro.h"
#include "sensors/rangefinder.h"

Expand Down Expand Up @@ -283,6 +285,9 @@ static const blackboxDeltaFieldDefinition_t blackboxMainFields[] =
{"Vbec", -1, UNSIGNED, .Ipredict = PREDICT(0), .Iencode = ENCODING(UNSIGNED_VB), .Ppredict = PREDICT(PREVIOUS), .Pencode = ENCODING(SIGNED_VB), CONDITION(VBEC)},
{"Vbus", -1, UNSIGNED, .Ipredict = PREDICT(0), .Iencode = ENCODING(UNSIGNED_VB), .Ppredict = PREDICT(PREVIOUS), .Pencode = ENCODING(SIGNED_VB), CONDITION(VBUS)},

{"Tmcu", -1, UNSIGNED, .Ipredict = PREDICT(0), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(PREVIOUS), .Pencode = ENCODING(SIGNED_VB), CONDITION(TMCU)},
{"Tesc", -1, UNSIGNED, .Ipredict = PREDICT(0), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(PREVIOUS), .Pencode = ENCODING(SIGNED_VB), CONDITION(TESC)},

{"headspeed", -1, UNSIGNED, .Ipredict = PREDICT(0), .Iencode = ENCODING(UNSIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(HEADSPEED)},
{"tailspeed", -1, UNSIGNED, .Ipredict = PREDICT(0), .Iencode = ENCODING(UNSIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(TAILSPEED)},

Expand Down Expand Up @@ -394,6 +399,9 @@ typedef struct blackboxMainState_s {
uint16_t vbec;
uint16_t vbus;

int16_t tmcu;
int16_t tesc;

uint16_t rssi;

uint16_t headspeed;
Expand Down Expand Up @@ -566,6 +574,11 @@ static bool testBlackboxConditionUncached(FlightLogFieldCondition condition)
case CONDITION(TAILSPEED):
return (getMotorCount() >= 2) && isFieldEnabled(FIELD_SELECT(RPM));

case CONDITION(TMCU):
return isFieldEnabled(FIELD_SELECT(TEMP));
case CONDITION(TESC):
return featureIsEnabled(FEATURE_ESC_SENSOR) && isFieldEnabled(FIELD_SELECT(TEMP));

case CONDITION(MOTOR_1):
return (getMotorCount() >= 1) && isFieldEnabled(FIELD_SELECT(MOTOR));
case CONDITION(MOTOR_2):
Expand Down Expand Up @@ -756,6 +769,12 @@ static void writeIntraframe(void)
if (testBlackboxCondition(CONDITION(VBUS))) {
blackboxWriteUnsignedVB(blackboxCurrent->vbus);
}
if (testBlackboxCondition(CONDITION(TMCU))) {
blackboxWriteSignedVB(blackboxCurrent->tmcu);
}
if (testBlackboxCondition(CONDITION(TESC))) {
blackboxWriteSignedVB(blackboxCurrent->tesc);
}
if (testBlackboxCondition(CONDITION(HEADSPEED))) {
blackboxWriteUnsignedVB(blackboxCurrent->headspeed);
}
Expand Down Expand Up @@ -930,6 +949,13 @@ static void writeInterframe(void)
blackboxWriteSignedVB((int32_t) blackboxCurrent->vbus - blackboxPrev->vbus);
}

if (testBlackboxCondition(CONDITION(TMCU))) {
blackboxWriteSignedVB((int32_t) blackboxCurrent->tmcu - blackboxPrev->tmcu);
}
if (testBlackboxCondition(CONDITION(TESC))) {
blackboxWriteSignedVB((int32_t) blackboxCurrent->tesc - blackboxPrev->tesc);
}

if (testBlackboxCondition(CONDITION(HEADSPEED))) {
int32_t predictor = (blackboxHistory[1]->headspeed + blackboxHistory[2]->headspeed) / 2;
blackboxWriteSignedVB(blackboxCurrent->headspeed - predictor);
Expand Down Expand Up @@ -1212,9 +1238,17 @@ static void loadMainState(timeUs_t currentTimeUs)

voltageMeter_t meter;
voltageSensorADCRead(VOLTAGE_SENSOR_ADC_BEC, &meter);
blackboxCurrent->vbec = meter.voltage;
blackboxCurrent->vbec = meter.voltage / 10;
voltageSensorADCRead(VOLTAGE_SENSOR_ADC_BUS, &meter);
blackboxCurrent->vbus = meter.voltage;
blackboxCurrent->vbus = meter.voltage / 10;

blackboxCurrent->tmcu = getCoreTemperatureCelsius();

const escSensorData_t *escData = getEscSensorData(ESC_SENSOR_COMBINED);
if (escData && escData->age <= ESC_BATTERY_AGE_MAX)
blackboxCurrent->tesc = escData->temperature / 10;
else
blackboxCurrent->tesc = 0;

blackboxCurrent->headspeed = getHeadSpeed();
blackboxCurrent->tailspeed = getTailSpeed();
Expand Down
4 changes: 4 additions & 0 deletions src/main/blackbox/blackbox_fielddefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ typedef enum FlightLogFieldCondition {
FLIGHT_LOG_FIELD_CONDITION_HEADSPEED,
FLIGHT_LOG_FIELD_CONDITION_TAILSPEED,

FLIGHT_LOG_FIELD_CONDITION_TMCU,
FLIGHT_LOG_FIELD_CONDITION_TESC,

FLIGHT_LOG_FIELD_CONDITION_MOTOR_1,
FLIGHT_LOG_FIELD_CONDITION_MOTOR_2,
FLIGHT_LOG_FIELD_CONDITION_MOTOR_3,
Expand Down Expand Up @@ -87,6 +90,7 @@ typedef enum FlightLogFieldSelect_e {
FLIGHT_LOG_FIELD_SELECT_SERVO,
FLIGHT_LOG_FIELD_SELECT_VBEC,
FLIGHT_LOG_FIELD_SELECT_VBUS,
FLIGHT_LOG_FIELD_SELECT_TEMP,
FLIGHT_LOG_FIELD_SELECT_COUNT
} FlightLogFieldSelect_e;

Expand Down

0 comments on commit 360ea93

Please sign in to comment.