Merge pull request #1339 from etracer65/add_filter_defaults_by_version

Add support for filtering defaults based on firmware version
10.5.x-maintenance
Michael Keller 2019-04-05 08:44:04 +13:00 committed by GitHub
commit c685be4223
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 25 deletions

View File

@ -466,9 +466,9 @@ var FC = {
gyro_lowpass_hz: 100,
gyro_lowpass_dyn_min_hz: 150,
gyro_lowpass_dyn_max_hz: 450,
gyro_lowpass_type: 0,
gyro_lowpass_type: FC.FILTER_TYPE_FLAGS.PT1,
gyro_lowpass2_hz: 300,
gyro_lowpass2_type: 0,
gyro_lowpass2_type: FC.FILTER_TYPE_FLAGS.PT1,
gyro_notch_cutoff: 300,
gyro_notch_hz: 400,
gyro_notch2_cutoff: 100,
@ -476,9 +476,9 @@ var FC = {
dterm_lowpass_hz: 100,
dterm_lowpass_dyn_min_hz: 150,
dterm_lowpass_dyn_max_hz: 250,
dterm_lowpass_type: 0,
dterm_lowpass_type: FC.FILTER_TYPE_FLAGS.PT1,
dterm_lowpass2_hz: 150,
dterm_lowpass2_type: 1,
dterm_lowpass2_type: FC.FILTER_TYPE_FLAGS.BIQUAD,
dterm_notch_cutoff: 160,
dterm_notch_hz: 260,
yaw_lowpass_hz: 100,
@ -537,4 +537,27 @@ var FC = {
return hasVcp;
},
FILTER_TYPE_FLAGS: {
PT1: 0,
BIQUAD: 1,
},
getFilterDefaults: function() {
var versionFilterDefaults = DEFAULT;
if (semver.eq(CONFIG.apiVersion, "1.40.0")) {
versionFilterDefaults.dterm_lowpass2_hz = 200;
} else if (semver.gte(CONFIG.apiVersion, "1.41.0")) {
versionFilterDefaults.gyro_lowpass_hz = 150;
versionFilterDefaults.gyro_lowpass_type = FC.FILTER_TYPE_FLAGS.BIQUAD;
versionFilterDefaults.gyro_lowpass2_hz = 0;
versionFilterDefaults.gyro_lowpass2_type = FC.FILTER_TYPE_FLAGS.BIQUAD;
versionFilterDefaults.dterm_lowpass_hz = 150;
versionFilterDefaults.dterm_lowpass_type = FC.FILTER_TYPE_FLAGS.BIQUAD;
versionFilterDefaults.dterm_lowpass2_hz = 150;
versionFilterDefaults.dterm_lowpass2_type = FC.FILTER_TYPE_FLAGS.BIQUAD;
}
return versionFilterDefaults;
},
};

View File

@ -13,12 +13,16 @@ TABS.pid_tuning = {
};
TABS.pid_tuning.initialize = function (callback) {
var self = this;
if (GUI.active_tab !== 'pid_tuning') {
GUI.active_tab = 'pid_tuning';
}
// Update filtering defaults based on API version
var FILTER_DEFAULT = FC.getFilterDefaults();
// requesting MSP_STATUS manually because it contains CONFIG.profile
MSP.promise(MSPCodes.MSP_STATUS).then(function() {
if (semver.gte(CONFIG.apiVersion, CONFIGURATOR.pidControllerChangeMinApiVersion)) {
@ -377,8 +381,8 @@ TABS.pid_tuning.initialize = function (callback) {
$('input[id="gyroNotch1Enabled"]').change(function() {
var checked = $(this).is(':checked');
var hz = FILTER_CONFIG.gyro_notch_hz > 0 ? FILTER_CONFIG.gyro_notch_hz : DEFAULT.gyro_notch_hz;
var cutoff = FILTER_CONFIG.gyro_notch_cutoff > 0 ? FILTER_CONFIG.gyro_notch_cutoff : DEFAULT.gyro_notch_cutoff;
var hz = FILTER_CONFIG.gyro_notch_hz > 0 ? FILTER_CONFIG.gyro_notch_hz : FILTER_DEFAULT.gyro_notch_hz;
var cutoff = FILTER_CONFIG.gyro_notch_cutoff > 0 ? FILTER_CONFIG.gyro_notch_cutoff : FILTER_DEFAULT.gyro_notch_cutoff;
$('.pid_filter input[name="gyroNotch1Frequency"]').val(checked ? hz : 0).attr('disabled', !checked)
.attr("min", checked ? 1 : 0).change();
@ -387,8 +391,8 @@ TABS.pid_tuning.initialize = function (callback) {
$('input[id="gyroNotch2Enabled"]').change(function() {
var checked = $(this).is(':checked');
var hz = FILTER_CONFIG.gyro_notch2_hz > 0 ? FILTER_CONFIG.gyro_notch2_hz : DEFAULT.gyro_notch2_hz;
var cutoff = FILTER_CONFIG.gyro_notch2_cutoff > 0 ? FILTER_CONFIG.gyro_notch2_cutoff : DEFAULT.gyro_notch2_cutoff;
var hz = FILTER_CONFIG.gyro_notch2_hz > 0 ? FILTER_CONFIG.gyro_notch2_hz : FILTER_DEFAULT.gyro_notch2_hz;
var cutoff = FILTER_CONFIG.gyro_notch2_cutoff > 0 ? FILTER_CONFIG.gyro_notch2_cutoff : FILTER_DEFAULT.gyro_notch2_cutoff;
$('.pid_filter input[name="gyroNotch2Frequency"]').val(checked ? hz : 0).attr('disabled', !checked)
.attr("min", checked ? 1 : 0).change();
@ -397,8 +401,8 @@ TABS.pid_tuning.initialize = function (callback) {
$('input[id="dtermNotchEnabled"]').change(function() {
var checked = $(this).is(':checked');
var hz = FILTER_CONFIG.dterm_notch_hz > 0 ? FILTER_CONFIG.dterm_notch_hz : DEFAULT.dterm_notch_hz;
var cutoff = FILTER_CONFIG.dterm_notch_cutoff > 0 ? FILTER_CONFIG.dterm_notch_cutoff : DEFAULT.dterm_notch_cutoff;
var hz = FILTER_CONFIG.dterm_notch_hz > 0 ? FILTER_CONFIG.dterm_notch_hz : FILTER_DEFAULT.dterm_notch_hz;
var cutoff = FILTER_CONFIG.dterm_notch_cutoff > 0 ? FILTER_CONFIG.dterm_notch_cutoff : FILTER_DEFAULT.dterm_notch_cutoff;
$('.pid_filter input[name="dTermNotchFrequency"]').val(checked ? hz : 0).attr('disabled', !checked)
.attr("min", checked ? 1 : 0).change();
@ -407,8 +411,8 @@ TABS.pid_tuning.initialize = function (callback) {
$('input[id="gyroLowpassEnabled"]').change(function() {
var checked = $(this).is(':checked');
var cutoff = FILTER_CONFIG.gyro_lowpass_hz > 0 ? FILTER_CONFIG.gyro_lowpass_hz : DEFAULT.gyro_lowpass_hz;
var type = FILTER_CONFIG.gyro_lowpass_type > 0 ? FILTER_CONFIG.gyro_lowpass_type : DEFAULT.gyro_lowpass_type;
var cutoff = FILTER_CONFIG.gyro_lowpass_hz > 0 ? FILTER_CONFIG.gyro_lowpass_hz : FILTER_DEFAULT.gyro_lowpass_hz;
var type = FILTER_CONFIG.gyro_lowpass_type > 0 ? FILTER_CONFIG.gyro_lowpass_type : FILTER_DEFAULT.gyro_lowpass_type;
$('.pid_filter input[name="gyroLowpassFrequency"]').val(checked ? cutoff : 0).attr('disabled', !checked);
$('.pid_filter select[name="gyroLowpassType"]').val(checked ? type : 0).attr('disabled', !checked);
@ -421,13 +425,13 @@ TABS.pid_tuning.initialize = function (callback) {
$('input[id="gyroLowpassDynEnabled"]').change(function() {
var checked = $(this).is(':checked');
var cutoff_min = DEFAULT.gyro_lowpass_dyn_min_hz;
var cutoff_max = DEFAULT.gyro_lowpass_dyn_max_hz;
var cutoff_min = FILTER_DEFAULT.gyro_lowpass_dyn_min_hz;
var cutoff_max = FILTER_DEFAULT.gyro_lowpass_dyn_max_hz;
if (FILTER_CONFIG.gyro_lowpass_dyn_min_hz > 0 && FILTER_CONFIG.gyro_lowpass_dyn_min_hz < FILTER_CONFIG.gyro_lowpass_dyn_max_hz) {
cutoff_min = FILTER_CONFIG.gyro_lowpass_dyn_min_hz;
cutoff_max = FILTER_CONFIG.gyro_lowpass_dyn_max_hz;
}
var type = FILTER_CONFIG.gyro_lowpass_type > 0 ? FILTER_CONFIG.gyro_lowpass_type : DEFAULT.gyro_lowpass_type;
var type = FILTER_CONFIG.gyro_lowpass_type > 0 ? FILTER_CONFIG.gyro_lowpass_type : FILTER_DEFAULT.gyro_lowpass_type;
$('.pid_filter input[name="gyroLowpassDynMinFrequency"]').val(checked ? cutoff_min : 0).attr('disabled', !checked);
$('.pid_filter input[name="gyroLowpassDynMaxFrequency"]').attr('disabled', !checked);
@ -440,8 +444,8 @@ TABS.pid_tuning.initialize = function (callback) {
$('input[id="gyroLowpass2Enabled"]').change(function() {
var checked = $(this).is(':checked');
var cutoff = FILTER_CONFIG.gyro_lowpass2_hz > 0 ? FILTER_CONFIG.gyro_lowpass2_hz : DEFAULT.gyro_lowpass2_hz;
var type = FILTER_CONFIG.gyro_lowpass2_type > 0 ? FILTER_CONFIG.gyro_lowpass2_type : DEFAULT.gyro_lowpass2_type;
var cutoff = FILTER_CONFIG.gyro_lowpass2_hz > 0 ? FILTER_CONFIG.gyro_lowpass2_hz : FILTER_DEFAULT.gyro_lowpass2_hz;
var type = FILTER_CONFIG.gyro_lowpass2_type > 0 ? FILTER_CONFIG.gyro_lowpass2_type : FILTER_DEFAULT.gyro_lowpass2_type;
$('.pid_filter input[name="gyroLowpass2Frequency"]').val(checked ? cutoff : 0).attr('disabled', !checked);
$('.pid_filter select[name="gyroLowpass2Type"]').val(checked ? type : 0).attr('disabled', !checked);
@ -449,8 +453,8 @@ TABS.pid_tuning.initialize = function (callback) {
$('input[id="dtermLowpassEnabled"]').change(function() {
var checked = $(this).is(':checked');
var cutoff = FILTER_CONFIG.dterm_lowpass_hz > 0 ? FILTER_CONFIG.dterm_lowpass_hz : DEFAULT.dterm_lowpass_hz;
var type = FILTER_CONFIG.dterm_lowpass_type > 0 ? FILTER_CONFIG.dterm_lowpass_type : DEFAULT.dterm_lowpass_type;
var cutoff = FILTER_CONFIG.dterm_lowpass_hz > 0 ? FILTER_CONFIG.dterm_lowpass_hz : FILTER_DEFAULT.dterm_lowpass_hz;
var type = FILTER_CONFIG.dterm_lowpass_type > 0 ? FILTER_CONFIG.dterm_lowpass_type : FILTER_DEFAULT.dterm_lowpass_type;
$('.pid_filter input[name="dtermLowpassFrequency"]').val(checked ? cutoff : 0).attr('disabled', !checked);
$('.pid_filter select[name="dtermLowpassType"]').val(checked ? type : 0).attr('disabled', !checked);
@ -462,13 +466,13 @@ TABS.pid_tuning.initialize = function (callback) {
$('input[id="dtermLowpassDynEnabled"]').change(function() {
var checked = $(this).is(':checked');
var cutoff_min = DEFAULT.dterm_lowpass_dyn_min_hz;
var cutoff_max = DEFAULT.dterm_lowpass_dyn_max_hz;
var cutoff_min = FILTER_DEFAULT.dterm_lowpass_dyn_min_hz;
var cutoff_max = FILTER_DEFAULT.dterm_lowpass_dyn_max_hz;
if (FILTER_CONFIG.dterm_lowpass_dyn_min_hz > 0 && FILTER_CONFIG.dterm_lowpass_dyn_min_hz < FILTER_CONFIG.dterm_lowpass_dyn_max_hz) {
cutoff_min = FILTER_CONFIG.dterm_lowpass_dyn_min_hz;
cutoff_max = FILTER_CONFIG.dterm_lowpass_dyn_max_hz;
}
var type = FILTER_CONFIG.dterm_lowpass_type > 0 ? FILTER_CONFIG.dterm_lowpass_type : DEFAULT.dterm_lowpass_type;
var type = FILTER_CONFIG.dterm_lowpass_type > 0 ? FILTER_CONFIG.dterm_lowpass_type : FILTER_DEFAULT.dterm_lowpass_type;
$('.pid_filter input[name="dtermLowpassDynMinFrequency"]').val(checked ? cutoff_min : 0).attr('disabled', !checked);
$('.pid_filter input[name="dtermLowpassDynMaxFrequency"]').val(checked ? cutoff_max : 0).attr('disabled', !checked);
@ -481,8 +485,8 @@ TABS.pid_tuning.initialize = function (callback) {
$('input[id="dtermLowpass2Enabled"]').change(function() {
var checked = $(this).is(':checked');
var cutoff = FILTER_CONFIG.dterm_lowpass2_hz > 0 ? FILTER_CONFIG.dterm_lowpass2_hz : DEFAULT.dterm_lowpass2_hz;
var type = FILTER_CONFIG.dterm_lowpass2_type > 0 ? FILTER_CONFIG.dterm_lowpass2_type : DEFAULT.dterm_lowpass2_type;
var cutoff = FILTER_CONFIG.dterm_lowpass2_hz > 0 ? FILTER_CONFIG.dterm_lowpass2_hz : FILTER_DEFAULT.dterm_lowpass2_hz;
var type = FILTER_CONFIG.dterm_lowpass2_type > 0 ? FILTER_CONFIG.dterm_lowpass2_type : FILTER_DEFAULT.dterm_lowpass2_type;
$('.pid_filter input[name="dtermLowpass2Frequency"]').val(checked ? cutoff : 0).attr('disabled', !checked);
$('.pid_filter select[name="dtermLowpass2Type"]').val(checked ? type : 0).attr('disabled', !checked);
@ -490,7 +494,7 @@ TABS.pid_tuning.initialize = function (callback) {
$('input[id="yawLowpassEnabled"]').change(function() {
var checked = $(this).is(':checked');
var cutoff = FILTER_CONFIG.yaw_lowpass_hz > 0 ? FILTER_CONFIG.yaw_lowpass_hz : DEFAULT.yaw_lowpass_hz;
var cutoff = FILTER_CONFIG.yaw_lowpass_hz > 0 ? FILTER_CONFIG.yaw_lowpass_hz : FILTER_DEFAULT.yaw_lowpass_hz;
$('.pid_filter input[name="yawLowpassFrequency"]').val(checked ? cutoff : 0).attr('disabled', !checked);
});