Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended dshot telemetry data parsing and presentation #625

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions js/flightlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,39 @@ function FlightLog(logData) {
return numMotors;
};

/*
* Propagates array data fiels over empty fields
* Debug fields can be arrays with data, so it fills data gaps when no arrays are stored
*/
function propagateArrayFields(chunks)
{
Comment on lines +299 to +304
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too sure about this. I think in the rest of the code we simply store the latest value, and add them when we process other kind of data, to add the values while processing. Maybe is clear with your method, with a little more process time (it needs to look at all the data chunk).

Can you look at the slow frames and gps frames chunks to see if they can be "filled" with this and remove the old implementation? Taking times of this method will be great to see if we loose too much time. If it takes not too much time, I prefer your implementation.

When there are errors in the blackbox (frames lost), this method will fill the data? I think remember that not, that we don't have data in the chunk when the frames are lost.

Copy link
Author

@damosvil damosvil Feb 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you look at the slow frames and gps frames chunks to see if they can be "filled" with this and remove the old implementation? Taking times of this method will be great to see if we loose too much time. If it takes not too much time, I prefer your implementation.

I have been looking for the current implementation. Is it the complete frame function set?
imagen

When there are errors in the blackbox (frames lost), this method will fill the data? I think remember that not, that we don't have data in the chunk when the frames are lost.

Still looking into this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this been resolved?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@McGiverGim are you okay with this - for a follow up PR?

var currentFrame;

for (let k = 0; k < chunks.length; k++)
{
let previousFrame = 0;

for (let j = 0; j < chunks[k].frames.length; j++)
{
currentFrame = chunks[k].frames[j];
if (previousFrame == 0)
{
previousFrame = currentFrame;
}

for (let i = 0; i < currentFrame.length; i++)
{
if (!Array.isArray(currentFrame[i]) && Array.isArray(previousFrame[i]))
{
currentFrame[i] = previousFrame[i];
}
}

previousFrame = chunks[k].frames[j];
}
}
}

