Skip to content

Commit a8dbf53

Browse files
Gary KeebleGary Keeble
authored andcommitted
Additional Graph Fields
Added scaled rcCommand and gyroADC fields so that direct comparison between command and result can be made.
1 parent eb13746 commit a8dbf53

File tree

5 files changed

+135
-53
lines changed

5 files changed

+135
-53
lines changed

js/flightlog.js

Lines changed: 25 additions & 24 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,
@@ -38,25 +38,7 @@ function FlightLog(logData) {
3838
//Public fields:
3939
this.parser = parser;
4040

41-
this.settings = [ // FlightLog Settings
42-
{ label: "Rates",
43-
parameters:
44-
[
45-
{ // Index 0
46-
label: "Roll Rate",
47-
value: 75
48-
},
49-
{ // Index 1
50-
label: "Pitch Rate",
51-
value: 75
52-
},
53-
{ // Index 2
54-
label: "Yaw Rate",
55-
value: 45
56-
}
57-
]
58-
},
59-
];
41+
this.settings = newSettings;
6042

6143
this.getMainFieldCount = function() {
6244
return fieldNames.length;
@@ -221,6 +203,8 @@ function FlightLog(logData) {
221203
fieldNames.push("heading[0]", "heading[1]", "heading[2]");
222204
fieldNames.push("axisSum[0]", "axisSum[1]", "axisSum[2]");
223205
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
224208

225209
fieldNameToIndex = {};
226210
for (i = 0; i < fieldNames.length; i++) {
@@ -563,8 +547,18 @@ function FlightLog(logData) {
563547
destFrame[fieldIndex++] =
564548
(gyroADC[axis] !== undefined ? that.gyroRawToDegreesPerSecond(srcFrame[gyroADC[axis]]) : 0) -
565549
(rcCommand[axis] !== undefined ? that.rcCommandRawToDegreesPerSecond(srcFrame[rcCommand[axis]], axis) : 0);
566-
console.log()
567-
}
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+
}
568562

569563
}
570564
}
@@ -921,13 +915,20 @@ FlightLog.prototype.rcCommandRawToDegreesPerSecond = function(value, axis) {
921915

922916
// ReWrite or LUXFloat only
923917

918+
924919
if(axis==2 /*YAW*/) {
925920
return ((this.settings[0].parameters[axis].value + 47) * value ) >> 7;
926921
} else { /*ROLL or PITCH */
927922
return ((this.settings[0].parameters[axis].value + 27) * value ) >> 6;
928923
}
929-
};
930924

925+
// var sysConfig = this.getSysConfig();
926+
// if(axis==2 /*YAW*/) {
927+
// return ((this.getSysConfig().yRate + 47) * value ) >> 7;
928+
// } else { /*ROLL or PITCH */
929+
// return ((((axis==0)?this.getSysConfig().rRate:this.getSysConfig().pRate) + 27) * value ) >> 6;
930+
// }
931+
};
931932

932933
FlightLog.prototype.getReferenceVoltageMillivolts = function() {
933934
return this.vbatADCToMillivolts(this.getSysConfig().vbatref);

js/flightlog_fields_presenter.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,19 @@ function FlightLogFieldPresenter() {
6565
'axisError[all]': 'PID_Error',
6666
'axisError[0]' : 'PID_Error[roll]',
6767
'axisError[1]' : 'PID_Error[pitch]',
68-
'axisError[2]' : 'PID_Error[yaw]'
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]'
6981

7082
};
7183

js/flightlog_parser.js

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,19 @@ 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:70, // RC Expo
198+
rRate:0, // Roll Rate
199+
pRate:0, // Pitch Rate
200+
yRate:45, // Yaw Rate
201+
yawExpo: 20, // Yaw Expo
202+
loopTime: 500, // Looptime
203+
},
191204

192205
frameTypes,
193206

