2014-08-09 18:01:17 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-08-12 13:51:31 +00:00
|
|
|
TABS.pid_tuning = {};
|
2014-08-12 14:20:26 +00:00
|
|
|
TABS.pid_tuning.initialize = function (callback) {
|
2014-10-01 10:58:09 +00:00
|
|
|
var self = this;
|
|
|
|
|
2014-10-01 11:16:22 +00:00
|
|
|
if (GUI.active_tab != 'pid_tuning') {
|
|
|
|
GUI.active_tab = 'pid_tuning';
|
|
|
|
googleAnalytics.sendAppView('PID Tuning');
|
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-05-03 20:42:11 +00:00
|
|
|
function get_pid_names() {
|
2014-06-01 12:10:18 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_PIDNAMES, false, false, get_pid_data);
|
2014-05-03 20:42:11 +00:00
|
|
|
}
|
2014-03-30 10:13:17 +00:00
|
|
|
|
|
|
|
function get_pid_data() {
|
2014-06-01 12:10:18 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_PID, false, false, get_rc_tuning_data);
|
2014-03-30 10:13:17 +00:00
|
|
|
}
|
2014-03-22 23:28:41 +00:00
|
|
|
|
|
|
|
function get_rc_tuning_data() {
|
2014-06-01 12:10:18 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_RC_TUNING, false, false, load_html);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function load_html() {
|
|
|
|
$('#content').load("./tabs/pid_tuning.html", process_html);
|
|
|
|
}
|
|
|
|
|
2014-08-14 14:48:16 +00:00
|
|
|
// requesting MSP_STATUS manually because it contains CONFIG.profile
|
|
|
|
MSP.send_message(MSP_codes.MSP_STATUS, false, false, get_pid_names);
|
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
function process_html() {
|
2014-05-06 14:48:46 +00:00
|
|
|
// translate to user-selected language
|
|
|
|
localize();
|
|
|
|
|
2014-05-03 20:54:33 +00:00
|
|
|
// Fill in the names from PID_names array
|
|
|
|
// this needs to be reworked, but will do for now
|
|
|
|
$('.pid_tuning tr:eq(1) td:first').text(PID_names[0]);
|
|
|
|
$('.pid_tuning tr:eq(2) td:first').text(PID_names[1]);
|
|
|
|
$('.pid_tuning tr:eq(3) td:first').text(PID_names[2]);
|
|
|
|
$('.pid_tuning tr:eq(4) td:first').text(PID_names[3]);
|
|
|
|
$('.pid_tuning tr:eq(5) td:first').text(PID_names[9]);
|
|
|
|
$('.pid_tuning tr:eq(6) td:first').text(PID_names[4]);
|
|
|
|
$('.pid_tuning tr:eq(7) td:first').text(PID_names[5]);
|
|
|
|
$('.pid_tuning tr:eq(8) td:first').text(PID_names[6]);
|
|
|
|
$('.pid_tuning tr:eq(9) td:first').text(PID_names[7]);
|
|
|
|
$('.pid_tuning tr:eq(10) td:first').text(PID_names[8]);
|
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
// Fill in the data from PIDs array
|
|
|
|
var i = 0;
|
2014-08-12 14:20:26 +00:00
|
|
|
$('.pid_tuning .ROLL input').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
$(this).val(PIDs[0][i++].toFixed(1));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
$(this).val(PIDs[0][i++].toFixed(3));
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
$(this).val(PIDs[0][i++].toFixed(0));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
i = 0;
|
2014-08-12 14:20:26 +00:00
|
|
|
$('.pid_tuning .PITCH input').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
$(this).val(PIDs[1][i++].toFixed(1));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
$(this).val(PIDs[1][i++].toFixed(3));
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
$(this).val(PIDs[1][i++].toFixed(0));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
i = 0;
|
2014-08-12 14:20:26 +00:00
|
|
|
$('.pid_tuning .YAW input').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
$(this).val(PIDs[2][i++].toFixed(1));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
$(this).val(PIDs[2][i++].toFixed(3));
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
$(this).val(PIDs[2][i++].toFixed(0));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2013-04-08 23:09:11 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
i = 0;
|
2014-08-12 14:20:26 +00:00
|
|
|
$('.pid_tuning .ALT input').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
$(this).val(PIDs[3][i++].toFixed(1));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
$(this).val(PIDs[3][i++].toFixed(3));
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
$(this).val(PIDs[3][i++].toFixed(0));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2013-04-08 23:09:11 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
i = 0;
|
2014-08-12 14:20:26 +00:00
|
|
|
$('.pid_tuning .Pos input').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
$(this).val(PIDs[4][i++].toFixed(2));
|
|
|
|
});
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
i = 0;
|
2014-08-12 14:20:26 +00:00
|
|
|
$('.pid_tuning .PosR input').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
$(this).val(PIDs[5][i++].toFixed(1));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
$(this).val(PIDs[5][i++].toFixed(2));
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
$(this).val(PIDs[5][i++].toFixed(3));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2013-04-08 23:09:11 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
i = 0;
|
2014-08-12 14:20:26 +00:00
|
|
|
$('.pid_tuning .NavR input').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
$(this).val(PIDs[6][i++].toFixed(1));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
$(this).val(PIDs[6][i++].toFixed(2));
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
$(this).val(PIDs[6][i++].toFixed(3));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2013-04-08 23:09:11 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
i = 0;
|
2014-08-12 14:20:26 +00:00
|
|
|
$('.pid_tuning .LEVEL input').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
$(this).val(PIDs[7][i++].toFixed(1));
|
|
|
|
break;
|
|
|
|
case 1:
|
2014-06-09 00:56:38 +00:00
|
|
|
$(this).val(PIDs[7][i++].toFixed(3));
|
2014-03-22 23:28:41 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
$(this).val(PIDs[7][i++].toFixed(0));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2013-04-08 23:09:11 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
i = 0;
|
2014-08-12 14:20:26 +00:00
|
|
|
$('.pid_tuning .MAG input').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
$(this).val(PIDs[8][i++].toFixed(1));
|
|
|
|
});
|
2013-04-08 23:49:49 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
i = 0;
|
2014-08-12 14:20:26 +00:00
|
|
|
$('.pid_tuning .Vario input').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
$(this).val(PIDs[9][i++].toFixed(1));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
$(this).val(PIDs[9][i++].toFixed(3));
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
$(this).val(PIDs[9][i++].toFixed(0));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
// Fill in data from RC_tuning object
|
|
|
|
$('.rate-tpa input[name="roll-pitch"]').val(RC_tuning.roll_pitch_rate.toFixed(2));
|
|
|
|
$('.rate-tpa input[name="yaw"]').val(RC_tuning.yaw_rate.toFixed(2));
|
|
|
|
$('.rate-tpa input[name="tpa"]').val(RC_tuning.dynamic_THR_PID.toFixed(2));
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
// Fill in currently selected profile
|
2014-09-23 19:02:07 +00:00
|
|
|
$('select[name="profile"]').val(CONFIG.profile);
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
// UI Hooks
|
2014-09-23 19:02:07 +00:00
|
|
|
$('select[name="profile"]').change(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
var profile = parseInt($(this).val());
|
2014-09-23 19:02:07 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_SELECT_SETTING, [profile], false, function () {
|
|
|
|
GUI.log(chrome.i18n.getMessage('pidTuningLoadedProfile', [profile + 1]));
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-08-12 14:20:26 +00:00
|
|
|
GUI.tab_switch_cleanup(function () {
|
2014-08-12 13:51:31 +00:00
|
|
|
TABS.pid_tuning.initialize();
|
2014-07-10 16:14:33 +00:00
|
|
|
});
|
2014-03-22 23:28:41 +00:00
|
|
|
});
|
|
|
|
});
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-08-12 14:20:26 +00:00
|
|
|
$('a.refresh').click(function () {
|
|
|
|
GUI.tab_switch_cleanup(function () {
|
2014-05-06 15:34:59 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('pidTuningDataRefreshed'));
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-08-12 13:51:31 +00:00
|
|
|
TABS.pid_tuning.initialize();
|
2014-03-22 23:28:41 +00:00
|
|
|
});
|
|
|
|
});
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-08-12 14:20:26 +00:00
|
|
|
$('a.update').click(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
// Catch all the changes and stuff the inside PIDs array
|
|
|
|
var i = 0;
|
2014-08-12 14:20:26 +00:00
|
|
|
$('table.pid_tuning tr.ROLL input').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
PIDs[0][i++] = parseFloat($(this).val());
|
|
|
|
});
|
|
|
|
|
|
|
|
i = 0;
|
2014-08-12 14:20:26 +00:00
|
|
|
$('table.pid_tuning tr.PITCH input').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
PIDs[1][i++] = parseFloat($(this).val());
|
|
|
|
});
|
|
|
|
|
|
|
|
i = 0;
|
2014-08-12 14:20:26 +00:00
|
|
|
$('table.pid_tuning tr.YAW input').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
PIDs[2][i++] = parseFloat($(this).val());
|
|
|
|
});
|
|
|
|
|
|
|
|
i = 0;
|
2014-08-12 14:20:26 +00:00
|
|
|
$('table.pid_tuning tr.ALT input').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
PIDs[3][i++] = parseFloat($(this).val());
|
|
|
|
});
|
|
|
|
|
|
|
|
i = 0;
|
2014-08-12 14:20:26 +00:00
|
|
|
$('table.pid_tuning tr.Vario input').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
PIDs[9][i++] = parseFloat($(this).val());
|
|
|
|
});
|
2013-06-13 11:11:53 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
i = 0;
|
2014-08-12 14:20:26 +00:00
|
|
|
$('table.pid_tuning tr.Pos input').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
PIDs[4][i++] = parseFloat($(this).val());
|
2014-01-24 16:06:54 +00:00
|
|
|
});
|
2014-03-22 23:28:41 +00:00
|
|
|
|
|
|
|
i = 0;
|
2014-08-12 14:20:26 +00:00
|
|
|
$('table.pid_tuning tr.PosR input').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
PIDs[5][i++] = parseFloat($(this).val());
|
|
|
|
});
|
|
|
|
|
|
|
|
i = 0;
|
2014-08-12 14:20:26 +00:00
|
|
|
$('table.pid_tuning tr.NavR input').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
PIDs[6][i++] = parseFloat($(this).val());
|
|
|
|
});
|
|
|
|
|
|
|
|
i = 0;
|
2014-08-12 14:20:26 +00:00
|
|
|
$('table.pid_tuning tr.LEVEL input').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
PIDs[7][i++] = parseFloat($(this).val());
|
|
|
|
});
|
|
|
|
|
|
|
|
i = 0;
|
2014-08-12 14:20:26 +00:00
|
|
|
$('table.pid_tuning tr.MAG input').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
PIDs[8][i++] = parseFloat($(this).val());
|
|
|
|
});
|
|
|
|
|
2014-09-16 21:07:52 +00:00
|
|
|
// catch RC_tuning changes
|
|
|
|
RC_tuning.roll_pitch_rate = parseFloat($('.rate-tpa input[name="roll-pitch"]').val());
|
|
|
|
RC_tuning.yaw_rate = parseFloat($('.rate-tpa input[name="yaw"]').val());
|
|
|
|
RC_tuning.dynamic_THR_PID = parseFloat($('.rate-tpa input[name="tpa"]').val());
|
2014-03-22 23:28:41 +00:00
|
|
|
|
|
|
|
function send_rc_tuning_changes() {
|
2014-09-17 07:27:54 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_SET_RC_TUNING, MSP.crunch(MSP_codes.MSP_SET_RC_TUNING), false, save_to_eeprom);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function save_to_eeprom() {
|
2014-08-12 14:20:26 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function () {
|
2014-05-06 15:34:59 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('pidTuningEepromSaved'));
|
2014-03-22 23:28:41 +00:00
|
|
|
});
|
|
|
|
}
|
2014-09-16 21:07:52 +00:00
|
|
|
|
2014-09-17 07:27:54 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_SET_PID, MSP.crunch(MSP_codes.MSP_SET_PID), false, send_rc_tuning_changes);
|
2013-12-15 01:28:12 +00:00
|
|
|
});
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2014-03-30 09:51:16 +00:00
|
|
|
// status data pulled via separate timer with static speed
|
2014-10-01 10:58:09 +00:00
|
|
|
GUI.interval_add('status_pull', function status_pull() {
|
2014-06-01 12:10:18 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_STATUS);
|
2014-03-30 09:51:16 +00:00
|
|
|
}, 250, true);
|
2014-07-10 16:14:33 +00:00
|
|
|
|
|
|
|
if (callback) callback();
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
2014-07-10 16:14:33 +00:00
|
|
|
};
|
|
|
|
|
2014-08-12 14:20:26 +00:00
|
|
|
TABS.pid_tuning.cleanup = function (callback) {
|
2014-07-10 16:14:33 +00:00
|
|
|
if (callback) callback();
|
2013-04-08 19:10:47 +00:00
|
|
|
}
|