Skip to content
Merged
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
2 changes: 1 addition & 1 deletion css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ html.has-sticks #stickCanvas {
display:block;
}

html.has-analyser-fullscreen.has-analyser .analyser input {
html.has-analyser-fullscreen.has-analyser .analyser input:not(.onlyFullScreenException) {
display:block;
}

Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ <h4>Workspace</h4>
<select id="spectrumTypeSelect">
<option value="0">Frequency</option>
<option value="1">Freq. vs Throttle</option>
<option value="2">Error vs Setpoint</option>
</select>
</div>

Expand Down
12 changes: 10 additions & 2 deletions js/graph_spectrum.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,14 @@ var
fftData = GraphSpectrumCalc.dataLoadFrequencyVsThrottle();
break;

case SPECTRUM_TYPE.PIDERROR_VS_SETPOINT:
fftData = GraphSpectrumCalc.dataLoadPidErrorVsSetpoint();
break;

case SPECTRUM_TYPE.FREQUENCY:
default:
fftData = GraphSpectrumCalc.dataLoadFrequency();
break;

}

};
Expand Down Expand Up @@ -196,7 +199,12 @@ var
dataReload = true;
that.plotSpectrum(dataBuffer.fieldIndex, dataBuffer.curve, dataBuffer.fieldName);
}
});

// Hide overdraw and zoomY if needed
const pidErrorVsSetpointSelected = optionSelected === SPECTRUM_TYPE.PIDERROR_VS_SETPOINT;
overdrawSpectrumTypeElem.toggle(!pidErrorVsSetpointSelected);
analyserZoomYElem.toggleClass('onlyFullScreenException', pidErrorVsSetpointSelected);
}).change();

// Spectrum overdraw to show
userSettings.overdrawSpectrumType = userSettings.overdrawSpectrumType || SPECTRUM_OVERDRAW_TYPE.ALL_FILTERS;
Expand Down
91 changes: 91 additions & 0 deletions js/graph_spectrum_calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,63 @@ GraphSpectrumCalc.dataLoadFrequencyVsThrottle = function() {

};

GraphSpectrumCalc.dataLoadPidErrorVsSetpoint = function() {

// Detect the axis
let axisIndex;
if (this._dataBuffer.fieldName.indexOf('[roll]') >= 0) {
axisIndex = 0;
} else if (this._dataBuffer.fieldName.indexOf('[pitch]') >= 0) {
axisIndex = 1;
} else if (this._dataBuffer.fieldName.indexOf('[yaw]') >= 0) {
axisIndex = 2;
}

const flightSamples = this._getFlightSamplesPidErrorVsSetpoint(axisIndex);

// Add the total error by absolute position
const errorBySetpoint = Array.from({length: flightSamples.maxSetpoint + 1});
const numberOfSamplesBySetpoint = Array.from({length: flightSamples.maxSetpoint + 1});

// Initialize
for (let i = 0; i <= flightSamples.maxSetpoint; i++) {
errorBySetpoint[i] = 0;
numberOfSamplesBySetpoint[i] = 0;
}

// Sum by position
for (let i = 0; i < flightSamples.count; i++) {

const pidErrorValue = Math.abs(flightSamples.piderror[i]);
const setpointValue = Math.abs(flightSamples.setpoint[i]);

errorBySetpoint[setpointValue] += pidErrorValue;
numberOfSamplesBySetpoint[setpointValue]++;
}

// Calculate the media and max values
let maxErrorBySetpoint = 0;
for (let i = 0; i <= flightSamples.maxSetpoint; i++) {
if (numberOfSamplesBySetpoint[i] > 0) {
errorBySetpoint[i] = errorBySetpoint[i] / numberOfSamplesBySetpoint[i];
if (errorBySetpoint[i] > maxErrorBySetpoint) {
maxErrorBySetpoint = errorBySetpoint[i];
}
} else {
errorBySetpoint[i] = null;
}
}

return {
fieldIndex : this._dataBuffer.fieldIndex,
fieldName : this._dataBuffer.fieldName,
axisName : FlightLogFieldPresenter.fieldNameToFriendly(`axisError[${axisIndex}]`),
fftOutput : errorBySetpoint,
fftMaxOutput : maxErrorBySetpoint,
};

};

GraphSpectrumCalc._getFlightChunks = function() {

var logStart = 0;
Expand Down Expand Up @@ -223,6 +280,40 @@ GraphSpectrumCalc._getFlightSamplesFreqVsThrottle = function() {
};
};

GraphSpectrumCalc._getFlightSamplesPidErrorVsSetpoint = function(axisIndex) {

const allChunks = this._getFlightChunks();

// Get the PID Error field
const FIELD_PIDERROR_INDEX = this._flightLog.getMainFieldIndexByName(`axisError[${axisIndex}]`);
const FIELD_SETPOINT_INDEX = this._flightLog.getMainFieldIndexByName(`setpoint[${axisIndex}]`);

const piderror = new Int16Array(MAX_ANALYSER_LENGTH / (1000 * 1000) * this._blackBoxRate);
const setpoint = new Int16Array(MAX_ANALYSER_LENGTH / (1000 * 1000) * this._blackBoxRate);

// Loop through all the samples in the chunks and assign them to a sample array.
let samplesCount = 0;
let maxSetpoint = 0;
for (let chunkIndex = 0; chunkIndex < allChunks.length; chunkIndex++) {
const chunk = allChunks[chunkIndex];
for (let frameIndex = 0; frameIndex < chunk.frames.length; frameIndex++) {
piderror[samplesCount] = chunk.frames[frameIndex][FIELD_PIDERROR_INDEX];
setpoint[samplesCount] = chunk.frames[frameIndex][FIELD_SETPOINT_INDEX];
if (setpoint[samplesCount] > maxSetpoint) {
maxSetpoint = setpoint[samplesCount];
}
samplesCount++;
}
}

return {
piderror,
setpoint,
maxSetpoint,
count: samplesCount,
};
};

GraphSpectrumCalc._hanningWindow = function(samples, size) {

if (!size) {
Expand Down
Loading