/**
* Get the raw chunks in the range [startIndex...endIndex] (inclusive)
*
Expand Down Expand Up @@ -504,6 +537,7 @@ function FlightLog(logData) {
}

injectComputedFields(resultChunks, resultChunks);
propagateArrayFields(resultChunks);

return resultChunks;
}
Expand Down
7 changes: 7 additions & 0 deletions js/flightlog_fielddefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,13 @@ let
"MAG_CALIB",
"MAG_TASK_RATE",
"EZLANDING",
"DSHOT_STATUS_N_TEMPERATURE",
"DSHOT_STATUS_N_VOLTAGE",
"DSHOT_STATUS_N_CURRENT",
"DSHOT_STATUS_N_DEBUG1",
"DSHOT_STATUS_N_DEBUG2",
"DSHOT_STATUS_N_STRESS_LVL",
"DSHOT_STATUS_N_ERPM_FRACTION_18",
]),

SUPER_EXPO_YAW = makeReadOnly([
Expand Down
66 changes: 66 additions & 0 deletions js/flightlog_fields_presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,55 @@ function FlightLogFieldPresenter() {
'debug[2]': 'Upper Limit',
'debug[3]': 'EZ Land Limit',
},
'DSHOT_STATUS_N_TEMPERATURE' : {
'debug[all]': 'ESC Status & Temperature',
'debug[0]': 'ESC1',
'debug[1]': 'ESC2',
'debug[2]': 'ESC3',
'debug[3]': 'ESC4',
},
'DSHOT_STATUS_N_VOLTAGE' : {
'debug[all]': 'ESC Status & Voltage',
'debug[0]': 'ESC1',
'debug[1]': 'ESC2',
'debug[2]': 'ESC3',
'debug[3]': 'ESC4',
},
'DSHOT_STATUS_N_CURRENT' : {
'debug[all]': 'ESC Status & Current',
'debug[0]': 'ESC1',
'debug[1]': 'ESC2',
'debug[2]': 'ESC3',
'debug[3]': 'ESC4',
},
'DSHOT_STATUS_N_DEBUG1' : {
'debug[all]': 'ESC Status & Debug1',
'debug[0]': 'ESC1',
'debug[1]': 'ESC2',
'debug[2]': 'ESC3',
'debug[3]': 'ESC4',
},
'DSHOT_STATUS_N_DEBUG2' : {
'debug[all]': 'ESC Status & Debug2',
'debug[0]': 'ESC1',
'debug[1]': 'ESC2',
'debug[2]': 'ESC3',
'debug[3]': 'ESC4',
},
'DSHOT_STATUS_N_STRESS_LVL' : {
'debug[all]': 'ESC Status & Stress Level',
'debug[0]': 'ESC1',
'debug[1]': 'ESC2',
'debug[2]': 'ESC3',
'debug[3]': 'ESC4',
},
'DSHOT_STATUS_N_ERPM_FRACTION_18' : {
'debug[all]': 'ESC Status & RPM',
'debug[0]': 'ESC1',
'debug[1]': 'ESC2',
'debug[2]': 'ESC3',
'debug[3]': 'ESC4',
},
};

let DEBUG_FRIENDLY_FIELD_NAMES = null;
Expand Down Expand Up @@ -1879,7 +1928,24 @@ function FlightLogFieldPresenter() {
return value.toFixed(0);
case 'DSHOT_TELEMETRY_COUNTS':
return value.toFixed(0);
case 'DSHOT_STATUS_N_TEMPERATURE':
return (value[0] != null) ? `A${value[0]} W${value[1]} E${value[2]} STRESS:${value[3]} ${value[4]}ºC` : '---';
case 'DSHOT_STATUS_N_VOLTAGE':
return (value[0] != null) ? `A${value[0]} W${value[1]} E${value[2]} STRESS:${value[3]} ${value[4]}V` : '---';
case 'DSHOT_STATUS_N_CURRENT':
return (value[0] != null) ? `A${value[0]} W${value[1]} E${value[2]} STRESS:${value[3]} ${value[4]}A` : '---';
case 'DSHOT_STATUS_N_DEBUG1':
return (value[0] != null) ? `A${value[0]} W${value[1]} E${value[2]} STRESS:${value[3]} ${value[4]}` : '---';
case 'DSHOT_STATUS_N_DEBUG2':
return (value[0] != null) ? `A${value[0]} W${value[1]} E${value[2]} STRESS:${value[3]} ${value[4]}` : '---';
case 'DSHOT_STATUS_N_STRESS_LVL':
return (value[0] != null) ? `A${value[0]} W${value[1]} E${value[2]} STRESS:${value[3]} ${value[4]}sTrs` : '---';
case 'DSHOT_STATUS_N_ERPM_FRACTION_18':
var rpm = (value[4] * 200 / flightLog.getSysConfig().motor_poles).toFixed();
return (value[0] != null) ? `A${value[0]} W${value[1]} E${value[2]} STRESS:${value[3]} ${rpm}Rpm` : '---';

}

return value.toFixed(0);
}
return "";
Expand Down
103 changes: 82 additions & 21 deletions js/flightlog_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,23 @@ var FlightLogParser = function(logData) {
//Predict that this field is minthrottle
FLIGHT_LOG_FIELD_PREDICTOR_MINMOTOR = 11,

//Predict that this field is dshot status and other data
FLIGHT_LOG_FIELD_PREDICTOR_DSHOT_STATUS_N_VOLTAGE = 12,
FLIGHT_LOG_FIELD_PREDICTOR_DSHOT_STATUS_N_ERPM_FRACTION_18 = 13,

//Home coord predictors appear in pairs (two copies of FLIGHT_LOG_FIELD_PREDICTOR_HOME_COORD). Rewrite the second
//one we see to this to make parsing easier
FLIGHT_LOG_FIELD_PREDICTOR_HOME_COORD_1 = 256,

FLIGHT_LOG_FIELD_ENCODING_SIGNED_VB = 0, // Signed variable-byte
FLIGHT_LOG_FIELD_ENCODING_UNSIGNED_VB = 1, // Unsigned variable-byte
FLIGHT_LOG_FIELD_ENCODING_NEG_14BIT = 3, // Unsigned variable-byte but we negate the value before storing, value is 14 bits
FLIGHT_LOG_FIELD_ENCODING_TAG8_8SVB = 6,
FLIGHT_LOG_FIELD_ENCODING_TAG2_3S32 = 7,
FLIGHT_LOG_FIELD_ENCODING_TAG8_4S16 = 8,
FLIGHT_LOG_FIELD_ENCODING_NULL = 9, // Nothing is written to the file, take value to be zero
FLIGHT_LOG_FIELD_ENCODING_TAG2_3SVARIABLE = 10,
FLIGHT_LOG_FIELD_ENCODING_SIGNED_VB = 0, // Signed variable-byte
FLIGHT_LOG_FIELD_ENCODING_UNSIGNED_VB = 1, // Unsigned variable-byte
FLIGHT_LOG_FIELD_ENCODING_NEG_14BIT = 3, // Unsigned variable-byte but we negate the value before storing, value is 14 bits
FLIGHT_LOG_FIELD_ENCODING_TAG8_8SVB = 6,
FLIGHT_LOG_FIELD_ENCODING_TAG2_3S32 = 7,
FLIGHT_LOG_FIELD_ENCODING_TAG8_4S16 = 8,
FLIGHT_LOG_FIELD_ENCODING_NULL = 9, // Nothing is written to the file, take value to be zero
FLIGHT_LOG_FIELD_ENCODING_TAG2_3SVARIABLE = 10,
FLIGHT_LOG_FIELD_ENCODING_PACK_1F_1F_1F_1G_4U_8U = 11, // 1 flagBit, 1 flagBit, 1 flagBit, 1 gapBit, 4 unsignedIntBit, 8 unsignedIntBit

FLIGHT_LOG_EVENT_LOG_END = 255,

Expand Down Expand Up @@ -530,9 +535,9 @@ var FlightLogParser = function(logData) {
function translateFieldName(fieldName) {
var translation = translationValues[fieldName];
if (typeof translation !== 'undefined') {
return translation;
return translation;
} else {
return fieldName;
return fieldName;
}
}

Expand Down Expand Up @@ -602,14 +607,14 @@ var FlightLogParser = function(logData) {
case "Cleanflight":
that.sysConfig.firmwareType = FIRMWARE_TYPE_CLEANFLIGHT;
$('html').removeClass('isBaseF');
$('html').addClass('isCF');
$('html').addClass('isCF');
$('html').removeClass('isBF');
$('html').removeClass('isINAV');
break;
default:
that.sysConfig.firmwareType = FIRMWARE_TYPE_BASEFLIGHT;
$('html').addClass('isBaseF');
$('html').removeClass('isCF');
$('html').removeClass('isCF');
$('html').removeClass('isBF');
$('html').removeClass('isINAV');
}
Expand Down Expand Up @@ -946,7 +951,7 @@ var FlightLogParser = function(logData) {
$('html').addClass('isINAV');
} else {

// Cleanflight 1.x and others
// Cleanflight 1.x and others
that.sysConfig.firmwareVersion = '0.0.0';
that.sysConfig.firmware = 0.0;
that.sysConfig.firmwarePatch = 0;
Expand Down Expand Up @@ -1109,6 +1114,34 @@ var FlightLogParser = function(logData) {
% that.sysConfig.frameIntervalPDenom < that.sysConfig.frameIntervalPNum;
}

/**
* Debug data interpretation depends on the chosen debug mode encodings and other parameters could need to be fixed
*/
function assimilateDebugMode(sysConfig, frameDef) {
console.log("Debug mode is " + DEBUG_MODE[sysConfig.debug_mode] + ":" + sysConfig.debug_mode);

if (DEBUG_MODE[sysConfig.debug_mode].startsWith("DSHOT_STATUS_N_")) {
for (let k = 0; k < frameDef.name.length; k++) {
if (frameDef.name[k].startsWith("debug")) {
// Assimilate encoding depending on debug mode
frameDef.encoding[k] = FLIGHT_LOG_FIELD_ENCODING_PACK_1F_1F_1F_1G_4U_8U;

// Assimilate predictor depending on debug mode
switch (DEBUG_MODE[sysConfig.debug_mode]) {
case "DSHOT_STATUS_N_VOLTAGE":
frameDef.predictor[k] = FLIGHT_LOG_FIELD_PREDICTOR_DSHOT_STATUS_N_VOLTAGE;
break;
case "DSHOT_STATUS_N_ERPM_FRACTION_18":
frameDef.predictor[k] = FLIGHT_LOG_FIELD_PREDICTOR_DSHOT_STATUS_N_ERPM_FRACTION_18;
break;
default:
break;
}
}
}
}
}

