Skip to content

Commit

Permalink
Add Pitch/Roll and Yaw Rate Parameters
Browse files Browse the repository at this point in the history
New feature : Adding pitch/roll and yaw rate parameters that were
active when log was made will allow rcCommand to show actual deg/s
value alongside raw input. This is then used to calculate new PID_Error
values as deg/s
  • Loading branch information
Gary Keeble authored and Gary Keeble committed Apr 11, 2016
1 parent b90d0d6 commit eb13746
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 26 deletions.
27 changes: 27 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ <h2>Legend <span class="log-close-legend-dialog glyphicon glyphicon-remove"></sp
<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 @@ -287,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 @@ -420,6 +446,7 @@ <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>
Expand Down
52 changes: 26 additions & 26 deletions js/flightlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,31 @@ function FlightLog(logData) {
maxSmoothing = 0,

smoothedCache = new FIFOCache(2);


//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.getMainFieldCount = function() {
return fieldNames.length;
};
Expand Down Expand Up @@ -898,34 +919,13 @@ FlightLog.prototype.rcCommandRawToDegreesPerSecond = function(value, axis) {
// Axis 0,1 refers to Roll and Pitch
// Axis 2 refers to Yaw.

var rRate = 65; // Roll Rate from configuration
var pRate = 65; // Pitch Rate from configuration
var yRate = 65; // Yaw Rate from configuration

var REWRITE = true; // Define that this is for the Rewrite Data - need to make dynamic!
// ReWrite or LUXFloat only

if(REWRITE) // PID is ReWrite
{
if(axis==0 /*ROLL*/) {
return ((rRate + 27) * value ) >> 6;
}
if(axis==1 /*PITCH*/) {
return ((pRate + 27) * value ) >> 6;
}
if(axis==2 /*YAW*/) {
return ((yRate + 27) * value ) >> 7;
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;
}
} else { // PID is Luxfloat
if(axis==0 /*ROLL*/) {
return ((rRate+20)*value) / 50;
}
if(axis==1 /*PITCH*/) {
return ((pRate+20)*value) / 50;
}
if(axis==2 /*YAW*/) {
return ((yRate+10)*value) / 50;
}
}
};


Expand Down
101 changes: 101 additions & 0 deletions js/flightlog_setup_dialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
"use strict";

function FlightLogSetupDialog(dialog, onSave) {

function renderParameter(parameter) {
var
elem = $(
'<li class="setup-parameter">'
+ '<label class="col-sm-2 control-label">' + parameter.label + '</label>'
+ '<input class="form-control" type="text" placeholder="Enter the value">'
+ '</li>'
);

$("input", elem).val(parameter.value);

return elem;
}

function renderParameters(setting) {
var
parametersElem = $(
'<li class="setup-parameters">'
+ '<dl>'
+ '<dt><h4>' + setting.label + '</dt>'
+ '<dd>'
+ '<div class="form-horizontal">'
+ '<div class="form-group form-group-sm">'
+ '<ul class="setup-parameter-list form-inline list-unstyled"></ul>'
+ '</div>'
+ '</div>'
+ '</dd>'
+ '</dl>'
+ '</li>'
),
parameterList = $(".setup-parameter-list", parametersElem);

for (var i = 0; i < setting.parameters.length; i++) {
var
parameter = setting.parameters[i],
parameterElem = renderParameter(parameter);

parameterList.append(parameterElem);
}

return parametersElem;
}

function renderSettings(flightLog) {
var
settingsList = $(".setup-flightlog-list", dialog);

settingsList.empty();

for (var i = 0; i < flightLog.settings.length; i++) {
settingsList.append(renderParameters(flightLog.settings[i]));
}
}

function convertUIToFlightLogSettings() {
var
settings = [],
setting,
parameter;

$(".setup-parameters", dialog).each(function() {
setting = {
label: '',
parameters: []
};

setting.label = $("h4", this).text();

$(".setup-parameter", this).each(function() {
parameter = {
label: $("label", this).text(),
value: parseInt($("input[type='text']", this).val()),
};
setting.parameters.push(parameter);
});

settings.push(setting);
});

return settings;
}

this.show = function(flightLog, settings) {
dialog.modal('show');

// Assign the settings
flightLog.settings = settings;

renderSettings(flightLog);
};

$(".flightlog-setup-dialog-save").click(function(e) {
onSave(convertUIToFlightLogSettings());
});


}
43 changes: 43 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ function BlackboxLogViewer() {
// JSON graph configuration:
graphConfig = {},

// JSON flightlog configuration
flightLogSettings = {},

// Graph configuration which is currently in use, customised based on the current flight log from graphConfig
activeGraphConfig = new GraphConfig(),

Expand Down Expand Up @@ -548,6 +551,33 @@ function BlackboxLogViewer() {
}
});

prefs.get('flightLogSettings', function(item) {
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
}
]
},
];
}
});


activeGraphConfig.addListener(function() {
invalidateGraph();
});
Expand Down Expand Up @@ -666,6 +696,13 @@ function BlackboxLogViewer() {
prefs.set('graphConfig', graphConfig);
}),

flightLogSetupDialog = new FlightLogSetupDialog($("#dlgFlightLogSetup"), function(newSettings) {
flightLog.settings = newSettings; // Store the settings to the flightlog

flightLogSettings = newSettings; // Let's write this information to the local store
prefs.set('flightLogSettings', flightLogSettings);
}),

exportDialog = new VideoExportDialog($("#dlgVideoExport"), function(newConfig) {
videoConfig = newConfig;

Expand All @@ -679,6 +716,12 @@ function BlackboxLogViewer() {
graphConfigDialog.show(flightLog, graphConfig);
});

$(".open-log-setup-dialog").click(function(e) {
e.preventDefault();

flightLogSetupDialog.show(flightLog, flightLogSettings);
});

if (FlightLogVideoRenderer.isSupported()) {
$(".btn-video-export").click(function(e) {
setGraphState(GRAPH_STATE_PAUSED);
Expand Down

0 comments on commit eb13746

Please sign in to comment.