Skip to content

Commit 04331c7

Browse files
committed
rpm wrong values filtration improvement
1 parent 0e341d4 commit 04331c7

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

src/graph_spectrum_calc.js

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +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_VALUE = 10000;
11+
MAX_RPM_VELOCITY = 100000,
12+
MAX_RPM_VALUE = 1000;
1213

1314
export const GraphSpectrumCalc = {
1415
_analyserTimeRange : {
@@ -23,23 +24,27 @@ export const GraphSpectrumCalc = {
2324
},
2425
_flightLog : null,
2526
_sysConfig : null,
27+
_prevRPM : [],
28+
_prevTime : undefined,
29+
_motorPoles : null,
2630
};
2731

2832
GraphSpectrumCalc.initialize = function(flightLog, sysConfig) {
2933

3034
this._flightLog = flightLog;
3135
this._sysConfig = sysConfig;
36+
this._motorPoles = flightLog.getSysConfig()['motor_poles'];
3237

33-
var gyroRate = (1000000 / this._sysConfig['looptime']).toFixed(0);
38+
const gyroRate = (1000000 / this._sysConfig['looptime']).toFixed(0);
3439
this._blackBoxRate = gyroRate * this._sysConfig['frameIntervalPNum'] / this._sysConfig['frameIntervalPDenom'];
3540
if (this._sysConfig.pid_process_denom != null) {
3641
this._blackBoxRate = this._blackBoxRate / this._sysConfig.pid_process_denom;
3742
}
3843
this._BetaflightRate = this._blackBoxRate;
3944

40-
let minTime = this._flightLog.getMinTime(),
41-
maxTime = this._flightLog.getMaxTime();
42-
let timeRange = maxTime - minTime;
45+
const minTime = this._flightLog.getMinTime(),
46+
maxTime = this._flightLog.getMaxTime(),
47+
timeRange = maxTime - minTime;
4348

4449
const length = flightLog.getCurrentLogRowsCount();
4550
this._actualeRate = 1e6 * length / timeRange;
@@ -186,9 +191,8 @@ GraphSpectrumCalc.dataLoadFrequencyVsThrottle = function() {
186191

187192
GraphSpectrumCalc.dataLoadFrequencyVsRpm = function() {
188193
let fftData = this._dataLoadFrequencyVsX(FIELD_RPM_NAMES, 0);
189-
const motorPoles = this._flightLog.getSysConfig()['motor_poles'];
190-
fftData.vsRange.max *= 3.333 / motorPoles;
191-
fftData.vsRange.min *= 3.333 / motorPoles;
194+
fftData.vsRange.max *= 3.333 / this._motorPoles;
195+
fftData.vsRange.min *= 3.333 / this._motorPoles;
192196
return fftData;
193197
};
194198

@@ -307,31 +311,37 @@ GraphSpectrumCalc._getVsIndexes = function(vsFieldNames) {
307311

308312
GraphSpectrumCalc._getFlightSamplesFreqVsX = function(vsFieldNames, minValue = Infinity, maxValue = -Infinity) {
309313

310-
var allChunks = this._getFlightChunks();
311-
let vsIndexes = this._getVsIndexes(vsFieldNames);
314+
const allChunks = this._getFlightChunks();
315+
const vsIndexes = this._getVsIndexes(vsFieldNames);
312316

313-
var samples = new Float64Array(MAX_ANALYSER_LENGTH / (1000 * 1000) * this._blackBoxRate);
314-
let vsValues = new Array(vsIndexes.length).fill(null).map(() => new Float64Array(MAX_ANALYSER_LENGTH / (1000 * 1000) * this._blackBoxRate));
317+
const samples = new Float64Array(MAX_ANALYSER_LENGTH / (1000 * 1000) * this._blackBoxRate);
318+
const vsValues = new Array(vsIndexes.length).fill(null).map(() => new Float64Array(MAX_ANALYSER_LENGTH / (1000 * 1000) * this._blackBoxRate));
315319

316-
var samplesCount = 0;
317-
let lastRPM = 0;
320+
let samplesCount = 0;
318321
for (var chunkIndex = 0; chunkIndex < allChunks.length; chunkIndex++) {
319322
var chunk = allChunks[chunkIndex];
320323
for (var frameIndex = 0; frameIndex < chunk.frames.length; frameIndex++) {
321324
samples[samplesCount] = (this._dataBuffer.curve.lookupRaw(chunk.frames[frameIndex][this._dataBuffer.fieldIndex]));
322-
325+
const time = chunk.frames[frameIndex][1];
326+
const dT = this._prevTime != null ? (time - this._prevTime)/1000000 : undefined;
323327
for (let i = 0; i < vsIndexes.length; i++) {
324-
let vsFieldIx = vsIndexes[i];
328+
const vsFieldIx = vsIndexes[i];
325329
let value = chunk.frames[frameIndex][vsFieldIx];
326330
if (vsFieldNames == FIELD_RPM_NAMES) {
327-
if (value > MAX_RPM_VALUE || value < 0)
328-
value = lastRPM;
329-
lastRPM = value;
331+
if (this._prevRPM[i] != undefined && dT != undefined) {
332+
const veloRPM = (value - this._prevRPM[i]) / dT * 3.333 / this._motorPoles;
333+
const rpmHz = value * 3.333 / this._motorPoles;
334+
if (veloRPM > MAX_RPM_VELOCITY || veloRPM < -MAX_RPM_VELOCITY || rpmHz < 0 || rpmHz > MAX_RPM_VALUE) {
335+
value = this._prevRPM[i];
336+
}
337+
}
330338
}
339+
this._prevRPM[i] = value;
331340
maxValue = Math.max(maxValue, value);
332341
minValue = Math.min(minValue, value);
333342
vsValues[i][samplesCount] = value;
334343
}
344+
this._prevTime = time;
335345
samplesCount++;
336346
}
337347
}

0 commit comments

Comments
 (0)