/**
* Attempt to parse the frame of into the supplied `current` buffer using the encoding/predictor
* definitions from `frameDefs`. The previous frame values are used for predictions.
Expand All @@ -1123,8 +1156,8 @@ var FlightLogParser = function(logData) {
predictor = frameDef.predictor,
encoding = frameDef.encoding,
values = new Array(8),
i, j, groupCount;

i, j, groupCount, updateCurrent;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try not adding new vars - please declare / initialize at block scope.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function where this i, j variables are defined use them in loops and after the loops, so in this case I recommend keeping them. They are defined that way because of the logic in this function.

i = 0;
while (i < frameDef.count) {
var
Expand All @@ -1138,6 +1171,10 @@ var FlightLogParser = function(logData) {

i++;
} else {
// Update current by default
updateCurrent = true;

// Decode
switch (encoding[i]) {
case FLIGHT_LOG_FIELD_ENCODING_SIGNED_VB:
value = stream.readSignedVB();
Expand All @@ -1158,7 +1195,7 @@ var FlightLogParser = function(logData) {
for (j = 0; j < 4; j++, i++)
current[i] = applyPrediction(i, raw ? FLIGHT_LOG_FIELD_PREDICTOR_0 : predictor[i], values[j], current, previous, previous2);

continue;
updateCurrent = false;
break;
case FLIGHT_LOG_FIELD_ENCODING_TAG2_3S32:
stream.readTag2_3S32(values);
Expand All @@ -1167,7 +1204,7 @@ var FlightLogParser = function(logData) {
for (j = 0; j < 3; j++, i++)
current[i] = applyPrediction(i, raw ? FLIGHT_LOG_FIELD_PREDICTOR_0 : predictor[i], values[j], current, previous, previous2);

continue;
updateCurrent = false;
break;
case FLIGHT_LOG_FIELD_ENCODING_TAG2_3SVARIABLE:
stream.readTag2_3SVariable(values);
Expand All @@ -1176,7 +1213,7 @@ var FlightLogParser = function(logData) {
for (j = 0; j < 3; j++, i++)
current[i] = applyPrediction(i, raw ? FLIGHT_LOG_FIELD_PREDICTOR_0 : predictor[i], values[j], current, previous, previous2);

continue;
updateCurrent = false;
break;
case FLIGHT_LOG_FIELD_ENCODING_TAG8_8SVB:
//How many fields are in this encoded group? Check the subsequent field encodings:
Expand All @@ -1191,7 +1228,20 @@ var FlightLogParser = function(logData) {
for (j = 0; j < groupCount; j++, i++)
current[i] = applyPrediction(i, raw ? FLIGHT_LOG_FIELD_PREDICTOR_0 : predictor[i], values[j], current, previous, previous2);

continue;
updateCurrent = false;
break;
case FLIGHT_LOG_FIELD_ENCODING_PACK_1F_1F_1F_1G_4U_8U:
value = stream.readSignedVB();

current[i] = new Array(5);
current[i][0] = ((value & 0x8000) != 0) ? 1 : 0;
current[i][1] = ((value & 0x4000) != 0) ? 1 : 0;
current[i][2] = ((value & 0x2000) != 0) ? 1 : 0;
current[i][3] = (value >> 8) & 0x000F;
current[i][4] = applyPrediction(i, raw ? FLIGHT_LOG_FIELD_PREDICTOR_0 : predictor[i], value & 0x00FF, current, previous, previous2);
i++;

updateCurrent = false;
break;
case FLIGHT_LOG_FIELD_ENCODING_NULL:
//Nothing to read
Expand All @@ -1204,8 +1254,11 @@ var FlightLogParser = function(logData) {
throw "Unsupported field encoding " + encoding[i];
}

current[i] = applyPrediction(i, raw ? FLIGHT_LOG_FIELD_PREDICTOR_0 : predictor[i], value, current, previous, previous2);
i++;
// Updates current when it is not updated by the decoder path`
if (updateCurrent) {
current[i] = applyPrediction(i, raw ? FLIGHT_LOG_FIELD_PREDICTOR_0 : predictor[i], value, current, previous, previous2);
i++;
}
}
}
}
Expand Down Expand Up @@ -1366,6 +1419,12 @@ var FlightLogParser = function(logData) {
if (mainHistory[1])
value += mainHistory[1][FlightLogParser.prototype.FLIGHT_LOG_FIELD_INDEX_TIME];
break;
case FLIGHT_LOG_FIELD_PREDICTOR_DSHOT_STATUS_N_VOLTAGE:
value /= 4;
break;
case FLIGHT_LOG_FIELD_PREDICTOR_DSHOT_STATUS_N_ERPM_FRACTION_18:
value *= 18;
break;
default:
throw "Unsupported field predictor " + predictor;
}
Expand Down Expand Up @@ -1703,6 +1762,8 @@ var FlightLogParser = function(logData) {
} else {
lastSlow = [];
}

assimilateDebugMode(that.sysConfig, this.frameDefs.I);
};

/**
Expand Down
29 changes: 28 additions & 1 deletion js/graph_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ GraphConfig.load = function(config) {
default:
return getCurveForMinMaxFields(fieldName);
}

case 'GPS_DOP':
switch (fieldName) {
case 'debug[0]': // Number of Satellites (now this is in normal GPS data, maybe gpsTrust?)
Expand Down Expand Up @@ -1135,7 +1136,33 @@ GraphConfig.load = function(config) {
default:
return getCurveForMinMaxFields(fieldName);
}
}
case 'DSHOT_STATUS_N_TEMPERATURE':
case 'DSHOT_STATUS_N_CURRENT':
case 'DSHOT_STATUS_N_DEBUG1':
case 'DSHOT_STATUS_N_DEBUG2':
case 'DSHOT_STATUS_N_STRESS_LVL':
return {
offset: 0,
power: 1.0,
inputRange: 400,
outputRange: 1.0,
};
case 'DSHOT_STATUS_N_VOLTAGE':
return {
offset: 0,
power: 1.0,
inputRange: 255,
outputRange: 1.0,
};
case 'DSHOT_STATUS_N_ERPM_FRACTION_18':
return {
offset: 0,
power: 1.0,
inputRange: 4000,
outputRange: 1.0,
};

}
}
// if not found above then
// Scale and center the field based on the whole-log observed ranges for that field
Expand Down
Loading