Skip to content

Commit

Permalink
Additional Graph Fields
Browse files Browse the repository at this point in the history
Added scaled rcCommand and gyroADC fields so that direct comparison
between command and result can be made.
  • Loading branch information
Gary Keeble authored and Gary Keeble committed Apr 14, 2016
1 parent eb13746 commit a8dbf53
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 53 deletions.
49 changes: 25 additions & 24 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 @@ -38,25 +38,7 @@ function FlightLog(logData) {
//Public fields:
this.parser = parser;

this.settings = [ // FlightLog Settings
{ label: "Rates",
parameters:
[
{ // Index 0
label: "Roll Rate",
value: 75
},
{ // Index 1
label: "Pitch Rate",
value: 75
},
{ // Index 2
label: "Yaw Rate",
value: 45
}
]
},
];
this.settings = newSettings;

this.getMainFieldCount = function() {
return fieldNames.length;
Expand Down Expand Up @@ -221,6 +203,8 @@ function FlightLog(logData) {
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 @@ -563,8 +547,18 @@ function FlightLog(logData) {
destFrame[fieldIndex++] =
(gyroADC[axis] !== undefined ? that.gyroRawToDegreesPerSecond(srcFrame[gyroADC[axis]]) : 0) -
(rcCommand[axis] !== undefined ? that.rcCommandRawToDegreesPerSecond(srcFrame[rcCommand[axis]], axis) : 0);
console.log()
}
}
// 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 @@ -921,13 +915,20 @@ FlightLog.prototype.rcCommandRawToDegreesPerSecond = function(value, axis) {

// 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;
}
};

// var sysConfig = this.getSysConfig();
// 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
14 changes: 13 additions & 1 deletion js/flightlog_fields_presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,19 @@ function FlightLogFieldPresenter() {
'axisError[all]': 'PID_Error',
'axisError[0]' : 'PID_Error[roll]',
'axisError[1]' : 'PID_Error[pitch]',
'axisError[2]' : 'PID_Error[yaw]'
'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]'

};

Expand Down
45 changes: 42 additions & 3 deletions js/flightlog_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ 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:70, // RC Expo
rRate:0, // Roll Rate
pRate:0, // Pitch Rate
yRate:45, // Yaw Rate
yawExpo: 20, // Yaw Expo
loopTime: 500, // Looptime
},

frameTypes,

Expand Down Expand Up @@ -228,8 +241,10 @@ var FlightLogParser = function(logData) {
*/
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 +346,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 "rRate":
that.sysConfig.rRate = parseInt(fieldValue, 10);
break;
case "pRate":
that.sysConfig.pRate = parseInt(fieldValue, 10);
break;
case "yRate":
that.sysConfig.yRate = parseInt(fieldValue, 10);
break;
case "yExpo":
that.sysConfig.yExpo = 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 @@ -963,7 +1000,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
24 changes: 19 additions & 5 deletions js/graph_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ GraphConfig.load = function(config) {
fields: ["axisSum[all]"]
},
{
label: "Gyro Error",
label: "PID Error",
fields: ["axisError[all]"]
},
{
Expand Down Expand Up @@ -243,13 +243,27 @@ GraphConfig.load = function(config) {
inputRange: sysConfig.acc_1G * 3.0, /* Reasonable typical maximum for acc */
outputRange: 1.0
};
} else if (fieldName.match(/^axisError\[/)) { // new PID error field
} else if (fieldName.match(/^axisError\[/)) { // Custom PID error field
return {
offset: 0,
power: 0.8, /* Make this 1.0 to scale linearly */
inputRange: 1000, // Maximum error is hard coded to 1000 deg/s
power: 1.0, /* Make this 1.0 to scale linearly */
inputRange: 1200, // Maximum error is hard coded to 1200 deg/s
outputRange: 1.0
};
} else if (fieldName.match(/^rcCommands\[/)) { // Custom scaled rcCommand scaling
return {
offset: 0,
power: 1.0,
inputRange: 1200,
outputRange: 1.0
};
} else if (fieldName.match(/^gyroADCs\[/)) { // Custom gyroADC scaling
return {
offset: 0,
power: 1.0,
inputRange: 1200,
outputRange: 1.0
};
} else if (fieldName.match(/^axis.+\[/)) {
return {
offset: 0,
Expand Down Expand Up @@ -277,7 +291,7 @@ GraphConfig.load = function(config) {
power: 0.8,
inputRange: 500 * (sysConfig.rcRate ? sysConfig.rcRate : 100) / 100,
outputRange: 1.0
};
};
} else if (fieldName == "heading[2]") {
return {
offset: -Math.PI,
Expand Down
56 changes: 36 additions & 20 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,40 @@ function BlackboxLogViewer() {

// JSON flightlog configuration
flightLogSettings = {},

flightLogDefaultSettings = [ // FlightLog Default Settings
{ label: "Rates",
parameters:
[
{ // Index 0
label: "Roll Rate",
value: 75
},
{ // Index 1
label: "Pitch Rate",
value: 75
},
{ // Index 2
label: "Yaw Rate",
value: 45
},
{ // Index 3
label: "Yaw Expo",
value: 20
}
]
},
{ label: "Loop Time",
parameters:
[
{ // Index 0
label: "Looptime",
value: 500
},
]
},
],


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

try {
flightLog = new FlightLog(flightLogDataArray);
flightLog = new FlightLog(flightLogDataArray, flightLogSettings);
} catch (err) {
alert("Sorry, an error occured while trying to open this log:\n\n" + err);
return;
Expand Down Expand Up @@ -555,25 +589,7 @@ function BlackboxLogViewer() {
if(item) {
flightLogSettings = item;
} else {
flightLogSettings = [ // FlightLog Default Settings
{ label: "Rates",
parameters:
[
{ // Index 0
label: "Roll Rate",
value: 75
},
{ // Index 1
label: "Pitch Rate",
value: 75
},
{ // Index 2
label: "Yaw Rate",
value: 45
}
]
},
];
flightLogSettings = flightLogDefaultSettings;
}
});

Expand Down

0 comments on commit a8dbf53

Please sign in to comment.