Rates preview for PID Tuning tab

10.3.x-maintenance
Anthony Dmitriyev 2016-06-29 21:59:47 +01:00
parent 9bbc5cc000
commit a0b2d9a090
5 changed files with 166 additions and 68 deletions

View File

@ -766,6 +766,9 @@
"pidTuningRate": {
"message": "Rate"
},
"pidTuningRatesPreview": {
"message": "Rates Preview"
},
"pidTuningRcExpo": {
"message": "RC Expo"
},

View File

@ -118,6 +118,16 @@ Model.prototype.rotateTo = function (x, y, z) {
this.render();
};
Model.prototype.rotateBy = function (x, y, z) {
if (!this.model) { return; }
this.model.rotateX(x);
this.model.rotateY(y);
this.model.rotateZ(z);
this.render();
};
Model.prototype.render = function () {
if (!this.model) { return; }

View File

@ -177,11 +177,6 @@
border-top-right-radius: 3px;
}
.tab-pid_tuning .tpa {
/*border: 0px solid #ccc; */
margin-bottom: 10px;
}
.tab-pid_tuning .rc_curve {
float: right;
width: calc(100% - 2px); /* - ( "virtual" margin) */
@ -580,3 +575,21 @@
margin-top: -28px;
margin-left: 8px;
}
.tab-pid_tuning .rates_preview_cell {
position: relative;
width: 100%;
height: 0;
padding-bottom: 100%;
}
.tab-pid_tuning .rates_preview {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-image: url(../images/paper.jpg);
background-size: 100%;
background-position: center;
}

View File

@ -199,10 +199,9 @@
</tr>
</table>
</div>
</div>
<div class="cf_column third_right">
<div class="spacer_left">
<div class="cf_column half topspacer">
<div>
<table class="rc_curve cf">
<thead>
<tr>
@ -221,8 +220,9 @@
</tr>
</tbody>
</table>
<div class="clear-both"></div>
</div>
<div class="spacer_left topspacer">
<div class="topspacer">
<table class="rc_yaw_curve cf">
<thead>
<tr>
@ -241,8 +241,32 @@
</tr>
</tbody>
</table>
<div class="clear-both"></div>
</div>
<div class="spacer_left throttle topspacer">
</div>
<div class="cf_column half topspacer">
<table class="tpa cf">
<thead>
<tr>
<th i18n="pidTuningRatesPreview"></th>
</tr>
</thead>
<tbody>
<tr>
<td class="rates_preview_cell">
<div class="rates_preview">
<canvas id="canvas"></canvas>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cf_column third_right">
<div class="spacer_left throttle">
<table class="cf">
<thead>
<tr>
@ -259,10 +283,18 @@
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="spacer_left topspacer">
<table class="tpa cf">
<thead>
<tr>
<th i18n="receiverThrottleMid"></th>
<th i18n="receiverThrottleExpo"></th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="number" name="mid" step="0.01" min="0" max="1" /></td>
<td><input type="number" name="expo" step="0.01" min="0" max="1" /></td>

View File

@ -315,7 +315,6 @@ TABS.pid_tuning.initialize = function (callback) {
}
});
pid_and_rc_to_form();
var pidController_e = $('select[name="controller"]');
@ -532,6 +531,13 @@ TABS.pid_tuning.initialize = function (callback) {
}
});
// Setup model for rates preview
self.initRatesPreview();
self.renderModel();
// enable RC data pulling for rates preview
GUI.interval_add('receiver_pull', self.getRecieverData, true);
// status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function status_pull() {
MSP.send_message(MSP_codes.MSP_STATUS);
@ -541,8 +547,42 @@ TABS.pid_tuning.initialize = function (callback) {
}
};
TABS.pid_tuning.cleanup = function (callback) {
if (callback) {
callback();
TABS.pid_tuning.getRecieverData = function () {
MSP.send_message(MSP_codes.MSP_RC, false, false);
};
TABS.pid_tuning.initRatesPreview = function () {
this.keepRendering = true;
this.model = new Model($('.rates_preview'), $('.rates_preview canvas'));
var scale = d3.scale.linear().domain([900, 2100]);
this.rollScale = scale.range([Math.PI * 2, -Math.PI * 2]);
this.pitchScale = scale.range([Math.PI * 2, -Math.PI * 2]);
this.yawScale = scale.range([Math.PI * 2, -Math.PI * 2]);
$(window).on('resize', $.proxy(this.model.resize, this.model));
};
TABS.pid_tuning.renderModel = function () {
if (this.keepRendering) { requestAnimationFrame(this.renderModel.bind(this)); }
if (!this.clock) { this.clock = new THREE.Clock(); }
if (RC.channels[0] && RC.channels[1] && RC.channels[2]) {
var delta = this.clock.getDelta(),
roll = delta * this.rollScale(RC.channels[0]),
pitch = delta * this.pitchScale(RC.channels[1]),
yaw = delta * this.yawScale(RC.channels[2]);
this.model.rotateBy(pitch, yaw, roll);
}
};
TABS.pid_tuning.cleanup = function (callback) {
$(window).off('resize', $.proxy(this.model.resize, this.model));
this.keepRendering = false;
if (callback) callback();
};