Skip to content

Commit 220d887

Browse files
author
Gary Keeble
committed
Merge branch 'SpectrumAnalyser'
2 parents f502631 + cdda9c5 commit 220d887

13 files changed

+668
-19
lines changed

css/main.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ html.has-log .log-graph-config {
203203
.graph-legend-field {
204204
padding-bottom:0.1em;
205205
margin-bottom:0.3em;
206+
cursor:pointer;
206207
}
207208

208209
html.has-video .graph-row,

index.html

100644100755
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ <h4>Log sync</h4>
234234
<h2>Legend <span class="log-close-legend-dialog glyphicon glyphicon-remove"></span></h2>
235235
<div class="log-graph-legend">
236236
</div>
237+
<button type="button" class="btn btn-default btn-block hide-analyser-window">Hide Analyser</button>
238+
<button type="button" class="btn btn-default btn-block open-log-setup-dialog">Log Setup</button>
237239
<button type="button" class="btn btn-default btn-block open-graph-configuration-dialog">Graph setup</button>
238240
</div>
239241
</div>
@@ -286,6 +288,31 @@ <h4 class="modal-title">Configure graphs</h4>
286288
</div>
287289
</div>
288290

291+
<div class="modal fade" id="dlgFlightLogSetup">
292+
<div class="modal-dialog">
293+
<div class="modal-content">
294+
<div class="modal-header">
295+
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
296+
<span aria-hidden="true">&times;</span>
297+
</button>
298+
<h4 class="modal-title">Setup Log Viewer</h4>
299+
</div>
300+
<div class="modal-body">
301+
<div class="btn-group">
302+
<ul class="dropdown-menu" role="menu">
303+
</ul>
304+
</div>
305+
<ul class="list-unstyled setup-flightlog-list">
306+
</ul>
307+
</div>
308+
<div class="modal-footer">
309+
<button type="button" class="btn btn-default flightlog-setup-dialog-cancel" data-dismiss="modal">Cancel</button>
310+
<button type="button" class="btn btn-primary flightlog-setup-dialog-save" data-dismiss="modal">Save changes</button>
311+
</div>
312+
</div>
313+
</div>
314+
</div>
315+
289316
<div class="modal fade" id="dlgVideoExport">
290317
<div class="modal-dialog">
291318
<div class="modal-content">
@@ -419,11 +446,13 @@ <h4 class="modal-title">Export video</h4>
419446
<script src="js/flightlog_fields_presenter.js"></script>
420447
<script src="js/flightlog_parser.js"></script>
421448
<script src="js/flightlog_index.js"></script>
449+
<script src="js/flightlog_setup_dialog.js"></script>
422450
<script src="js/flightlog.js"></script>
423451
<script src="js/grapher.js"></script>
424452
<script src="js/graph_config.js"></script>
425453
<script src="js/graph_legend.js"></script>
426454
<script src="js/graph_config_dialog.js"></script>
455+
<script src="js/graph_spectrum.js"></script>
427456
<script src="js/seekbar.js"></script>
428457
<script src="js/video_export_dialog.js"></script>
429458
<script src="js/flightlog_video_renderer.js"></script>

js/expo.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
*/
88
function ExpoCurve(offset, power, inputRange, outputRange, steps) {
99
var
10-
curve, inputScale;
10+
curve, inputScale, rawInputScale;
1111

1212
function lookupStraightLine(input) {
1313
return (input + offset) * inputScale;
1414
}
1515

16+
this.lookupRaw = function(input) {
17+
return (input + offset) * rawInputScale;
18+
}
19+
1620
/**
1721
* An approximation of lookupMathPow by precomputing several expo curve points and interpolating between those
1822
* points using straight line interpolation.
@@ -58,6 +62,8 @@ function ExpoCurve(offset, power, inputRange, outputRange, steps) {
5862
return result;
5963
}
6064

65+
rawInputScale = outputRange / inputRange;
66+
6167
// If steps argument isn't supplied, use a reasonable default
6268
if (steps === undefined) {
6369
steps = 12;

js/flightlog.js

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* Additional computed fields are derived from the original data set and added as new fields in the resulting data.
1010
* Window based smoothing of fields is offered.
1111
*/
12-
function FlightLog(logData) {
12+
function FlightLog(logData, newSettings) {
1313
var
14-
ADDITIONAL_COMPUTED_FIELD_COUNT = 6, /** attitude + PID_SUM **/
14+
ADDITIONAL_COMPUTED_FIELD_COUNT = 15, /** attitude + PID_SUM + PID_ERROR + RCCOMMAND_SCALED + GYROADC_SCALED **/
1515

1616
that = this,
1717
logIndex = false,
@@ -33,10 +33,13 @@ function FlightLog(logData) {
3333
maxSmoothing = 0,
3434

3535
smoothedCache = new FIFOCache(2);
36+
3637

3738
//Public fields:
3839
this.parser = parser;
3940

41+
this.settings = newSettings;
42+
4043
this.getMainFieldCount = function() {
4144
return fieldNames.length;
4245
};
@@ -199,6 +202,9 @@ function FlightLog(logData) {
199202
// Add names for our ADDITIONAL_COMPUTED_FIELDS
200203
fieldNames.push("heading[0]", "heading[1]", "heading[2]");
201204
fieldNames.push("axisSum[0]", "axisSum[1]", "axisSum[2]");
205+
fieldNames.push("axisError[0]", "axisError[1]", "axisError[2]"); // Custom calculated error field
206+
fieldNames.push("rcCommands[0]", "rcCommands[1]", "rcCommands[2]"); // Custom calculated error field
207+
fieldNames.push("gyroADCs[0]", "gyroADCs[1]", "gyroADCs[2]"); // Custom calculated error field
202208

203209
fieldNameToIndex = {};
204210
for (i = 0; i < fieldNames.length; i++) {
@@ -469,7 +475,8 @@ function FlightLog(logData) {
469475
gyroADC = [fieldNameToIndex["gyroADC[0]"], fieldNameToIndex["gyroADC[1]"], fieldNameToIndex["gyroADC[2]"]],
470476
accSmooth = [fieldNameToIndex["accSmooth[0]"], fieldNameToIndex["accSmooth[1]"], fieldNameToIndex["accSmooth[2]"]],
471477
magADC = [fieldNameToIndex["magADC[0]"], fieldNameToIndex["magADC[1]"], fieldNameToIndex["magADC[2]"]],
472-
478+
rcCommand = [fieldNameToIndex["rcCommand[0]"], fieldNameToIndex["rcCommand[1]"], fieldNameToIndex["rcCommand[2]"]],
479+
473480
sourceChunkIndex, destChunkIndex,
474481

475482
sysConfig,
@@ -534,6 +541,25 @@ function FlightLog(logData) {
534541
(axisPID[axis][1] !== undefined ? srcFrame[axisPID[axis][1]] : 0) +
535542
(axisPID[axis][2] !== undefined ? srcFrame[axisPID[axis][2]] : 0);
536543
}
544+
545+
// Calculate the PID Error
546+
for (var axis = 0; axis < 3; axis++) {
547+
destFrame[fieldIndex++] =
548+
(gyroADC[axis] !== undefined ? that.gyroRawToDegreesPerSecond(srcFrame[gyroADC[axis]]) : 0) -
549+
(rcCommand[axis] !== undefined ? that.rcCommandRawToDegreesPerSecond(srcFrame[rcCommand[axis]], axis) : 0);
550+
}
551+
// Calculate the Scaled rcCommand (in deg/s)
552+
for (var axis = 0; axis < 3; axis++) {
553+
destFrame[fieldIndex++] =
554+
(rcCommand[axis] !== undefined ? that.rcCommandRawToDegreesPerSecond(srcFrame[rcCommand[axis]], axis) : 0);
555+
}
556+
557+
// Calculate the scaled Gyro ADC
558+
for (var axis = 0; axis < 3; axis++) {
559+
destFrame[fieldIndex++] =
560+
(gyroADC[axis] !== undefined ? that.gyroRawToDegreesPerSecond(srcFrame[gyroADC[axis]]) : 0);
561+
}
562+
537563
}
538564
}
539565
}
@@ -881,6 +907,28 @@ FlightLog.prototype.gyroRawToDegreesPerSecond = function(value) {
881907
return this.getSysConfig().gyroScale * 1000000 / (Math.PI / 180.0) * value;
882908
};
883909

910+
// Convert rcCommand to degrees per second
911+
FlightLog.prototype.rcCommandRawToDegreesPerSecond = function(value, axis) {
912+
913+
// Axis 0,1 refers to Roll and Pitch
914+
// Axis 2 refers to Yaw.
915+
916+
// ReWrite or LUXFloat only
917+
918+
919+
// if(axis==2 /*YAW*/) {
920+
// return ((this.settings[0].parameters[axis].value + 47) * value ) >> 7;
921+
// } else { /*ROLL or PITCH */
922+
// return ((this.settings[0].parameters[axis].value + 27) * value ) >> 6;
923+
// }
924+
925+
if(axis==2 /*YAW*/) {
926+
return ((this.getSysConfig().yRate + 47) * value ) >> 7;
927+
} else { /*ROLL or PITCH */
928+
return ((((axis==0)?this.getSysConfig().rRate:this.getSysConfig().pRate) + 27) * value ) >> 6;
929+
}
930+
};
931+
884932
FlightLog.prototype.getReferenceVoltageMillivolts = function() {
885933
return this.vbatADCToMillivolts(this.getSysConfig().vbatref);
886934
};

js/flightlog_fielddefs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var
2121
LOGGING_RESUME: 14,
2222

2323
GTUNE_CYCLE_RESULT: 20,
24+
FLIGHT_MODE: 30, // New Event type
2425

2526
LOG_END: 255
2627
}),

js/flightlog_fields_presenter.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,26 @@ function FlightLogFieldPresenter() {
5959
'axisSum[all]': 'PID_sum',
6060
'axisSum[0]' : 'PID_sum[roll]',
6161
'axisSum[1]' : 'PID_sum[pitch]',
62-
'axisSum[2]' : 'PID_sum[yaw]'
62+
'axisSum[2]' : 'PID_sum[yaw]',
63+
64+
//Virtual fields - Add the Error fields
65+
'axisError[all]': 'PID_Error',
66+
'axisError[0]' : 'PID_Error[roll]',
67+
'axisError[1]' : 'PID_Error[pitch]',
68+
'axisError[2]' : 'PID_Error[yaw]',
69+
70+
//Virtual fields - add the Scaled rcCommands
71+
'rcCommands[all]': 'rcCommands',
72+
'rcCommands[0]' : 'rcCommands[roll]',
73+
'rcCommands[1]' : 'rcCommands[pitch]',
74+
'rcCommands[2]' : 'rcCommands[yaw]',
75+
76+
//Virtual fields - add the Scaled gyros
77+
'gyroADCs[all]': 'gyros',
78+
'gyroADCs[0]': 'gyros[roll]',
79+
'gyroADCs[1]': 'gyros[pitch]',
80+
'gyroADCs[2]': 'gyros[yaw]'
81+
6382
};
6483

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

141+
case 'axisError[0]':
142+
case 'axisError[1]':
143+
case 'axisError[2]':
144+
return Math.round(value) + " deg/s";
145+
146+
case 'rcCommand[0]':
147+
return Math.round(flightLog.rcCommandRawToDegreesPerSecond(value,0)) + " deg/s";
148+
case 'rcCommand[1]':
149+
return Math.round(flightLog.rcCommandRawToDegreesPerSecond(value,1)) + " deg/s";
150+
case 'rcCommand[2]':
151+
return Math.round(flightLog.rcCommandRawToDegreesPerSecond(value,2)) + " deg/s";
152+
122153
case 'accSmooth[0]':
123154
case 'accSmooth[1]':
124155
case 'accSmooth[2]':

js/flightlog_parser.js

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,20 @@ var FlightLogParser = function(logData) {
188188
currentMeterScale: 400,
189189
deviceUID: null
190190
},
191+
192+
// One day, maybe these will be part of the blackbox log; they certainly would be helpfull!
193+
// If so, then they can be moved intor the defaultSysConfig definition above.
194+
// At the moment they are entered on a dialog box.
195+
196+
defaultSysConfigExtension = {
197+
rcExpo:null,//70, // RC Expo
198+
rRate:null,//0, // Roll Rate
199+
pRate:null,//0, // Pitch Rate
200+
yRate:null,//45, // Yaw Rate
201+
rcYawExpo: null,//20, // Yaw Expo
202+
superExpoFactor: null,//30, // Super Expo Factor
203+
loopTime: null,//500, // Looptime
204+
},
191205

192206
frameTypes,
193207

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

221235
//The actual log data stream we're reading:
222236
stream;
223-
237+
224238
//Public fields:
225239

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

231-
this.sysConfig = Object.create(defaultSysConfig);
232-
245+
// Lets add the custom extensions
246+
var completeSysConfig = $.extend({}, defaultSysConfig, defaultSysConfigExtension);
247+
this.sysConfig = Object.create(completeSysConfig); // Object.create(defaultSysConfig);
248+
233249
/*
234250
* Event handler of the signature (frameValid, frame, frameType, frameOffset, frameSize)
235251
* called when a frame has been decoded.
@@ -331,6 +347,28 @@ var FlightLogParser = function(logData) {
331347
case "rcRate":
332348
that.sysConfig.rcRate = parseInt(fieldValue, 10);
333349
break;
350+
351+
// In future these fields may exist int the blackbox log
352+
case "rcExpo":
353+
that.sysConfig.rcExpo = parseInt(fieldValue, 10);
354+
break;
355+
case "rates":
356+
var ratesParams = parseCommaSeparatedIntegers(fieldValue);
357+
that.sysConfig.rRate = ratesParams[0];
358+
that.sysConfig.pRate = ratesParams[1];
359+
that.sysConfig.yRate = ratesParams[2];
360+
break;
361+
case "rcYawExpo":
362+
that.sysConfig.rcYawExpo = parseInt(fieldValue, 10);
363+
break;
364+
case "superExpoFactor":
365+
that.sysConfig.superExpoFactor = parseInt(fieldValue, 10);
366+
break;
367+
case "looptime":
368+
that.sysConfig.loopTime = parseInt(fieldValue, 10);
369+
break;
370+
/****************************/
371+
334372
case "vbatscale":
335373
that.sysConfig.vbatscale = parseInt(fieldValue, 10);
336374
break;
@@ -868,6 +906,10 @@ var FlightLogParser = function(logData) {
868906
lastEvent.data.time = stream.readUnsignedVB();
869907
lastEvent.time = lastEvent.data.time;
870908
break;
909+
case FlightLogEvent.FLIGHT_MODE: // get the flag status change
910+
lastEvent.data.newFlags = stream.readUnsignedVB();
911+
lastEvent.data.lastFlags = stream.readUnsignedVB();
912+
break;
871913
case FlightLogEvent.AUTOTUNE_CYCLE_START:
872914
lastEvent.data.phase = stream.readByte();
873915

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

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

9681012
this.frameDefs = {};
9691013

0 commit comments

Comments
 (0)