2014-08-09 18:01:17 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-03-10 23:19:24 +00:00
|
|
|
TABS.pid_tuning = {
|
2016-07-27 13:24:16 +00:00
|
|
|
RATE_PROFILE_MASK: 128,
|
2016-07-26 14:46:13 +00:00
|
|
|
showAllPids: false,
|
2016-07-27 13:24:16 +00:00
|
|
|
updating: true,
|
|
|
|
dirty: false,
|
|
|
|
currentProfile: null,
|
|
|
|
currentRateProfile: null
|
2015-03-10 23:19:24 +00:00
|
|
|
};
|
|
|
|
|
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;
|
2016-07-27 13:24:16 +00:00
|
|
|
|
2016-08-04 14:24:29 +00:00
|
|
|
if (GUI.active_tab !== 'pid_tuning') {
|
2016-07-06 23:55:15 +00:00
|
|
|
GUI.active_tab = 'pid_tuning';
|
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2016-06-24 09:07:12 +00:00
|
|
|
// requesting MSP_STATUS manually because it contains CONFIG.profile
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.promise(MSPCodes.MSP_STATUS).then(function() {
|
2016-07-29 09:37:04 +00:00
|
|
|
if (semver.gte(CONFIG.apiVersion, CONFIGURATOR.pidControllerChangeMinApiVersion)) {
|
2016-08-06 13:31:10 +00:00
|
|
|
return MSP.promise(MSPCodes.MSP_PID_CONTROLLER);
|
2015-01-29 17:27:50 +00:00
|
|
|
}
|
2016-06-24 09:07:12 +00:00
|
|
|
}).then(function() {
|
2016-08-06 13:31:10 +00:00
|
|
|
return MSP.promise(MSPCodes.MSP_PIDNAMES)
|
2016-06-24 09:07:12 +00:00
|
|
|
}).then(function() {
|
2016-08-06 13:31:10 +00:00
|
|
|
return MSP.promise(MSPCodes.MSP_PID);
|
2016-07-30 08:22:14 +00:00
|
|
|
}).then(function () {
|
2016-08-02 19:54:50 +00:00
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, "2.9.0") && semver.lt(CONFIG.flightControllerVersion, "2.9.1")) {
|
2016-08-06 13:31:10 +00:00
|
|
|
return MSP.promise(MSPCodes.MSP_SPECIAL_PARAMETERS);
|
2016-07-30 08:22:14 +00:00
|
|
|
}
|
2016-06-24 09:07:12 +00:00
|
|
|
}).then(function() {
|
2016-07-30 09:39:48 +00:00
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, "2.8.2")) {
|
2016-08-06 13:31:10 +00:00
|
|
|
return MSP.promise(MSPCodes.MSP_PID_ADVANCED);
|
2016-07-30 08:22:14 +00:00
|
|
|
}
|
2016-06-24 09:07:12 +00:00
|
|
|
}).then(function() {
|
2016-08-06 13:31:10 +00:00
|
|
|
return MSP.promise(MSPCodes.MSP_RC_TUNING);
|
2016-06-24 09:07:12 +00:00
|
|
|
}).then(function() {
|
2016-08-06 13:31:10 +00:00
|
|
|
return MSP.promise(MSPCodes.MSP_FILTER_CONFIG);
|
2016-07-06 10:26:11 +00:00
|
|
|
}).then(function() {
|
|
|
|
var promise = true;
|
|
|
|
if (CONFIG.flightControllerIdentifier === "BTFL" && semver.gte(CONFIG.flightControllerVersion, "2.8.0")) {
|
2016-08-06 13:31:10 +00:00
|
|
|
promise = MSP.promise(MSPCodes.MSP_BF_CONFIG);
|
2016-07-06 10:26:11 +00:00
|
|
|
}
|
|
|
|
|
2016-09-07 20:49:54 +00:00
|
|
|
return promise;
|
|
|
|
}).then(function() {
|
|
|
|
var promise = true;
|
|
|
|
if (semver.gte(CONFIG.apiVersion, "1.15.0")) {
|
|
|
|
promise = MSP.promise(MSPCodes.MSP_RC_DEADBAND);
|
|
|
|
}
|
|
|
|
|
2016-07-06 10:26:11 +00:00
|
|
|
return promise;
|
2016-06-24 09:07:12 +00:00
|
|
|
}).then(function() {
|
2014-03-22 23:28:41 +00:00
|
|
|
$('#content').load("./tabs/pid_tuning.html", process_html);
|
2016-06-24 09:07:12 +00:00
|
|
|
});
|
2014-08-14 14:48:16 +00:00
|
|
|
|
2015-03-11 20:24:46 +00:00
|
|
|
function pid_and_rc_to_form() {
|
2016-07-27 13:24:16 +00:00
|
|
|
self.setProfile();
|
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, "3.0.0")) {
|
|
|
|
self.setRateProfile();
|
|
|
|
}
|
|
|
|
|
2015-03-11 20:34:02 +00:00
|
|
|
// Fill in the data from PIDs array
|
2014-03-22 23:28:41 +00:00
|
|
|
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:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[0][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[0][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[0][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
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:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[1][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[1][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[1][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
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:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[2][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[2][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
break;
|
2016-07-12 10:27:28 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
$('.pid_tuning .YAW_JUMP_PREVENTION input').each(function () {
|
|
|
|
switch (i) {
|
2014-03-22 23:28:41 +00:00
|
|
|
case 2:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[2][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
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:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[3][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[3][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[3][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
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 () {
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[4][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
});
|
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:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[5][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[5][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[5][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
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:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[6][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[6][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[6][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2013-04-08 23:09:11 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
i = 0;
|
2016-07-09 17:49:51 +00:00
|
|
|
$('.pid_tuning .ANGLE input').each(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
switch (i) {
|
|
|
|
case 0:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[7][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
break;
|
2016-06-30 12:38:26 +00:00
|
|
|
}
|
|
|
|
});
|
2016-07-09 17:49:51 +00:00
|
|
|
$('.pid_tuning .HORIZON input').each(function () {
|
2016-06-30 12:38:26 +00:00
|
|
|
switch (i) {
|
2016-07-09 17:49:51 +00:00
|
|
|
case 1:
|
|
|
|
$(this).val(PIDs[7][i++]);
|
|
|
|
break;
|
2014-03-22 23:28:41 +00:00
|
|
|
case 2:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[7][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
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 () {
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[8][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
});
|
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:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[9][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[9][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2016-06-17 18:27:10 +00:00
|
|
|
$(this).val(PIDs[9][i++]);
|
2014-03-22 23:28:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
// Fill in data from RC_tuning object
|
2016-06-14 12:20:23 +00:00
|
|
|
$('.pid_tuning input[name="rc_rate"]').val(RC_tuning.RC_RATE.toFixed(2));
|
|
|
|
$('.pid_tuning input[name="roll_pitch_rate"]').val(RC_tuning.roll_pitch_rate.toFixed(2));
|
|
|
|
$('.pid_tuning input[name="roll_rate"]').val(RC_tuning.roll_rate.toFixed(2));
|
|
|
|
$('.pid_tuning input[name="pitch_rate"]').val(RC_tuning.pitch_rate.toFixed(2));
|
|
|
|
$('.pid_tuning input[name="yaw_rate"]').val(RC_tuning.yaw_rate.toFixed(2));
|
|
|
|
$('.pid_tuning input[name="rc_expo"]').val(RC_tuning.RC_EXPO.toFixed(2));
|
|
|
|
$('.pid_tuning input[name="rc_yaw_expo"]').val(RC_tuning.RC_YAW_EXPO.toFixed(2));
|
|
|
|
|
2016-07-26 14:46:13 +00:00
|
|
|
$('.throttle input[name="mid"]').val(RC_tuning.throttle_MID.toFixed(2));
|
|
|
|
$('.throttle input[name="expo"]').val(RC_tuning.throttle_EXPO.toFixed(2));
|
2016-06-28 13:17:33 +00:00
|
|
|
|
2016-06-14 12:20:23 +00:00
|
|
|
$('.tpa input[name="tpa"]').val(RC_tuning.dynamic_THR_PID.toFixed(2));
|
|
|
|
$('.tpa input[name="tpa-breakpoint"]').val(RC_tuning.dynamic_THR_breakpoint);
|
|
|
|
|
|
|
|
if (semver.lt(CONFIG.apiVersion, "1.10.0")) {
|
|
|
|
$('.pid_tuning input[name="rc_yaw_expo"]').hide();
|
|
|
|
$('.pid_tuning input[name="rc_expo"]').attr("rowspan", "3");
|
|
|
|
}
|
2016-06-21 00:16:22 +00:00
|
|
|
|
2016-08-27 00:34:05 +00:00
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, "2.8.1")) {
|
|
|
|
$('input[id="vbatpidcompensation"]').prop('checked', ADVANCED_TUNING.vbatPidCompensation !== 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, "2.8.2")) {
|
|
|
|
$('#pid-tuning .delta select').val(ADVANCED_TUNING.deltaMethod);
|
|
|
|
}
|
|
|
|
|
2016-08-16 12:25:09 +00:00
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, '2.9.0')) {
|
|
|
|
$('.pid_tuning input[name="rc_rate_yaw"]').val(RC_tuning.rcYawRate.toFixed(2));
|
|
|
|
$('.pid_filter input[name="gyroLowpassFrequency"]').val(FILTER_CONFIG.gyro_soft_lpf_hz);
|
|
|
|
$('.pid_filter input[name="dtermLowpassFrequency"]').val(FILTER_CONFIG.dterm_lpf_hz);
|
|
|
|
$('.pid_filter input[name="yawLowpassFrequency"]').val(FILTER_CONFIG.yaw_lpf_hz);
|
|
|
|
} else {
|
|
|
|
$('.tab-pid_tuning .subtab-filter').hide();
|
|
|
|
$('.tab-pid_tuning .tab_container').hide();
|
2016-06-24 12:29:46 +00:00
|
|
|
$('.pid_tuning input[name="rc_rate_yaw"]').hide();
|
|
|
|
}
|
2016-08-16 12:25:09 +00:00
|
|
|
|
2016-09-06 19:51:47 +00:00
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, "3.0.0")
|
|
|
|
|| semver.gte(CONFIG.flightControllerVersion, "2.8.0") && BF_CONFIG.features.isEnabled('SUPEREXPO_RATES')) {
|
|
|
|
$('#pid-tuning .rate').text(chrome.i18n.getMessage("pidTuningSuperRate"));
|
|
|
|
} else {
|
|
|
|
$('#pid-tuning .rate').text(chrome.i18n.getMessage("pidTuningRate"));
|
|
|
|
}
|
|
|
|
|
2016-08-16 12:25:09 +00:00
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, '3.0.0')) {
|
2016-10-11 12:48:03 +00:00
|
|
|
$('.pid_filter input[name="gyroNotch1Frequency"]').val(FILTER_CONFIG.gyro_soft_notch_hz_1);
|
|
|
|
$('.pid_filter input[name="gyroNotch1Cutoff"]').val(FILTER_CONFIG.gyro_soft_notch_cutoff_1);
|
2016-08-16 12:25:09 +00:00
|
|
|
$('.pid_filter input[name="dTermNotchFrequency"]').val(FILTER_CONFIG.dterm_notch_hz);
|
|
|
|
$('.pid_filter input[name="dTermNotchCutoff"]').val(FILTER_CONFIG.dterm_notch_cutoff);
|
2015-03-10 23:19:24 +00:00
|
|
|
|
2016-08-27 00:34:05 +00:00
|
|
|
$('input[name="ptermSetpoint-number"]').val(ADVANCED_TUNING.ptermSetpointWeight / 100);
|
|
|
|
$('input[name="ptermSetpoint-range"]').val(ADVANCED_TUNING.ptermSetpointWeight / 100);
|
2016-08-02 14:26:06 +00:00
|
|
|
|
2016-08-27 00:34:05 +00:00
|
|
|
$('input[name="dtermSetpoint-number"]').val(ADVANCED_TUNING.dtermSetpointWeight / 100);
|
|
|
|
$('input[name="dtermSetpoint-range"]').val(ADVANCED_TUNING.dtermSetpointWeight / 100);
|
|
|
|
} else {
|
|
|
|
$('.pid_filter .newFilter').hide();
|
2016-07-26 14:46:13 +00:00
|
|
|
}
|
2016-10-13 00:05:41 +00:00
|
|
|
|
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, '3.0.1')) {
|
|
|
|
$('.pid_filter input[name="gyroNotch2Frequency"]').val(FILTER_CONFIG.gyro_soft_notch_hz_2);
|
|
|
|
$('.pid_filter input[name="gyroNotch2Cutoff"]').val(FILTER_CONFIG.gyro_soft_notch_cutoff_2);
|
|
|
|
} else {
|
|
|
|
$('.pid_filter .gyroNotch2').hide();
|
|
|
|
}
|
2016-08-27 00:34:05 +00:00
|
|
|
}
|
2016-07-26 14:46:13 +00:00
|
|
|
|
2016-08-27 00:34:05 +00:00
|
|
|
function form_to_pid_and_rc() {
|
2016-07-06 10:26:11 +00:00
|
|
|
// Fill in the data from PIDs array
|
2015-03-11 20:34:02 +00:00
|
|
|
// Catch all the changes and stuff the inside PIDs array
|
2015-03-10 23:19:24 +00:00
|
|
|
var i = 0;
|
2016-07-12 10:27:28 +00:00
|
|
|
$('table.pid_tuning tr.ROLL .pid_data input').each(function () {
|
2015-03-10 23:19:24 +00:00
|
|
|
PIDs[0][i++] = parseFloat($(this).val());
|
|
|
|
});
|
|
|
|
|
|
|
|
i = 0;
|
2016-07-12 10:27:28 +00:00
|
|
|
$('table.pid_tuning tr.PITCH .pid_data input').each(function () {
|
2015-03-10 23:19:24 +00:00
|
|
|
PIDs[1][i++] = parseFloat($(this).val());
|
|
|
|
});
|
|
|
|
|
|
|
|
i = 0;
|
2016-07-12 10:27:28 +00:00
|
|
|
$('table.pid_tuning tr.YAW .pid_data input').each(function () {
|
|
|
|
PIDs[2][i++] = parseFloat($(this).val());
|
|
|
|
});
|
|
|
|
$('table.pid_tuning tr.YAW_JUMP_PREVENTION .pid_data input').each(function () {
|
2015-03-10 23:19:24 +00:00
|
|
|
PIDs[2][i++] = parseFloat($(this).val());
|
|
|
|
});
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
$('table.pid_tuning tr.ALT input').each(function () {
|
|
|
|
PIDs[3][i++] = parseFloat($(this).val());
|
|
|
|
});
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
$('table.pid_tuning tr.Vario input').each(function () {
|
|
|
|
PIDs[9][i++] = parseFloat($(this).val());
|
|
|
|
});
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
$('table.pid_tuning tr.Pos input').each(function () {
|
|
|
|
PIDs[4][i++] = parseFloat($(this).val());
|
|
|
|
});
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
$('table.pid_tuning tr.PosR input').each(function () {
|
|
|
|
PIDs[5][i++] = parseFloat($(this).val());
|
|
|
|
});
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
$('table.pid_tuning tr.NavR input').each(function () {
|
|
|
|
PIDs[6][i++] = parseFloat($(this).val());
|
|
|
|
});
|
|
|
|
|
|
|
|
i = 0;
|
2016-07-09 17:49:51 +00:00
|
|
|
$('table.pid_tuning tr.ANGLE input').each(function () {
|
2016-06-30 12:38:26 +00:00
|
|
|
PIDs[7][i++] = parseFloat($(this).val());
|
|
|
|
});
|
2016-07-09 17:49:51 +00:00
|
|
|
$('table.pid_tuning tr.HORIZON input').each(function () {
|
2015-03-10 23:19:24 +00:00
|
|
|
PIDs[7][i++] = parseFloat($(this).val());
|
|
|
|
});
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
$('table.pid_tuning tr.MAG input').each(function () {
|
|
|
|
PIDs[8][i++] = parseFloat($(this).val());
|
|
|
|
});
|
|
|
|
|
|
|
|
// catch RC_tuning changes
|
2016-06-14 12:20:23 +00:00
|
|
|
RC_tuning.RC_RATE = parseFloat($('.pid_tuning input[name="rc_rate"]').val());
|
|
|
|
RC_tuning.roll_pitch_rate = parseFloat($('.pid_tuning input[name="roll_pitch_rate"]').val());
|
|
|
|
RC_tuning.roll_rate = parseFloat($('.pid_tuning input[name="roll_rate"]').val());
|
|
|
|
RC_tuning.pitch_rate = parseFloat($('.pid_tuning input[name="pitch_rate"]').val());
|
|
|
|
RC_tuning.yaw_rate = parseFloat($('.pid_tuning input[name="yaw_rate"]').val());
|
|
|
|
RC_tuning.RC_EXPO = parseFloat($('.pid_tuning input[name="rc_expo"]').val());
|
|
|
|
RC_tuning.RC_YAW_EXPO = parseFloat($('.pid_tuning input[name="rc_yaw_expo"]').val());
|
2016-07-28 13:47:18 +00:00
|
|
|
RC_tuning.rcYawRate = parseFloat($('.pid_tuning input[name="rc_rate_yaw"]').val());
|
2016-06-14 12:20:23 +00:00
|
|
|
|
2016-06-28 13:17:33 +00:00
|
|
|
RC_tuning.throttle_MID = parseFloat($('.throttle input[name="mid"]').val());
|
|
|
|
RC_tuning.throttle_EXPO = parseFloat($('.throttle input[name="expo"]').val())
|
|
|
|
|
2016-06-14 12:20:23 +00:00
|
|
|
RC_tuning.dynamic_THR_PID = parseFloat($('.tpa input[name="tpa"]').val());
|
|
|
|
RC_tuning.dynamic_THR_breakpoint = parseInt($('.tpa input[name="tpa-breakpoint"]').val());
|
2016-08-16 12:25:09 +00:00
|
|
|
FILTER_CONFIG.gyro_soft_lpf_hz = parseInt($('.pid_filter input[name="gyroLowpassFrequency"]').val());
|
|
|
|
FILTER_CONFIG.dterm_lpf_hz = parseInt($('.pid_filter input[name="dtermLowpassFrequency"]').val());
|
|
|
|
FILTER_CONFIG.yaw_lpf_hz = parseInt($('.pid_filter input[name="yawLowpassFrequency"]').val());
|
|
|
|
|
2016-08-27 00:34:05 +00:00
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, "2.8.0") && !semver.gte(CONFIG.flightControllerVersion, "3.0.0")) {
|
|
|
|
BF_CONFIG.features.updateData($('input[name="SUPEREXPO_RATES"]'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, "2.8.1")) {
|
|
|
|
ADVANCED_TUNING.vbatPidCompensation = $('input[id="vbatpidcompensation"]').is(':checked') ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, "2.8.2")) {
|
|
|
|
ADVANCED_TUNING.deltaMethod = $('#pid-tuning .delta select').val();
|
|
|
|
}
|
|
|
|
|
2016-08-16 12:25:09 +00:00
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, '3.0.0')) {
|
2016-08-27 00:34:05 +00:00
|
|
|
ADVANCED_TUNING.ptermSetpointWeight = parseInt($('input[name="ptermSetpoint-number"]').val() * 100);
|
|
|
|
ADVANCED_TUNING.dtermSetpointWeight = parseInt($('input[name="dtermSetpoint-number"]').val() * 100);
|
|
|
|
|
2016-10-11 12:48:03 +00:00
|
|
|
FILTER_CONFIG.gyro_soft_notch_hz_1 = parseInt($('.pid_filter input[name="gyroNotch1Frequency"]').val());
|
|
|
|
FILTER_CONFIG.gyro_soft_notch_cutoff_1 = parseInt($('.pid_filter input[name="gyroNotch1Cutoff"]').val());
|
2016-08-16 12:25:09 +00:00
|
|
|
FILTER_CONFIG.dterm_notch_hz = parseInt($('.pid_filter input[name="dTermNotchFrequency"]').val());
|
|
|
|
FILTER_CONFIG.dterm_notch_cutoff = parseInt($('.pid_filter input[name="dTermNotchCutoff"]').val());
|
2016-10-11 12:48:03 +00:00
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, '3.0.1')) {
|
|
|
|
FILTER_CONFIG.gyro_soft_notch_hz_2 = parseInt($('.pid_filter input[name="gyroNotch2Frequency"]').val());
|
|
|
|
FILTER_CONFIG.gyro_soft_notch_cutoff_2 = parseInt($('.pid_filter input[name="gyroNotch2Cutoff"]').val());
|
|
|
|
}
|
2016-08-16 12:25:09 +00:00
|
|
|
}
|
2016-08-27 00:34:05 +00:00
|
|
|
|
2015-03-10 23:19:24 +00:00
|
|
|
}
|
2016-06-30 12:38:26 +00:00
|
|
|
|
2016-06-30 21:05:18 +00:00
|
|
|
function showAllPids() {
|
|
|
|
$('.tab-pid_tuning .pid_tuning').show();
|
|
|
|
}
|
|
|
|
|
|
|
|
function hideUnusedPids() {
|
2016-06-30 12:38:26 +00:00
|
|
|
$('.tab-pid_tuning .pid_tuning').hide();
|
|
|
|
|
|
|
|
$('#pid_main').show();
|
|
|
|
|
2016-06-30 21:05:18 +00:00
|
|
|
if (have_sensor(CONFIG.activeSensors, 'acc')) {
|
2016-06-30 12:38:26 +00:00
|
|
|
$('#pid_accel').show();
|
2016-07-04 07:37:26 +00:00
|
|
|
$('#pid_level').show();
|
2016-06-30 12:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var showTitle = false;
|
2016-06-30 21:05:18 +00:00
|
|
|
if (have_sensor(CONFIG.activeSensors, 'baro') ||
|
|
|
|
have_sensor(CONFIG.activeSensors, 'sonar')) {
|
2016-06-30 12:38:26 +00:00
|
|
|
$('#pid_baro').show();
|
2016-06-30 21:05:18 +00:00
|
|
|
showTitle = true;
|
2016-06-30 12:38:26 +00:00
|
|
|
}
|
2016-06-30 21:05:18 +00:00
|
|
|
if (have_sensor(CONFIG.activeSensors, 'mag')) {
|
2016-06-30 12:38:26 +00:00
|
|
|
$('#pid_mag').show();
|
2016-06-30 21:05:18 +00:00
|
|
|
showTitle = true;
|
2016-06-30 12:38:26 +00:00
|
|
|
}
|
2016-07-24 11:09:51 +00:00
|
|
|
if (BF_CONFIG.features.isEnabled('GPS')) {
|
2016-06-30 12:38:26 +00:00
|
|
|
$('#pid_gps').show();
|
2016-06-30 21:05:18 +00:00
|
|
|
showTitle = true;
|
2016-06-30 12:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (showTitle) {
|
|
|
|
$('#pid_optional').show();
|
|
|
|
}
|
2015-11-02 09:10:08 +00:00
|
|
|
}
|
2016-06-30 12:38:26 +00:00
|
|
|
|
2016-09-17 07:03:00 +00:00
|
|
|
function drawAxes(curveContext, width, height) {
|
2016-07-03 15:02:15 +00:00
|
|
|
curveContext.strokeStyle = '#000000';
|
2016-07-05 11:30:19 +00:00
|
|
|
curveContext.lineWidth = 4;
|
2016-07-03 15:02:15 +00:00
|
|
|
|
|
|
|
// Horizontal
|
|
|
|
curveContext.beginPath();
|
|
|
|
curveContext.moveTo(0, height / 2);
|
|
|
|
curveContext.lineTo(width, height / 2);
|
|
|
|
curveContext.stroke();
|
|
|
|
|
|
|
|
// Vertical
|
|
|
|
curveContext.beginPath();
|
|
|
|
curveContext.moveTo(width / 2, 0);
|
|
|
|
curveContext.lineTo(width / 2, height);
|
|
|
|
curveContext.stroke();
|
|
|
|
|
2016-09-17 07:03:00 +00:00
|
|
|
}
|
2016-07-03 15:02:15 +00:00
|
|
|
|
|
|
|
|
2016-07-05 11:30:19 +00:00
|
|
|
function checkInput(element) {
|
|
|
|
var value = parseFloat(element.val());
|
|
|
|
if (value < parseFloat(element.prop('min'))
|
|
|
|
|| value > parseFloat(element.prop('max'))) {
|
|
|
|
value = undefined;
|
2016-07-03 15:02:15 +00:00
|
|
|
}
|
2016-07-05 11:30:19 +00:00
|
|
|
|
|
|
|
return value;
|
2016-07-03 15:02:15 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 12:12:09 +00:00
|
|
|
var useLegacyCurve = false;
|
2016-09-09 03:48:36 +00:00
|
|
|
if (!semver.gte(CONFIG.flightControllerVersion, "2.8.0")) {
|
2016-07-07 12:12:09 +00:00
|
|
|
useLegacyCurve = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.rateCurve = new RateCurve(useLegacyCurve);
|
|
|
|
|
2016-09-07 20:49:54 +00:00
|
|
|
function printMaxAngularVel(rate, rcRate, rcExpo, useSuperExpo, deadband, maxAngularVelElement) {
|
|
|
|
var maxAngularVel = self.rateCurve.getMaxAngularVel(rate, rcRate, rcExpo, useSuperExpo, deadband).toFixed(0);
|
2016-07-07 12:12:09 +00:00
|
|
|
maxAngularVelElement.text(maxAngularVel);
|
|
|
|
|
|
|
|
return maxAngularVel;
|
|
|
|
}
|
|
|
|
|
2016-09-07 20:49:54 +00:00
|
|
|
function drawCurve(rate, rcRate, rcExpo, useSuperExpo, maxAngularVel, deadband, colour, yOffset, context) {
|
2016-07-07 12:12:09 +00:00
|
|
|
context.save();
|
|
|
|
context.strokeStyle = colour;
|
|
|
|
context.translate(0, yOffset);
|
2016-09-07 20:49:54 +00:00
|
|
|
self.rateCurve.draw(rate, rcRate, rcExpo, useSuperExpo, maxAngularVel, deadband, context);
|
2016-07-07 12:12:09 +00:00
|
|
|
context.restore();
|
|
|
|
}
|
|
|
|
|
2015-03-10 23:19:24 +00:00
|
|
|
function process_html() {
|
2016-09-09 03:48:36 +00:00
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, "2.8.0") && !semver.gte(CONFIG.flightControllerVersion, "3.0.0")) {
|
2016-07-27 01:14:00 +00:00
|
|
|
BF_CONFIG.features.generateElements($('.tab-pid_tuning .features'));
|
2016-09-09 03:48:36 +00:00
|
|
|
} else {
|
|
|
|
$('.tab-pid_tuning .pidTuningFeatures').hide();
|
2016-07-24 11:09:51 +00:00
|
|
|
}
|
|
|
|
|
2015-03-10 23:19:24 +00:00
|
|
|
// translate to user-selected language
|
|
|
|
localize();
|
|
|
|
|
2016-07-06 22:13:07 +00:00
|
|
|
// Local cache of current rates
|
|
|
|
self.currentRates = {
|
2016-07-07 21:21:32 +00:00
|
|
|
roll_rate: RC_tuning.roll_rate,
|
|
|
|
pitch_rate: RC_tuning.pitch_rate,
|
|
|
|
yaw_rate: RC_tuning.yaw_rate,
|
|
|
|
rc_rate: RC_tuning.RC_RATE,
|
2016-07-28 13:47:18 +00:00
|
|
|
rc_rate_yaw: RC_tuning.rcYawRate,
|
2016-07-07 21:21:32 +00:00
|
|
|
rc_expo: RC_tuning.RC_EXPO,
|
|
|
|
rc_yaw_expo: RC_tuning.RC_YAW_EXPO,
|
2016-09-07 20:49:54 +00:00
|
|
|
superexpo: BF_CONFIG.features.isEnabled('SUPEREXPO_RATES'),
|
|
|
|
deadband: RC_deadband.deadband,
|
|
|
|
yawDeadband: RC_deadband.yaw_deadband
|
2016-07-06 22:13:07 +00:00
|
|
|
};
|
|
|
|
|
2016-07-07 12:12:09 +00:00
|
|
|
if (semver.lt(CONFIG.apiVersion, "1.7.0")) {
|
2016-07-07 21:21:32 +00:00
|
|
|
self.currentRates.roll_rate = RC_tuning.roll_pitch_rate;
|
|
|
|
self.currentRates.pitch_rate = RC_tuning.roll_pitch_rate;
|
2016-06-30 21:05:18 +00:00
|
|
|
}
|
2015-11-02 09:10:08 +00:00
|
|
|
|
2016-08-27 00:34:05 +00:00
|
|
|
if (semver.lt(CONFIG.flightControllerVersion, "2.8.1")) {
|
|
|
|
self.currentRates.rc_rate_yaw = self.currentRates.rc_rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, "3.0.0")) {
|
|
|
|
self.currentRates.superexpo = true;
|
|
|
|
}
|
|
|
|
|
2016-08-16 12:25:09 +00:00
|
|
|
$('.tab-pid_tuning .tab_container .pid').on('click', function () {
|
|
|
|
$('.tab-pid_tuning .subtab-pid').show();
|
|
|
|
$('.tab-pid_tuning .subtab-filter').hide();
|
|
|
|
|
|
|
|
$('.tab-pid_tuning .tab_container td').removeClass('active');
|
|
|
|
$(this).addClass('active');
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.tab-pid_tuning .tab_container .filter').on('click', function () {
|
|
|
|
$('.tab-pid_tuning .subtab-filter').show();
|
|
|
|
$('.tab-pid_tuning .subtab-pid').hide();
|
|
|
|
|
|
|
|
$('.tab-pid_tuning .tab_container td').removeClass('active');
|
|
|
|
$(this).addClass('active');
|
|
|
|
});
|
|
|
|
|
2016-07-17 00:18:19 +00:00
|
|
|
var showAllButton = $('#showAllPids');
|
|
|
|
|
|
|
|
function updatePidDisplay() {
|
2016-07-27 13:24:16 +00:00
|
|
|
if (!self.showAllPids) {
|
2016-07-17 00:18:19 +00:00
|
|
|
hideUnusedPids();
|
|
|
|
|
|
|
|
showAllButton.text(chrome.i18n.getMessage("pidTuningShowAllPids"));
|
|
|
|
} else {
|
|
|
|
showAllPids();
|
|
|
|
|
|
|
|
showAllButton.text(chrome.i18n.getMessage("pidTuningHideUnusedPids"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-30 22:51:47 +00:00
|
|
|
updatePidDisplay();
|
2016-06-30 21:05:18 +00:00
|
|
|
|
2016-06-30 22:51:47 +00:00
|
|
|
showAllButton.on('click', function(){
|
2016-07-27 13:24:16 +00:00
|
|
|
self.showAllPids = !self.showAllPids;
|
2016-06-30 21:05:18 +00:00
|
|
|
|
2016-06-30 22:51:47 +00:00
|
|
|
updatePidDisplay();
|
2015-11-02 09:10:08 +00:00
|
|
|
});
|
|
|
|
|
2016-07-27 13:24:16 +00:00
|
|
|
$('#resetProfile').on('click', function(){
|
|
|
|
self.updating = true;
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.promise(MSPCodes.MSP_SET_RESET_CURR_PID).then(function () {
|
2016-07-27 13:24:16 +00:00
|
|
|
self.refresh(function () {
|
|
|
|
self.updating = false;
|
2015-12-12 23:42:49 +00:00
|
|
|
|
2016-07-27 13:24:16 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('pidTuningProfileReset'));
|
2016-07-26 14:46:13 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-07-25 12:49:59 +00:00
|
|
|
|
2016-07-27 13:24:16 +00:00
|
|
|
$('.tab-pid_tuning select[name="profile"]').change(function () {
|
|
|
|
self.currentProfile = parseInt($(this).val());
|
|
|
|
self.updating = true;
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.promise(MSPCodes.MSP_SELECT_SETTING, [self.currentProfile]).then(function () {
|
2016-07-27 13:24:16 +00:00
|
|
|
self.refresh(function () {
|
|
|
|
self.updating = false;
|
2016-07-26 14:46:13 +00:00
|
|
|
|
2016-07-27 13:24:16 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('pidTuningLoadedProfile', [self.currentProfile + 1]));
|
2016-07-26 14:46:13 +00:00
|
|
|
});
|
2016-07-25 12:49:59 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-07-27 13:24:16 +00:00
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, "3.0.0")) {
|
|
|
|
$('.tab-pid_tuning select[name="rate_profile"]').change(function () {
|
|
|
|
self.currentRateProfile = parseInt($(this).val());
|
|
|
|
self.updating = true;
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.promise(MSPCodes.MSP_SELECT_SETTING, [self.currentRateProfile + self.RATE_PROFILE_MASK]).then(function () {
|
2016-07-27 13:24:16 +00:00
|
|
|
self.refresh(function () {
|
|
|
|
self.updating = false;
|
|
|
|
|
|
|
|
GUI.log(chrome.i18n.getMessage('pidTuningLoadedRateProfile', [self.currentRateProfile + 1]));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-08-02 14:26:06 +00:00
|
|
|
|
|
|
|
var ptermNumberElement = $('input[name="ptermSetpoint-number"]');
|
|
|
|
var ptermRangeElement = $('input[name="ptermSetpoint-range"]');
|
|
|
|
ptermNumberElement.change(function () {
|
|
|
|
ptermRangeElement.val($(this).val());
|
|
|
|
});
|
|
|
|
ptermRangeElement.change(function () {
|
|
|
|
ptermNumberElement.val($(this).val());
|
|
|
|
});
|
|
|
|
|
|
|
|
var dtermNumberElement = $('input[name="dtermSetpoint-number"]');
|
|
|
|
var dtermRangeElement = $('input[name="dtermSetpoint-range"]');
|
|
|
|
dtermNumberElement.change(function () {
|
|
|
|
dtermRangeElement.val($(this).val());
|
|
|
|
});
|
|
|
|
dtermRangeElement.change(function () {
|
|
|
|
dtermNumberElement.val($(this).val());
|
|
|
|
});
|
2016-07-27 13:24:16 +00:00
|
|
|
} else {
|
|
|
|
$('.tab-pid_tuning .rate_profile').hide();
|
2016-08-02 14:26:06 +00:00
|
|
|
|
2016-08-05 09:05:13 +00:00
|
|
|
$('#pid-tuning .ptermSetpoint').hide();
|
|
|
|
$('#pid-tuning .dtermSetpoint').hide();
|
2016-07-27 13:24:16 +00:00
|
|
|
}
|
2016-08-05 10:43:20 +00:00
|
|
|
|
2016-08-02 14:26:06 +00:00
|
|
|
if (!semver.gte(CONFIG.flightControllerVersion, "2.8.2")) {
|
|
|
|
$('#pid-tuning .delta').hide();
|
|
|
|
$('.tab-pid_tuning .note').hide();
|
|
|
|
}
|
|
|
|
|
2015-11-02 09:10:08 +00:00
|
|
|
$('.pid_tuning tr').each(function(){
|
|
|
|
for(i = 0; i < PID_names.length; i++) {
|
|
|
|
if($(this).hasClass(PID_names[i])) {
|
|
|
|
$(this).find('td:first').text(PID_names[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-03-11 20:24:46 +00:00
|
|
|
pid_and_rc_to_form();
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2015-01-29 17:27:50 +00:00
|
|
|
var pidController_e = $('select[name="controller"]');
|
2015-11-14 00:41:23 +00:00
|
|
|
|
|
|
|
var pidControllerList;
|
|
|
|
|
|
|
|
if (semver.lt(CONFIG.apiVersion, "1.14.0")) {
|
|
|
|
pidControllerList = [
|
|
|
|
{ name: "MultiWii (Old)"},
|
|
|
|
{ name: "MultiWii (rewrite)"},
|
|
|
|
{ name: "LuxFloat"},
|
|
|
|
{ name: "MultiWii (2.3 - latest)"},
|
|
|
|
{ name: "MultiWii (2.3 - hybrid)"},
|
|
|
|
{ name: "Harakiri"}
|
|
|
|
]
|
2016-07-17 22:50:50 +00:00
|
|
|
} else if (semver.gte(CONFIG.flightControllerVersion, "3.0.0")) {
|
|
|
|
pidControllerList = [
|
|
|
|
{ name: "Legacy"},
|
|
|
|
{ name: "Betaflight"},
|
|
|
|
]
|
2015-11-14 00:41:23 +00:00
|
|
|
} else {
|
|
|
|
pidControllerList = [
|
2016-06-19 21:50:14 +00:00
|
|
|
{ name: ""},
|
|
|
|
{ name: "Integer"},
|
|
|
|
{ name: "Float"},
|
2015-11-14 00:41:23 +00:00
|
|
|
]
|
|
|
|
}
|
2016-06-29 20:59:47 +00:00
|
|
|
|
2015-11-14 00:41:23 +00:00
|
|
|
for (var i = 0; i < pidControllerList.length; i++) {
|
|
|
|
pidController_e.append('<option value="' + (i) + '">' + pidControllerList[i].name + '</option>');
|
|
|
|
}
|
2016-06-29 20:59:47 +00:00
|
|
|
|
2016-07-26 14:46:13 +00:00
|
|
|
if (semver.gte(CONFIG.apiVersion, CONFIGURATOR.pidControllerChangeMinApiVersion)) {
|
2015-01-29 17:27:50 +00:00
|
|
|
pidController_e.val(PID.controller);
|
2016-08-02 14:26:06 +00:00
|
|
|
|
|
|
|
self.updatePidControllerParameters();
|
2015-01-29 17:27:50 +00:00
|
|
|
} else {
|
|
|
|
GUI.log(chrome.i18n.getMessage('pidTuningUpgradeFirmwareToChangePidController', [CONFIG.apiVersion, CONFIGURATOR.pidControllerChangeMinApiVersion]));
|
2015-03-10 23:19:24 +00:00
|
|
|
|
2015-01-29 17:27:50 +00:00
|
|
|
pidController_e.empty();
|
|
|
|
pidController_e.append('<option value="">Unknown</option>');
|
2015-03-10 23:19:24 +00:00
|
|
|
|
2015-01-29 17:27:50 +00:00
|
|
|
pidController_e.prop('disabled', true);
|
|
|
|
}
|
2015-11-02 09:10:08 +00:00
|
|
|
|
2015-05-07 21:10:26 +00:00
|
|
|
if (semver.lt(CONFIG.apiVersion, "1.7.0")) {
|
2016-06-14 12:20:23 +00:00
|
|
|
$('.tpa .tpa-breakpoint').hide();
|
|
|
|
|
|
|
|
$('.pid_tuning .roll_rate').hide();
|
|
|
|
$('.pid_tuning .pitch_rate').hide();
|
2015-03-11 21:56:02 +00:00
|
|
|
} else {
|
2016-06-14 12:20:23 +00:00
|
|
|
$('.pid_tuning .roll_pitch_rate').hide();
|
|
|
|
}
|
|
|
|
|
2016-07-07 12:12:09 +00:00
|
|
|
if (useLegacyCurve) {
|
|
|
|
$('.new_rates').hide();
|
2016-07-03 15:02:15 +00:00
|
|
|
}
|
2016-06-14 12:20:23 +00:00
|
|
|
|
2016-07-07 12:12:09 +00:00
|
|
|
// Getting the DOM elements for curve display
|
2016-09-18 13:14:54 +00:00
|
|
|
var rcCurveElement = $('.rate_curve canvas#rate_curve_layer0').get(0),
|
2016-09-17 07:03:00 +00:00
|
|
|
curveContext = rcCurveElement.getContext("2d"),
|
|
|
|
updateNeeded = true,
|
|
|
|
maxAngularVel;
|
|
|
|
|
2016-09-18 13:14:54 +00:00
|
|
|
// make these variables global scope so that they can be accessed by the updateRates function.
|
|
|
|
self.maxAngularVelRollElement = $('.pid_tuning .maxAngularVelRoll');
|
|
|
|
self.maxAngularVelPitchElement = $('.pid_tuning .maxAngularVelPitch');
|
|
|
|
self.maxAngularVelYawElement = $('.pid_tuning .maxAngularVelYaw');
|
|
|
|
|
2016-07-03 15:02:15 +00:00
|
|
|
rcCurveElement.width = 1000;
|
|
|
|
rcCurveElement.height = 1000;
|
|
|
|
|
2016-09-17 07:03:00 +00:00
|
|
|
function updateRates (event) {
|
2016-06-14 12:20:23 +00:00
|
|
|
setTimeout(function () { // let global validation trigger and adjust the values first
|
2016-09-17 07:03:00 +00:00
|
|
|
if(event) { // if an event is passed, then use it
|
|
|
|
var targetElement = $(event.target),
|
|
|
|
targetValue = checkInput(targetElement);
|
2016-07-06 23:55:15 +00:00
|
|
|
|
2016-09-17 07:03:00 +00:00
|
|
|
if (self.currentRates.hasOwnProperty(targetElement.attr('name')) && targetValue !== undefined) {
|
|
|
|
self.currentRates[targetElement.attr('name')] = targetValue;
|
2016-07-07 21:21:32 +00:00
|
|
|
|
2016-09-17 07:03:00 +00:00
|
|
|
updateNeeded = true;
|
|
|
|
}
|
2016-07-06 23:55:15 +00:00
|
|
|
|
2016-09-17 07:03:00 +00:00
|
|
|
if (targetElement.attr('name') === 'rc_rate' && semver.lt(CONFIG.flightControllerVersion, "2.8.1")) {
|
|
|
|
self.currentRates.rc_rate_yaw = targetValue;
|
|
|
|
}
|
2016-07-07 12:12:09 +00:00
|
|
|
|
2016-09-17 07:03:00 +00:00
|
|
|
if (targetElement.attr('name') === 'roll_pitch_rate' && semver.lt(CONFIG.apiVersion, "1.7.0")) {
|
|
|
|
self.currentRates.roll_rate = targetValue;
|
|
|
|
self.currentRates.pitch_rate = targetValue;
|
2016-07-07 21:21:32 +00:00
|
|
|
|
2016-09-17 07:03:00 +00:00
|
|
|
updateNeeded = true;
|
|
|
|
}
|
2016-07-07 12:12:09 +00:00
|
|
|
|
2016-09-17 07:03:00 +00:00
|
|
|
if (targetElement.attr('name') === 'SUPEREXPO_RATES') {
|
|
|
|
self.currentRates.superexpo = targetElement.is(':checked');
|
2016-07-07 21:21:32 +00:00
|
|
|
|
2016-09-17 07:03:00 +00:00
|
|
|
updateNeeded = true;
|
|
|
|
}
|
|
|
|
} else { // no event was passed, just force a graph update
|
2016-07-07 21:21:32 +00:00
|
|
|
updateNeeded = true;
|
2016-07-24 11:09:51 +00:00
|
|
|
}
|
2016-07-07 21:21:32 +00:00
|
|
|
if (updateNeeded) {
|
|
|
|
var curveHeight = rcCurveElement.height;
|
|
|
|
var curveWidth = rcCurveElement.width;
|
2016-09-18 13:14:54 +00:00
|
|
|
var lineScale = curveContext.canvas.width / curveContext.canvas.clientWidth;
|
2016-07-06 22:13:07 +00:00
|
|
|
|
2016-07-07 21:21:32 +00:00
|
|
|
curveContext.clearRect(0, 0, curveWidth, curveHeight);
|
2016-07-03 15:02:15 +00:00
|
|
|
|
2016-07-07 21:21:32 +00:00
|
|
|
if (!useLegacyCurve) {
|
2016-09-07 20:49:54 +00:00
|
|
|
maxAngularVel = Math.max(
|
2016-09-18 13:14:54 +00:00
|
|
|
printMaxAngularVel(self.currentRates.roll_rate, self.currentRates.rc_rate, self.currentRates.rc_expo, self.currentRates.superexpo, self.currentRates.deadband, self.maxAngularVelRollElement),
|
|
|
|
printMaxAngularVel(self.currentRates.pitch_rate, self.currentRates.rc_rate, self.currentRates.rc_expo, self.currentRates.superexpo, self.currentRates.deadband, self.maxAngularVelPitchElement),
|
|
|
|
printMaxAngularVel(self.currentRates.yaw_rate, self.currentRates.rc_rate_yaw, self.currentRates.rc_yaw_expo, self.currentRates.superexpo, self.currentRates.yawDeadband, self.maxAngularVelYawElement));
|
2016-09-07 20:49:54 +00:00
|
|
|
|
2016-09-14 11:55:03 +00:00
|
|
|
// make maxAngularVel multiple of 200deg/s so that the auto-scale doesn't keep changing for small changes of the maximum curve
|
2016-09-18 13:14:54 +00:00
|
|
|
maxAngularVel = self.rateCurve.setMaxAngularVel(maxAngularVel);
|
2016-09-14 11:55:03 +00:00
|
|
|
|
2016-09-17 07:03:00 +00:00
|
|
|
drawAxes(curveContext, curveWidth, curveHeight);
|
|
|
|
|
2016-09-07 20:49:54 +00:00
|
|
|
} else {
|
|
|
|
maxAngularVel = 0;
|
2016-07-07 21:21:32 +00:00
|
|
|
}
|
|
|
|
|
2016-09-17 07:03:00 +00:00
|
|
|
curveContext.lineWidth = 2 * lineScale;
|
2016-09-07 20:49:54 +00:00
|
|
|
drawCurve(self.currentRates.roll_rate, self.currentRates.rc_rate, self.currentRates.rc_expo, self.currentRates.superexpo, self.currentRates.deadband, maxAngularVel, '#ff0000', 0, curveContext);
|
|
|
|
drawCurve(self.currentRates.pitch_rate, self.currentRates.rc_rate, self.currentRates.rc_expo, self.currentRates.superexpo, self.currentRates.deadband, maxAngularVel, '#00ff00', -4, curveContext);
|
|
|
|
drawCurve(self.currentRates.yaw_rate, self.currentRates.rc_rate_yaw, self.currentRates.rc_yaw_expo, self.currentRates.superexpo, self.currentRates.yawDeadband, maxAngularVel, '#0000ff', 4, curveContext);
|
2016-07-07 12:12:09 +00:00
|
|
|
|
2016-09-17 07:03:00 +00:00
|
|
|
self.updateRatesLabels();
|
2016-09-14 11:55:03 +00:00
|
|
|
|
2016-07-07 21:21:32 +00:00
|
|
|
updateNeeded = false;
|
|
|
|
}
|
2016-06-28 13:17:33 +00:00
|
|
|
}, 0);
|
2016-07-03 15:02:15 +00:00
|
|
|
};
|
|
|
|
|
2016-07-07 12:12:09 +00:00
|
|
|
// UI Hooks
|
|
|
|
// curves
|
2016-08-27 00:34:05 +00:00
|
|
|
$('input.feature').on('input change', updateRates);
|
|
|
|
$('.pid_tuning').on('input change', updateRates).trigger('input');
|
2016-06-28 13:17:33 +00:00
|
|
|
|
|
|
|
$('.throttle input').on('input change', function () {
|
2016-07-03 15:02:15 +00:00
|
|
|
setTimeout(function () { // let global validation trigger and adjust the values first
|
2016-06-28 13:17:33 +00:00
|
|
|
var throttleMidE = $('.throttle input[name="mid"]'),
|
|
|
|
throttleExpoE = $('.throttle input[name="expo"]'),
|
|
|
|
mid = parseFloat(throttleMidE.val()),
|
|
|
|
expo = parseFloat(throttleExpoE.val()),
|
|
|
|
throttleCurve = $('.throttle .throttle_curve canvas').get(0),
|
|
|
|
context = throttleCurve.getContext("2d");
|
|
|
|
|
|
|
|
// local validation to deal with input event
|
|
|
|
if (mid >= parseFloat(throttleMidE.prop('min')) &&
|
|
|
|
mid <= parseFloat(throttleMidE.prop('max')) &&
|
|
|
|
expo >= parseFloat(throttleExpoE.prop('min')) &&
|
|
|
|
expo <= parseFloat(throttleExpoE.prop('max'))) {
|
|
|
|
// continue
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var canvasHeight = throttleCurve.height;
|
|
|
|
var canvasWidth = throttleCurve.width;
|
|
|
|
|
|
|
|
// math magic by englishman
|
|
|
|
var midx = canvasWidth * mid,
|
|
|
|
midxl = midx * 0.5,
|
|
|
|
midxr = (((canvasWidth - midx) * 0.5) + midx),
|
|
|
|
midy = canvasHeight - (midx * (canvasHeight / canvasWidth)),
|
|
|
|
midyl = canvasHeight - ((canvasHeight - midy) * 0.5 *(expo + 1)),
|
|
|
|
midyr = (midy / 2) * (expo + 1);
|
|
|
|
|
|
|
|
// draw
|
|
|
|
context.clearRect(0, 0, canvasWidth, canvasHeight);
|
|
|
|
context.beginPath();
|
|
|
|
context.moveTo(0, canvasHeight);
|
|
|
|
context.quadraticCurveTo(midxl, midyl, midx, midy);
|
|
|
|
context.moveTo(midx, midy);
|
|
|
|
context.quadraticCurveTo(midxr, midyr, canvasWidth, 0);
|
|
|
|
context.lineWidth = 2;
|
|
|
|
context.strokeStyle = '#ffbb00';
|
|
|
|
context.stroke();
|
2016-06-14 12:20:23 +00:00
|
|
|
}, 0);
|
|
|
|
}).trigger('input');
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-08-12 14:20:26 +00:00
|
|
|
$('a.refresh').click(function () {
|
2016-07-27 13:24:16 +00:00
|
|
|
self.refresh(function () {
|
2014-05-06 15:34:59 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('pidTuningDataRefreshed'));
|
2014-03-22 23:28:41 +00:00
|
|
|
});
|
|
|
|
});
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2016-07-26 14:46:13 +00:00
|
|
|
$('#pid-tuning').find('input').each(function (k, item) {
|
2016-08-02 14:26:06 +00:00
|
|
|
if ($(item).attr('class') !== "feature toggle"
|
|
|
|
&& $(item).attr('class') !== "nonProfile") {
|
|
|
|
$(item).change(function () {
|
|
|
|
self.setDirty(true);
|
|
|
|
});
|
|
|
|
}
|
2015-03-10 23:19:24 +00:00
|
|
|
});
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2016-08-05 22:06:47 +00:00
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, "2.8.2")) {
|
|
|
|
$('#pid-tuning .delta select').change(function() {
|
|
|
|
self.setDirty(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-03-10 23:19:24 +00:00
|
|
|
pidController_e.change(function () {
|
2016-07-27 13:24:16 +00:00
|
|
|
self.setDirty(true);
|
2016-08-02 14:26:06 +00:00
|
|
|
|
|
|
|
self.updatePidControllerParameters();
|
2015-03-10 23:19:24 +00:00
|
|
|
});
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2015-03-10 23:19:24 +00:00
|
|
|
// update == save.
|
|
|
|
$('a.update').click(function () {
|
|
|
|
form_to_pid_and_rc();
|
2016-07-06 10:26:11 +00:00
|
|
|
|
2016-07-27 13:24:16 +00:00
|
|
|
self.updating = true;
|
2016-07-30 07:52:29 +00:00
|
|
|
Promise.resolve(true)
|
|
|
|
.then(function () {
|
2016-07-30 07:40:25 +00:00
|
|
|
var promise;
|
|
|
|
if (semver.gte(CONFIG.apiVersion, CONFIGURATOR.pidControllerChangeMinApiVersion)) {
|
|
|
|
PID.controller = pidController_e.val();
|
2016-08-06 13:31:10 +00:00
|
|
|
promise = MSP.promise(MSPCodes.MSP_SET_PID_CONTROLLER, mspHelper.crunch(MSPCodes.MSP_SET_PID_CONTROLLER));
|
2016-07-30 07:40:25 +00:00
|
|
|
}
|
|
|
|
return promise;
|
|
|
|
}).then(function () {
|
2016-08-06 13:31:10 +00:00
|
|
|
return MSP.promise(MSPCodes.MSP_SET_PID, mspHelper.crunch(MSPCodes.MSP_SET_PID));
|
2016-07-26 14:46:13 +00:00
|
|
|
}).then(function () {
|
2016-07-30 17:24:35 +00:00
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, "2.9.0") && semver.lt(CONFIG.flightControllerVersion, "3.0.0")) {
|
2016-08-06 13:31:10 +00:00
|
|
|
return MSP.promise(MSPCodes.MSP_SET_SPECIAL_PARAMETERS, mspHelper.crunch(MSPCodes.MSP_SET_SPECIAL_PARAMETERS));
|
2016-07-30 08:15:46 +00:00
|
|
|
}
|
|
|
|
}).then(function () {
|
2016-07-30 17:24:35 +00:00
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, "2.8.2")) {
|
2016-08-06 13:31:10 +00:00
|
|
|
return MSP.promise(MSPCodes.MSP_SET_PID_ADVANCED, mspHelper.crunch(MSPCodes.MSP_SET_PID_ADVANCED));
|
2016-07-30 08:15:46 +00:00
|
|
|
}
|
2016-07-26 14:46:13 +00:00
|
|
|
}).then(function () {
|
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, "2.8.1")) {
|
2016-08-06 13:31:10 +00:00
|
|
|
return MSP.promise(MSPCodes.MSP_SET_FILTER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_FILTER_CONFIG));
|
2016-07-26 14:46:13 +00:00
|
|
|
}
|
|
|
|
}).then(function () {
|
2016-08-06 13:31:10 +00:00
|
|
|
return MSP.promise(MSPCodes.MSP_SET_RC_TUNING, mspHelper.crunch(MSPCodes.MSP_SET_RC_TUNING));
|
2016-07-26 14:46:13 +00:00
|
|
|
}).then(function () {
|
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, "2.8.0")) {
|
2016-08-06 13:31:10 +00:00
|
|
|
return MSP.promise(MSPCodes.MSP_SET_BF_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_BF_CONFIG));
|
2016-07-26 14:46:13 +00:00
|
|
|
}
|
|
|
|
}).then(function () {
|
2016-08-06 13:31:10 +00:00
|
|
|
return MSP.promise(MSPCodes.MSP_EEPROM_WRITE);
|
2016-07-26 14:46:13 +00:00
|
|
|
}).then(function () {
|
2016-07-27 13:24:16 +00:00
|
|
|
self.updating = false;
|
|
|
|
self.setDirty(false);
|
|
|
|
|
2016-07-26 14:46:13 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('pidTuningEepromSaved'));
|
|
|
|
});
|
2013-12-15 01:28:12 +00:00
|
|
|
});
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2016-06-29 20:59:47 +00:00
|
|
|
// Setup model for rates preview
|
|
|
|
self.initRatesPreview();
|
|
|
|
self.renderModel();
|
|
|
|
|
2016-07-27 13:24:16 +00:00
|
|
|
self.updating = false;
|
|
|
|
|
2016-06-29 20:59:47 +00:00
|
|
|
// enable RC data pulling for rates preview
|
|
|
|
GUI.interval_add('receiver_pull', self.getRecieverData, true);
|
|
|
|
|
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() {
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_STATUS);
|
2014-03-30 09:51:16 +00:00
|
|
|
}, 250, true);
|
2014-07-10 16:14:33 +00:00
|
|
|
|
2015-11-11 21:01:22 +00:00
|
|
|
GUI.content_ready(callback);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
2014-07-10 16:14:33 +00:00
|
|
|
};
|
|
|
|
|
2016-06-29 20:59:47 +00:00
|
|
|
TABS.pid_tuning.getRecieverData = function () {
|
2016-08-06 13:31:10 +00:00
|
|
|
MSP.send_message(MSPCodes.MSP_RC, false, false);
|
2016-06-29 20:59:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TABS.pid_tuning.initRatesPreview = function () {
|
|
|
|
this.keepRendering = true;
|
|
|
|
this.model = new Model($('.rates_preview'), $('.rates_preview canvas'));
|
|
|
|
|
|
|
|
$(window).on('resize', $.proxy(this.model.resize, this.model));
|
2016-09-17 07:03:00 +00:00
|
|
|
$(window).on('resize', $.proxy(this.updateRatesLabels, this));
|
2016-06-29 20:59:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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]) {
|
2016-07-06 23:55:15 +00:00
|
|
|
var delta = this.clock.getDelta();
|
2016-07-06 22:13:07 +00:00
|
|
|
|
2016-09-07 20:49:54 +00:00
|
|
|
var roll = delta * this.rateCurve.rcCommandRawToDegreesPerSecond(RC.channels[0], this.currentRates.roll_rate, this.currentRates.rc_rate, this.currentRates.rc_expo, this.currentRates.superexpo, this.currentRates.deadband),
|
|
|
|
pitch = delta * this.rateCurve.rcCommandRawToDegreesPerSecond(RC.channels[1], this.currentRates.pitch_rate, this.currentRates.rc_rate, this.currentRates.rc_expo, this.currentRates.superexpo, this.currentRates.deadband),
|
|
|
|
yaw = delta * this.rateCurve.rcCommandRawToDegreesPerSecond(RC.channels[2], this.currentRates.yaw_rate, this.currentRates.rc_rate_yaw, this.currentRates.rc_yaw_expo, this.currentRates.superexpo, this.currentRates.yawDeadband);
|
2016-06-29 20:59:47 +00:00
|
|
|
|
2016-07-06 23:55:15 +00:00
|
|
|
this.model.rotateBy(-degToRad(pitch), -degToRad(yaw), -degToRad(roll));
|
2016-09-17 07:03:00 +00:00
|
|
|
|
2016-09-18 13:14:54 +00:00
|
|
|
if (this.checkRC()) this.updateRatesLabels(); // has the RC data changed ?
|
|
|
|
|
2015-03-11 20:34:02 +00:00
|
|
|
}
|
2016-06-14 12:20:23 +00:00
|
|
|
};
|
2016-06-29 20:59:47 +00:00
|
|
|
|
|
|
|
TABS.pid_tuning.cleanup = function (callback) {
|
2016-07-27 13:24:16 +00:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
if (self.model) {
|
|
|
|
$(window).off('resize', $.proxy(self.model.resize, self.model));
|
2016-07-26 14:46:13 +00:00
|
|
|
}
|
2016-06-29 20:59:47 +00:00
|
|
|
|
2016-09-17 07:03:00 +00:00
|
|
|
$(window).off('resize', $.proxy(this.updateRatesLabels, this));
|
|
|
|
|
|
|
|
|
2016-07-27 13:24:16 +00:00
|
|
|
self.keepRendering = false;
|
2016-06-29 20:59:47 +00:00
|
|
|
|
|
|
|
if (callback) callback();
|
|
|
|
};
|
2016-07-26 14:46:13 +00:00
|
|
|
|
|
|
|
TABS.pid_tuning.refresh = function (callback) {
|
2016-07-27 13:24:16 +00:00
|
|
|
var self = this;
|
|
|
|
|
2016-07-26 14:46:13 +00:00
|
|
|
GUI.tab_switch_cleanup(function () {
|
2016-07-27 13:24:16 +00:00
|
|
|
self.initialize();
|
|
|
|
|
|
|
|
self.setDirty(false);
|
2016-07-26 14:46:13 +00:00
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-07-27 13:24:16 +00:00
|
|
|
TABS.pid_tuning.setProfile = function () {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
self.currentProfile = CONFIG.profile;
|
|
|
|
$('.tab-pid_tuning select[name="profile"]').val(self.currentProfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
TABS.pid_tuning.setRateProfile = function () {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
self.currentRateProfile = CONFIG.rateProfile;
|
|
|
|
$('.tab-pid_tuning select[name="rate_profile"]').val(self.currentRateProfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
TABS.pid_tuning.setDirty = function (isDirty) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
self.dirty = isDirty;
|
|
|
|
$('.tab-pid_tuning select[name="profile"]').prop('disabled', isDirty);
|
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, "3.0.0")) {
|
|
|
|
$('.tab-pid_tuning select[name="rate_profile"]').prop('disabled', isDirty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TABS.pid_tuning.checkUpdateProfile = function (updateRateProfile) {
|
|
|
|
var self = this;
|
|
|
|
|
2016-08-04 14:24:29 +00:00
|
|
|
if (GUI.active_tab === 'pid_tuning') {
|
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, "3.0.0")
|
|
|
|
&& CONFIG.numProfiles === 2) {
|
|
|
|
$('.tab-pid_tuning select[name="profile"] .profile3').hide();
|
|
|
|
}
|
2016-07-26 14:46:13 +00:00
|
|
|
|
2016-08-04 14:24:29 +00:00
|
|
|
if (!self.updating && !self.dirty) {
|
|
|
|
var changedProfile = false;
|
|
|
|
if (self.currentProfile !== CONFIG.profile) {
|
|
|
|
self.setProfile();
|
2016-07-27 13:24:16 +00:00
|
|
|
|
2016-08-04 14:24:29 +00:00
|
|
|
changedProfile = true;
|
|
|
|
}
|
2016-07-27 13:24:16 +00:00
|
|
|
|
2016-08-04 14:24:29 +00:00
|
|
|
var changedRateProfile = false;
|
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, "3.0.0")
|
|
|
|
&& updateRateProfile
|
|
|
|
&& self.currentRateProfile !== CONFIG.rateProfile) {
|
|
|
|
self.setRateProfile();
|
2016-07-27 13:24:16 +00:00
|
|
|
|
2016-08-04 14:24:29 +00:00
|
|
|
changedRateProfile = true;
|
|
|
|
}
|
2016-07-27 13:24:16 +00:00
|
|
|
|
2016-08-04 14:24:29 +00:00
|
|
|
if (changedProfile || changedRateProfile) {
|
|
|
|
self.refresh(function () {
|
|
|
|
if (changedProfile) {
|
|
|
|
GUI.log(chrome.i18n.getMessage('pidTuningReceivedProfile', [CONFIG.profile + 1]));
|
|
|
|
}
|
2016-07-26 14:46:13 +00:00
|
|
|
|
2016-08-04 14:24:29 +00:00
|
|
|
if (changedRateProfile) {
|
|
|
|
GUI.log(chrome.i18n.getMessage('pidTuningReceivedRateProfile', [CONFIG.rateProfile + 1]));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-07-26 14:46:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-02 21:38:01 +00:00
|
|
|
|
2016-09-18 13:14:54 +00:00
|
|
|
TABS.pid_tuning.checkRC = function() {
|
|
|
|
// Function monitors for change in the primary axes rc received data and returns true if a change is detected.
|
|
|
|
|
|
|
|
if (!this.oldRC) { this.oldRC = [RC.channels[0], RC.channels[1], RC.channels[2]]; }
|
|
|
|
|
|
|
|
// Monitor RC.channels and detect change of value;
|
|
|
|
var rateCurveUpdateRequired = false;
|
|
|
|
for(var i=0; i<this.oldRC.length; i++) { // has the value changed ?
|
|
|
|
if(this.oldRC[i] != RC.channels[i]) {
|
|
|
|
this.oldRC[i] = RC.channels[i];
|
|
|
|
rateCurveUpdateRequired = true; // yes, then an update of the values displayed on the rate curve graph is required
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rateCurveUpdateRequired;
|
|
|
|
};
|
|
|
|
|
2016-08-02 14:26:06 +00:00
|
|
|
TABS.pid_tuning.updatePidControllerParameters = function () {
|
|
|
|
if (semver.gte(CONFIG.flightControllerVersion, "3.0.0")) {
|
|
|
|
if ($('.tab-pid_tuning select[name="controller"]').val() === '0') {
|
2016-07-12 10:27:28 +00:00
|
|
|
$('.pid_tuning .YAW_JUMP_PREVENTION').show();
|
|
|
|
|
2016-08-02 14:26:06 +00:00
|
|
|
$('#pid-tuning .delta').show();
|
2016-08-02 21:38:01 +00:00
|
|
|
|
2016-08-02 14:26:06 +00:00
|
|
|
$('#pid-tuning .ptermSetpoint').hide();
|
|
|
|
$('#pid-tuning .dtermSetpoint').hide();
|
|
|
|
} else {
|
2016-07-12 10:27:28 +00:00
|
|
|
$('.pid_tuning .YAW_JUMP_PREVENTION').hide();
|
|
|
|
|
2016-08-02 14:26:06 +00:00
|
|
|
$('#pid-tuning .ptermSetpoint').show();
|
|
|
|
$('#pid-tuning .dtermSetpoint').show();
|
|
|
|
|
|
|
|
$('#pid-tuning .delta').hide();
|
|
|
|
}
|
|
|
|
}
|
2016-08-02 21:38:01 +00:00
|
|
|
}
|
2016-09-18 13:14:54 +00:00
|
|
|
|
|
|
|
TABS.pid_tuning.updateRatesLabels = function() {
|
|
|
|
var self = this;
|
|
|
|
if (!self.rateCurve.useLegacyCurve && self.rateCurve.maxAngularVel) {
|
|
|
|
|
|
|
|
var drawAxisLabel = function(context, axisLabel, x, y, align, color) {
|
|
|
|
|
|
|
|
context.fillStyle = color || '#000000' ;
|
|
|
|
context.textAlign = align || 'center';
|
|
|
|
context.fillText(axisLabel, x, y);
|
|
|
|
}
|
|
|
|
var drawBalloonLabel = function(context, axisLabel, x, y, align, colors, dirty) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* curveContext is the canvas to draw on
|
|
|
|
* axisLabel is the string to display in the center of the balloon
|
|
|
|
* x, y are the coordinates of the point of the balloon
|
|
|
|
* align is whether the balloon appears to the left (align 'right') or right (align left) of the x,y coordinates
|
|
|
|
* colors is an object defining color, border and text are the fill color, border color and text color of the balloon
|
|
|
|
*/
|
|
|
|
|
|
|
|
const DEFAULT_OFFSET = 125; // in canvas scale; this is the horizontal length of the pointer
|
|
|
|
const DEFAULT_RADIUS = 10; // in canvas scale, this is the radius around the balloon
|
|
|
|
const DEFAULT_MARGIN = 5; // in canvas scale, this is the margin around the balloon when it overlaps
|
|
|
|
|
|
|
|
const fontSize = parseInt(context.font);
|
|
|
|
|
|
|
|
// calculate the width and height required for the balloon
|
|
|
|
const width = (context.measureText(axisLabel).width * 1.2);
|
|
|
|
const height = fontSize * 1.5; // the balloon is bigger than the text height
|
|
|
|
const pointerY = y; // always point to the required Y
|
|
|
|
// coordinate, even if we move the balloon itself to keep it on the canvas
|
|
|
|
|
|
|
|
// setup balloon background
|
|
|
|
context.fillStyle = colors.color || '#ffffff' ;
|
|
|
|
context.strokeStyle = colors.border || '#000000' ;
|
|
|
|
|
|
|
|
// correct x position to account for window scaling
|
|
|
|
x *= context.canvas.clientWidth/context.canvas.clientHeight;
|
|
|
|
|
|
|
|
// adjust the coordinates for determine where the balloon background should be drawn
|
|
|
|
x += ((align=='right')?-(width + DEFAULT_OFFSET):0) + ((align=='left')?DEFAULT_OFFSET:0);
|
|
|
|
y -= (height/2); if(y<0) y=0; else if(y>context.height) y=context.height; // prevent balloon from going out of canvas
|
|
|
|
|
|
|
|
// check that the balloon does not already overlap
|
|
|
|
for(var i=0; i<dirty.length; i++) {
|
|
|
|
if((x>=dirty[i].left && x<=dirty[i].right) || (x+width>=dirty[i].left && x+width<=dirty[i].right)) { // does it overlap horizontally
|
|
|
|
if((y>=dirty[i].top && y<=dirty[i].bottom) || (y+height>=dirty[i].top && y+height<=dirty[i].bottom )) { // this overlaps another balloon
|
|
|
|
// snap above or snap below
|
|
|
|
if(y<=(dirty[i].bottom - dirty[i].top) / 2 && (dirty[i].top - height) > 0) {
|
|
|
|
y = dirty[i].top - height;
|
|
|
|
} else { // snap down
|
|
|
|
y = dirty[i].bottom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the draw area to the dirty array
|
|
|
|
dirty.push({left:x, right:x+width, top:y-DEFAULT_MARGIN, bottom:y+height+DEFAULT_MARGIN});
|
|
|
|
|
|
|
|
|
|
|
|
var pointerLength = (height - 2 * DEFAULT_RADIUS ) / 6;
|
|
|
|
|
|
|
|
context.beginPath();
|
|
|
|
context.moveTo(x + DEFAULT_RADIUS, y);
|
|
|
|
context.lineTo(x + width - DEFAULT_RADIUS, y);
|
|
|
|
context.quadraticCurveTo(x + width, y, x + width, y + DEFAULT_RADIUS);
|
|
|
|
|
|
|
|
if(align=='right') { // point is to the right
|
|
|
|
context.lineTo(x + width, y + DEFAULT_RADIUS + pointerLength);
|
|
|
|
context.lineTo(x + width + DEFAULT_OFFSET, pointerY); // point
|
|
|
|
context.lineTo(x + width, y + height - DEFAULT_RADIUS - pointerLength);
|
|
|
|
}
|
|
|
|
context.lineTo(x + width, y + height - DEFAULT_RADIUS);
|
|
|
|
|
|
|
|
context.quadraticCurveTo(x + width, y + height, x + width - DEFAULT_RADIUS, y + height);
|
|
|
|
context.lineTo(x + DEFAULT_RADIUS, y + height);
|
|
|
|
context.quadraticCurveTo(x, y + height, x, y + height - DEFAULT_RADIUS);
|
|
|
|
|
|
|
|
if(align=='left') { // point is to the left
|
|
|
|
context.lineTo(x, y + height - DEFAULT_RADIUS - pointerLength);
|
|
|
|
context.lineTo(x - DEFAULT_OFFSET, pointerY); // point
|
|
|
|
context.lineTo(x, y + DEFAULT_RADIUS - pointerLength);
|
|
|
|
}
|
|
|
|
context.lineTo(x, y + DEFAULT_RADIUS);
|
|
|
|
|
|
|
|
context.quadraticCurveTo(x, y, x + DEFAULT_RADIUS, y);
|
|
|
|
context.closePath();
|
|
|
|
|
|
|
|
// fill in the balloon background
|
|
|
|
context.fill();
|
|
|
|
context.stroke();
|
|
|
|
|
|
|
|
// and add the label
|
|
|
|
drawAxisLabel(context, axisLabel, x + (width/2), y + (height + fontSize)/2 - 4, 'center', colors.text);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const BALLOON_COLORS = {
|
|
|
|
roll : {color: 'rgba(255,128,128,0.4)', border: 'rgba(255,128,128,0.6)', text: '#000000'},
|
|
|
|
pitch : {color: 'rgba(128,255,128,0.4)', border: 'rgba(128,255,128,0.6)', text: '#000000'},
|
|
|
|
yaw : {color: 'rgba(128,128,255,0.4)', border: 'rgba(128,128,255,0.6)', text: '#000000'}
|
|
|
|
};
|
|
|
|
|
|
|
|
var rcStickElement,
|
|
|
|
stickContext;
|
|
|
|
|
|
|
|
if(!rcStickElement) {
|
|
|
|
rcStickElement = $('.rate_curve canvas#rate_curve_layer1').get(0);
|
|
|
|
rcStickElement.width = 1000;
|
|
|
|
rcStickElement.height = 1000;
|
|
|
|
}
|
|
|
|
if(!stickContext) stickContext = rcStickElement.getContext("2d");
|
|
|
|
|
|
|
|
stickContext.save();
|
|
|
|
|
|
|
|
var
|
|
|
|
maxAngularVelRoll = self.maxAngularVelRollElement.text() + ' deg/s',
|
|
|
|
maxAngularVelPitch = self.maxAngularVelPitchElement.text() + ' deg/s',
|
|
|
|
maxAngularVelYaw = self.maxAngularVelYawElement.text() + ' deg/s',
|
|
|
|
currentValues = [],
|
|
|
|
balloonsDirty = [],
|
|
|
|
curveHeight = rcStickElement.height,
|
|
|
|
curveWidth = rcStickElement.width,
|
|
|
|
maxAngularVel = self.rateCurve.maxAngularVel,
|
|
|
|
windowScale = (400 / stickContext.canvas.clientHeight),
|
|
|
|
rateScale = (curveHeight / 2) / maxAngularVel,
|
|
|
|
lineScale = stickContext.canvas.width / stickContext.canvas.clientWidth,
|
|
|
|
textScale = stickContext.canvas.clientHeight / stickContext.canvas.clientWidth;
|
|
|
|
|
|
|
|
|
|
|
|
stickContext.clearRect(0, 0, curveWidth, curveHeight);
|
|
|
|
|
|
|
|
// calculate the fontSize based upon window scaling
|
|
|
|
if(windowScale <= 1) {
|
|
|
|
stickContext.font = "24pt Verdana, Arial, sans-serif";
|
|
|
|
} else {
|
|
|
|
stickContext.font = (24 * windowScale) + "pt Verdana, Arial, sans-serif";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(RC.channels[0] && RC.channels[1] && RC.channels[2]) {
|
|
|
|
currentValues.push(self.rateCurve.drawStickPosition(RC.channels[0], self.currentRates.roll_rate, self.currentRates.rc_rate, self.currentRates.rc_expo, self.currentRates.superexpo, self.currentRates.deadband, maxAngularVel, stickContext, '#FF8080') + ' deg/s');
|
|
|
|
currentValues.push(self.rateCurve.drawStickPosition(RC.channels[1], self.currentRates.roll_rate, self.currentRates.rc_rate, self.currentRates.rc_expo, self.currentRates.superexpo, self.currentRates.deadband, maxAngularVel, stickContext, '#80FF80') + ' deg/s');
|
|
|
|
currentValues.push(self.rateCurve.drawStickPosition(RC.channels[2], self.currentRates.yaw_rate, self.currentRates.rc_rate_yaw, self.currentRates.rc_yaw_expo, self.currentRates.superexpo, self.currentRates.yawDeadband, maxAngularVel, stickContext, '#8080FF') + ' deg/s');
|
|
|
|
} else {
|
|
|
|
currentValues = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
stickContext.lineWidth = 1 * lineScale;
|
|
|
|
|
|
|
|
// use a custom scale so that the text does not appear stretched
|
|
|
|
stickContext.scale(textScale,1);
|
|
|
|
|
|
|
|
// add the maximum range label
|
|
|
|
drawAxisLabel(stickContext, maxAngularVel.toFixed(0) + ' deg/s', ((curveWidth / 2) - 10) / textScale, parseInt(stickContext.font)*1.2, 'right');
|
|
|
|
|
|
|
|
// and then the balloon labels.
|
|
|
|
balloonsDirty = []; // reset the dirty balloon draw area (for overlap detection)
|
|
|
|
// create an array of balloons to draw
|
|
|
|
var balloons = [
|
|
|
|
{value: parseInt(maxAngularVelRoll), balloon: function() {drawBalloonLabel(stickContext, maxAngularVelRoll, curveWidth, rateScale * (maxAngularVel - parseInt(maxAngularVelRoll)), 'right', BALLOON_COLORS.roll, balloonsDirty);}},
|
|
|
|
{value: parseInt(maxAngularVelPitch), balloon: function() {drawBalloonLabel(stickContext, maxAngularVelPitch, curveWidth, rateScale * (maxAngularVel - parseInt(maxAngularVelPitch)), 'right', BALLOON_COLORS.pitch, balloonsDirty);}},
|
|
|
|
{value: parseInt(maxAngularVelYaw), balloon: function() {drawBalloonLabel(stickContext, maxAngularVelYaw, curveWidth, rateScale * (maxAngularVel - parseInt(maxAngularVelYaw)), 'right', BALLOON_COLORS.yaw, balloonsDirty);}}
|
|
|
|
];
|
|
|
|
// and sort them in descending order so the largest value is at the top always
|
|
|
|
balloons.sort(function(a,b) {return (b.value - a.value)});
|
|
|
|
|
|
|
|
// add the current rc values
|
|
|
|
if(currentValues[0] && currentValues[1] && currentValues[2]) {
|
|
|
|
balloons.push(
|
|
|
|
{value: parseInt(currentValues[0]), balloon: function() {drawBalloonLabel(stickContext, currentValues[0], 10, 150, 'none', BALLOON_COLORS.roll, balloonsDirty);}},
|
|
|
|
{value: parseInt(currentValues[1]), balloon: function() {drawBalloonLabel(stickContext, currentValues[1], 10, 250, 'none', BALLOON_COLORS.pitch, balloonsDirty);}},
|
|
|
|
{value: parseInt(currentValues[2]), balloon: function() {drawBalloonLabel(stickContext, currentValues[2], 10, 350, 'none', BALLOON_COLORS.yaw, balloonsDirty);}}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
// then display them on the chart
|
|
|
|
for(var i=0; i<balloons.length; i++) balloons[i].balloon();
|
|
|
|
|
|
|
|
stickContext.restore();
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|