Skip to content

Commit 0b14d8c

Browse files
committed
The bad rpm values filtering by plot spectrum chart improvement. The chunks rpm averages min-max values are used now by spectrum plot
1 parent 1a959d8 commit 0b14d8c

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

src/graph_spectrum_calc.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const
88
MAX_ANALYSER_LENGTH = 300 * 1000 * 1000, // 5min
99
NUM_VS_BINS = 100,
1010
WARNING_RATE_DIFFERENCE = 0.05,
11-
MAX_RPM_VELOCITY = 100000,
12-
MAX_RPM_VALUE = 1000;
11+
MAX_RPM_HZ_VALUE = 800;
12+
1313

1414
export const GraphSpectrumCalc = {
1515
_analyserTimeRange : {
@@ -24,20 +24,16 @@ export const GraphSpectrumCalc = {
2424
},
2525
_flightLog : null,
2626
_sysConfig : null,
27-
_prevRPM : [],
28-
_prevTime : undefined,
2927
_motorPoles : null,
3028
};
3129

3230
GraphSpectrumCalc.initialize = function(flightLog, sysConfig) {
3331

3432
this._flightLog = flightLog;
3533
this._sysConfig = sysConfig;
36-
this._prevRPM = [];
37-
this._prevTime = undefined;
38-
this._motorPoles = flightLog.getSysConfig()['motor_poles'];
3934

4035
const gyroRate = (1000000 / this._sysConfig['looptime']).toFixed(0);
36+
this._motorPoles = flightLog.getSysConfig()['motor_poles'];
4137
this._blackBoxRate = gyroRate * this._sysConfig['frameIntervalPNum'] / this._sysConfig['frameIntervalPDenom'];
4238
if (this._sysConfig.pid_process_denom != null) {
4339
this._blackBoxRate = this._blackBoxRate / this._sysConfig.pid_process_denom;
@@ -320,39 +316,43 @@ GraphSpectrumCalc._getFlightSamplesFreqVsX = function(vsFieldNames, minValue = I
320316

321317
let samplesCount = 0;
322318
for (const chunk of allChunks) {
323-
for (const frame of chunk.frames) {
324-
samples[samplesCount] = (this._dataBuffer.curve.lookupRaw(frame[this._dataBuffer.fieldIndex]));
325-
const time = frame[1];
326-
const dT = this._prevTime != null ? (time - this._prevTime)/1000000 : undefined;
319+
for (let frameIndex = 0; frameIndex < chunk.frames.length; frameIndex++) {
320+
samples[samplesCount] = (this._dataBuffer.curve.lookupRaw(chunk.frames[frameIndex][this._dataBuffer.fieldIndex]));
327321
for (let i = 0; i < vsIndexes.length; i++) {
328-
const vsFieldIx = vsIndexes[i];
329-
let value = frame[vsFieldIx];
330-
//Drop wrong RPM values
322+
let vsFieldIx = vsIndexes[i];
323+
let value = chunk.frames[frameIndex][vsFieldIx];
331324
if (vsFieldNames == FIELD_RPM_NAMES) {
332-
if (this._prevRPM[i] != undefined && dT != undefined) {
333-
const veloRPM = (value - this._prevRPM[i]) / dT * 3.333 / this._motorPoles;
334-
const rpmHz = value * 3.333 / this._motorPoles;
335-
if (veloRPM > MAX_RPM_VELOCITY || veloRPM < -MAX_RPM_VELOCITY || rpmHz < 0 || rpmHz > MAX_RPM_VALUE) {
336-
value = this._prevRPM[i];
337-
}
338-
} else {
339-
if (value < 0) {
340-
value = 0;
341-
} else if (value > MAX_RPM_VALUE) {
342-
value = MAX_RPM_VALUE;
343-
}
325+
const maxRPM = MAX_RPM_HZ_VALUE * this._motorPoles / 3.333;
326+
if (value > maxRPM) {
327+
value = maxRPM;
328+
}
329+
else if (value < 0) {
330+
value = 0;
344331
}
345-
this._prevRPM[i] = value;
346332
}
347-
maxValue = Math.max(maxValue, value);
348-
minValue = Math.min(minValue, value);
349333
vsValues[i][samplesCount] = value;
350334
}
351-
this._prevTime = time;
352335
samplesCount++;
353336
}
354337
}
355338

339+
// Calculate min max average of the VS values in the chunk what will used by spectrum data definition
340+
const fftChunkLength = this._blackBoxRate * FREQ_VS_THR_CHUNK_TIME_MS / 1000;
341+
const fftChunkWindow = Math.round(fftChunkLength / FREQ_VS_THR_WINDOW_DIVISOR);
342+
for (let fftChunkIndex = 0; fftChunkIndex + fftChunkLength < samplesCount; fftChunkIndex += fftChunkWindow) {
343+
for (const vsValueArray of vsValues) {
344+
// Calculate average of the VS values in the chunk
345+
let sumVsValues = 0;
346+
for (let indexVs = fftChunkIndex; indexVs < fftChunkIndex + fftChunkLength; indexVs++) {
347+
sumVsValues += vsValueArray[indexVs];
348+
}
349+
// Find min max average of the VS values in the chunk
350+
const avgVsValue = sumVsValues / fftChunkLength;
351+
maxValue = Math.max(maxValue, avgVsValue);
352+
minValue = Math.min(minValue, avgVsValue);
353+
}
354+
}
355+
356356
if (minValue > maxValue) {
357357
if (minValue == Infinity) { // this should never happen
358358
minValue = 0;
@@ -365,7 +365,7 @@ GraphSpectrumCalc._getFlightSamplesFreqVsX = function(vsFieldNames, minValue = I
365365
}
366366
}
367367

368-
const slicedVsValues = [];
368+
let slicedVsValues = [];
369369
for (const vsValueArray of vsValues) {
370370
slicedVsValues.push(vsValueArray.slice(0, samplesCount));
371371
}

0 commit comments

Comments
 (0)