Skip to content

Commit

Permalink
Merge branch 'SpectrumAnalyser'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Keeble committed Apr 18, 2016
2 parents f502631 + cdda9c5 commit 220d887
Show file tree
Hide file tree
Showing 13 changed files with 668 additions and 19 deletions.
1 change: 1 addition & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ html.has-log .log-graph-config {
.graph-legend-field {
padding-bottom:0.1em;
margin-bottom:0.3em;
cursor:pointer;
}

html.has-video .graph-row,
Expand Down
29 changes: 29 additions & 0 deletions index.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ <h4>Log sync</h4>
<h2>Legend <span class="log-close-legend-dialog glyphicon glyphicon-remove"></span></h2>
<div class="log-graph-legend">
</div>
<button type="button" class="btn btn-default btn-block hide-analyser-window">Hide Analyser</button>
<button type="button" class="btn btn-default btn-block open-log-setup-dialog">Log Setup</button>
<button type="button" class="btn btn-default btn-block open-graph-configuration-dialog">Graph setup</button>
</div>
</div>
Expand Down Expand Up @@ -286,6 +288,31 @@ <h4 class="modal-title">Configure graphs</h4>
</div>
</div>

<div class="modal fade" id="dlgFlightLogSetup">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title">Setup Log Viewer</h4>
</div>
<div class="modal-body">
<div class="btn-group">
<ul class="dropdown-menu" role="menu">
</ul>
</div>
<ul class="list-unstyled setup-flightlog-list">
</ul>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default flightlog-setup-dialog-cancel" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary flightlog-setup-dialog-save" data-dismiss="modal">Save changes</button>
</div>
</div>
</div>
</div>

<div class="modal fade" id="dlgVideoExport">
<div class="modal-dialog">
<div class="modal-content">
Expand Down Expand Up @@ -419,11 +446,13 @@ <h4 class="modal-title">Export video</h4>
<script src="js/flightlog_fields_presenter.js"></script>
<script src="js/flightlog_parser.js"></script>
<script src="js/flightlog_index.js"></script>
<script src="js/flightlog_setup_dialog.js"></script>
<script src="js/flightlog.js"></script>
<script src="js/grapher.js"></script>
<script src="js/graph_config.js"></script>
<script src="js/graph_legend.js"></script>
<script src="js/graph_config_dialog.js"></script>
<script src="js/graph_spectrum.js"></script>
<script src="js/seekbar.js"></script>
<script src="js/video_export_dialog.js"></script>
<script src="js/flightlog_video_renderer.js"></script>
Expand Down
8 changes: 7 additions & 1 deletion js/expo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
*/
function ExpoCurve(offset, power, inputRange, outputRange, steps) {
var
curve, inputScale;
curve, inputScale, rawInputScale;

function lookupStraightLine(input) {
return (input + offset) * inputScale;
}

this.lookupRaw = function(input) {
return (input + offset) * rawInputScale;
}

/**
* An approximation of lookupMathPow by precomputing several expo curve points and interpolating between those
* points using straight line interpolation.
Expand Down Expand Up @@ -58,6 +62,8 @@ function ExpoCurve(offset, power, inputRange, outputRange, steps) {
return result;
}

rawInputScale = outputRange / inputRange;

// If steps argument isn't supplied, use a reasonable default
if (steps === undefined) {
steps = 12;
Expand Down
54 changes: 51 additions & 3 deletions js/flightlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Additional computed fields are derived from the original data set and added as new fields in the resulting data.
* Window based smoothing of fields is offered.
*/
function FlightLog(logData) {
function FlightLog(logData, newSettings) {
var
ADDITIONAL_COMPUTED_FIELD_COUNT = 6, /** attitude + PID_SUM **/
ADDITIONAL_COMPUTED_FIELD_COUNT = 15, /** attitude + PID_SUM + PID_ERROR + RCCOMMAND_SCALED + GYROADC_SCALED **/

that = this,
logIndex = false,
Expand All @@ -33,10 +33,13 @@ function FlightLog(logData) {
maxSmoothing = 0,

smoothedCache = new FIFOCache(2);


//Public fields:
this.parser = parser;

this.settings = newSettings;

this.getMainFieldCount = function() {
return fieldNames.length;
};
Expand Down Expand Up @@ -199,6 +202,9 @@ function FlightLog(logData) {
// Add names for our ADDITIONAL_COMPUTED_FIELDS
fieldNames.push("heading[0]", "heading[1]", "heading[2]");
fieldNames.push("axisSum[0]", "axisSum[1]", "axisSum[2]");
fieldNames.push("axisError[0]", "axisError[1]", "axisError[2]"); // Custom calculated error field
fieldNames.push("rcCommands[0]", "rcCommands[1]", "rcCommands[2]"); // Custom calculated error field
fieldNames.push("gyroADCs[0]", "gyroADCs[1]", "gyroADCs[2]"); // Custom calculated error field

fieldNameToIndex = {};
for (i = 0; i < fieldNames.length; i++) {
Expand Down Expand Up @@ -469,7 +475,8 @@ function FlightLog(logData) {
gyroADC = [fieldNameToIndex["gyroADC[0]"], fieldNameToIndex["gyroADC[1]"], fieldNameToIndex["gyroADC[2]"]],
accSmooth = [fieldNameToIndex["accSmooth[0]"], fieldNameToIndex["accSmooth[1]"], fieldNameToIndex["accSmooth[2]"]],
magADC = [fieldNameToIndex["magADC[0]"], fieldNameToIndex["magADC[1]"], fieldNameToIndex["magADC[2]"]],

rcCommand = [fieldNameToIndex["rcCommand[0]"], fieldNameToIndex["rcCommand[1]"], fieldNameToIndex["rcCommand[2]"]],

sourceChunkIndex, destChunkIndex,

sysConfig,
Expand Down Expand Up @@ -534,6 +541,25 @@ function FlightLog(logData) {
(axisPID[axis][1] !== undefined ? srcFrame[axisPID[axis][1]] : 0) +
(axisPID[axis][2] !== undefined ? srcFrame[axisPID[axis][2]] : 0);
}

// Calculate the PID Error
for (var axis = 0; axis < 3; axis++) {
destFrame[fieldIndex++] =
(gyroADC[axis] !== undefined ? that.gyroRawToDegreesPerSecond(srcFrame[gyroADC[axis]]) : 0) -
(rcCommand[axis] !== undefined ? that.rcCommandRawToDegreesPerSecond(srcFrame[rcCommand[axis]], axis) : 0);
}
// Calculate the Scaled rcCommand (in deg/s)
for (var axis = 0; axis < 3; axis++) {
destFrame[fieldIndex++] =
(rcCommand[axis] !== undefined ? that.rcCommandRawToDegreesPerSecond(srcFrame[rcCommand[axis]], axis) : 0);
}

// Calculate the scaled Gyro ADC
for (var axis = 0; axis < 3; axis++) {
destFrame[fieldIndex++] =
(gyroADC[axis] !== undefined ? that.gyroRawToDegreesPerSecond(srcFrame[gyroADC[axis]]) : 0);
}

}
}
}
Expand Down Expand Up @@ -881,6 +907,28 @@ FlightLog.prototype.gyroRawToDegreesPerSecond = function(value) {
return this.getSysConfig().gyroScale * 1000000 / (Math.PI / 180.0) * value;
};

// Convert rcCommand to degrees per second
FlightLog.prototype.rcCommandRawToDegreesPerSecond = function(value, axis) {

// Axis 0,1 refers to Roll and Pitch
// Axis 2 refers to Yaw.

// ReWrite or LUXFloat only


// if(axis==2 /*YAW*/) {
// return ((this.settings[0].parameters[axis].value + 47) * value ) >> 7;
// } else { /*ROLL or PITCH */
// return ((this.settings[0].parameters[axis].value + 27) * value ) >> 6;
// }

if(axis==2 /*YAW*/) {
return ((this.getSysConfig().yRate + 47) * value ) >> 7;
} else { /*ROLL or PITCH */
return ((((axis==0)?this.getSysConfig().rRate:this.getSysConfig().pRate) + 27) * value ) >> 6;
}
};

FlightLog.prototype.getReferenceVoltageMillivolts = function() {
return this.vbatADCToMillivolts(this.getSysConfig().vbatref);
};
Expand Down
1 change: 1 addition & 0 deletions js/flightlog_fielddefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var
LOGGING_RESUME: 14,

GTUNE_CYCLE_RESULT: 20,
FLIGHT_MODE: 30, // New Event type

LOG_END: 255
}),
Expand Down
33 changes: 32 additions & 1 deletion js/flightlog_fields_presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,26 @@ function FlightLogFieldPresenter() {
'axisSum[all]': 'PID_sum',
'axisSum[0]' : 'PID_sum[roll]',
'axisSum[1]' : 'PID_sum[pitch]',
'axisSum[2]' : 'PID_sum[yaw]'
'axisSum[2]' : 'PID_sum[yaw]',

//Virtual fields - Add the Error fields
'axisError[all]': 'PID_Error',
'axisError[0]' : 'PID_Error[roll]',
'axisError[1]' : 'PID_Error[pitch]',
'axisError[2]' : 'PID_Error[yaw]',

//Virtual fields - add the Scaled rcCommands
'rcCommands[all]': 'rcCommands',
'rcCommands[0]' : 'rcCommands[roll]',
'rcCommands[1]' : 'rcCommands[pitch]',
'rcCommands[2]' : 'rcCommands[yaw]',

//Virtual fields - add the Scaled gyros
'gyroADCs[all]': 'gyros',
'gyroADCs[0]': 'gyros[roll]',
'gyroADCs[1]': 'gyros[pitch]',
'gyroADCs[2]': 'gyros[yaw]'

};

function presentFlags(flags, flagNames) {
Expand Down Expand Up @@ -119,6 +138,18 @@ function FlightLogFieldPresenter() {
case 'gyroADC[2]':
return Math.round(flightLog.gyroRawToDegreesPerSecond(value)) + " deg/s";

case 'axisError[0]':
case 'axisError[1]':
case 'axisError[2]':
return Math.round(value) + " deg/s";

case 'rcCommand[0]':
return Math.round(flightLog.rcCommandRawToDegreesPerSecond(value,0)) + " deg/s";
case 'rcCommand[1]':
return Math.round(flightLog.rcCommandRawToDegreesPerSecond(value,1)) + " deg/s";
case 'rcCommand[2]':
return Math.round(flightLog.rcCommandRawToDegreesPerSecond(value,2)) + " deg/s";

case 'accSmooth[0]':
case 'accSmooth[1]':
case 'accSmooth[2]':
Expand Down
52 changes: 48 additions & 4 deletions js/flightlog_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,20 @@ var FlightLogParser = function(logData) {
currentMeterScale: 400,
deviceUID: null
},

// One day, maybe these will be part of the blackbox log; they certainly would be helpfull!
// If so, then they can be moved intor the defaultSysConfig definition above.
// At the moment they are entered on a dialog box.

defaultSysConfigExtension = {
rcExpo:null,//70, // RC Expo
rRate:null,//0, // Roll Rate
pRate:null,//0, // Pitch Rate
yRate:null,//45, // Yaw Rate
rcYawExpo: null,//20, // Yaw Expo
superExpoFactor: null,//30, // Super Expo Factor
loopTime: null,//500, // Looptime
},

frameTypes,

Expand Down Expand Up @@ -220,16 +234,18 @@ var FlightLogParser = function(logData) {

//The actual log data stream we're reading:
stream;

//Public fields:

/* Information about the frame types the log contains, along with details on their fields.
* Each entry is an object with field details {encoding:[], predictor:[], name:[], count:0, signed:[]}
*/
this.frameDefs = {};

this.sysConfig = Object.create(defaultSysConfig);

// Lets add the custom extensions
var completeSysConfig = $.extend({}, defaultSysConfig, defaultSysConfigExtension);
this.sysConfig = Object.create(completeSysConfig); // Object.create(defaultSysConfig);

/*
* Event handler of the signature (frameValid, frame, frameType, frameOffset, frameSize)
* called when a frame has been decoded.
Expand Down Expand Up @@ -331,6 +347,28 @@ var FlightLogParser = function(logData) {
case "rcRate":
that.sysConfig.rcRate = parseInt(fieldValue, 10);
break;

// In future these fields may exist int the blackbox log
case "rcExpo":
that.sysConfig.rcExpo = parseInt(fieldValue, 10);
break;
case "rates":
var ratesParams = parseCommaSeparatedIntegers(fieldValue);
that.sysConfig.rRate = ratesParams[0];
that.sysConfig.pRate = ratesParams[1];
that.sysConfig.yRate = ratesParams[2];
break;
case "rcYawExpo":
that.sysConfig.rcYawExpo = parseInt(fieldValue, 10);
break;
case "superExpoFactor":
that.sysConfig.superExpoFactor = parseInt(fieldValue, 10);
break;
case "looptime":
that.sysConfig.loopTime = parseInt(fieldValue, 10);
break;
/****************************/

case "vbatscale":
that.sysConfig.vbatscale = parseInt(fieldValue, 10);
break;
Expand Down Expand Up @@ -868,6 +906,10 @@ var FlightLogParser = function(logData) {
lastEvent.data.time = stream.readUnsignedVB();
lastEvent.time = lastEvent.data.time;
break;
case FlightLogEvent.FLIGHT_MODE: // get the flag status change
lastEvent.data.newFlags = stream.readUnsignedVB();
lastEvent.data.lastFlags = stream.readUnsignedVB();
break;
case FlightLogEvent.AUTOTUNE_CYCLE_START:
lastEvent.data.phase = stream.readByte();

Expand Down Expand Up @@ -963,7 +1005,9 @@ var FlightLogParser = function(logData) {
this.resetStats();

//Reset system configuration to MW's defaults
this.sysConfig = Object.create(defaultSysConfig);
// Lets add the custom extensions
var completeSysConfig = $.extend({}, defaultSysConfig, defaultSysConfigExtension);
this.sysConfig = Object.create(completeSysConfig); // Object.create(defaultSysConfig);

this.frameDefs = {};

Expand Down
Loading

0 comments on commit 220d887

Please sign in to comment.