@@ -228,8 +241,10 @@ var FlightLogParser = function(logData) {
228241
*/
229242
this.frameDefs = {};
230243

231-
this.sysConfig = Object.create(defaultSysConfig);
232-
244+
// Lets add the custom extensions
245+
var completeSysConfig = $.extend({}, defaultSysConfig, defaultSysConfigExtension);
246+
this.sysConfig = Object.create(completeSysConfig); // Object.create(defaultSysConfig);
247+
233248
/*
234249
* Event handler of the signature (frameValid, frame, frameType, frameOffset, frameSize)
235250
* called when a frame has been decoded.
@@ -331,6 +346,28 @@ var FlightLogParser = function(logData) {
331346
case "rcRate":
332347
that.sysConfig.rcRate = parseInt(fieldValue, 10);
333348
break;
349+
350+
/* In future these fields may exist int the blackbox log
351+
case "rcExpo":
352+
that.sysConfig.rcExpo = parseInt(fieldValue, 10);
353+
break;
354+
case "rRate":
355+
that.sysConfig.rRate = parseInt(fieldValue, 10);
356+
break;
357+
case "pRate":
358+
that.sysConfig.pRate = parseInt(fieldValue, 10);
359+
break;
360+
case "yRate":
361+
that.sysConfig.yRate = parseInt(fieldValue, 10);
362+
break;
363+
case "yExpo":
364+
that.sysConfig.yExpo = parseInt(fieldValue, 10);
365+
break;
366+
case "loopTime":
367+
that.sysConfig.loopTime = parseInt(fieldValue, 10);
368+
break;
369+
*******/
370+
334371
case "vbatscale":
335372
that.sysConfig.vbatscale = parseInt(fieldValue, 10);
336373
break;
@@ -963,7 +1000,9 @@ var FlightLogParser = function(logData) {
9631000
this.resetStats();
9641001

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

9681007
this.frameDefs = {};
9691008

js/graph_config.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ GraphConfig.load = function(config) {
174174
fields: ["axisSum[all]"]
175175
},
176176
{
177-
label: "Gyro Error",
177+
label: "PID Error",
178178
fields: ["axisError[all]"]
179179
},
180180
{
@@ -243,13 +243,27 @@ GraphConfig.load = function(config) {
243243
inputRange: sysConfig.acc_1G * 3.0, /* Reasonable typical maximum for acc */
244244
outputRange: 1.0
245245
};
246-
} else if (fieldName.match(/^axisError\[/)) { // new PID error field
246+
} else if (fieldName.match(/^axisError\[/)) { // Custom PID error field
247247
return {
248248
offset: 0,
249-
power: 0.8, /* Make this 1.0 to scale linearly */
250-
inputRange: 1000, // Maximum error is hard coded to 1000 deg/s
249+
power: 1.0, /* Make this 1.0 to scale linearly */
250+
inputRange: 1200, // Maximum error is hard coded to 1200 deg/s
251251
outputRange: 1.0
252252
};
253+
} else if (fieldName.match(/^rcCommands\[/)) { // Custom scaled rcCommand scaling
254+
return {
255+
offset: 0,
256+
power: 1.0,
257+
inputRange: 1200,
258+
outputRange: 1.0
259+
};
260+
} else if (fieldName.match(/^gyroADCs\[/)) { // Custom gyroADC scaling
261+
return {
262+
offset: 0,
263+
power: 1.0,
264+
inputRange: 1200,
265+
outputRange: 1.0
266+
};
253267
} else if (fieldName.match(/^axis.+\[/)) {
254268
return {
255269
offset: 0,
@@ -277,7 +291,7 @@ GraphConfig.load = function(config) {
277291
power: 0.8,
278292
inputRange: 500 * (sysConfig.rcRate ? sysConfig.rcRate : 100) / 100,
279293
outputRange: 1.0
280-
};
294+
};
281295
} else if (fieldName == "heading[2]") {
282296
return {
283297
offset: -Math.PI,

js/main.js

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,40 @@ function BlackboxLogViewer() {
4040

4141
// JSON flightlog configuration
4242
flightLogSettings = {},
43+
44+
flightLogDefaultSettings = [ // FlightLog Default Settings
45+
{ label: "Rates",
46+
parameters:
47+
[
48+
{ // Index 0
49+
label: "Roll Rate",
50+
value: 75
51+
},
52+
{ // Index 1
53+
label: "Pitch Rate",
54+
value: 75
55+
},
56+
{ // Index 2
57+
label: "Yaw Rate",
58+
value: 45
59+
},
60+
{ // Index 3
61+
label: "Yaw Expo",
62+
value: 20
63+
}
64+
]
65+
},
66+
{ label: "Loop Time",
67+
parameters:
68+
[
69+
{ // Index 0
70+
label: "Looptime",
71+
value: 500
72+
},
73+
]
74+
},
75+
],
76+
4377

4478
// Graph configuration which is currently in use, customised based on the current flight log from graphConfig
4579
activeGraphConfig = new GraphConfig(),
@@ -473,7 +507,7 @@ function BlackboxLogViewer() {
473507
flightLogDataArray = new Uint8Array(bytes);
474508

475509
try {
476-
flightLog = new FlightLog(flightLogDataArray);
510+
flightLog = new FlightLog(flightLogDataArray, flightLogSettings);
477511
} catch (err) {
478512
alert("Sorry, an error occured while trying to open this log:\n\n" + err);
479513
return;
@@ -555,25 +589,7 @@ function BlackboxLogViewer() {
555589
if(item) {
556590
flightLogSettings = item;
557591
} else {
558-
flightLogSettings = [ // FlightLog Default Settings
559-
{ label: "Rates",
560-
parameters:
561-
[
562-
{ // Index 0
563-
label: "Roll Rate",
564-
value: 75
565-
},
566-
{ // Index 1
567-
label: "Pitch Rate",
568-
value: 75
569-
},
570-
{ // Index 2
571-
label: "Yaw Rate",
572-
value: 45
573-
}
574-
]
575-
},
576-
];
592+
flightLogSettings = flightLogDefaultSettings;
577593
}
578594
});
579595

0 commit comments

Comments
 (0)