From 7e3ff0b27be0c2baf8cde3f435f7c4bc8ed992be Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Mon, 20 Jun 2022 02:31:14 +0200 Subject: [PATCH] Remove antiGravityMode and change itermAcceleratorGain to antiGravityGain --- src/js/fc.js | 3 +- src/js/msp/MSPHelper.js | 16 ++++-- src/js/tabs/pid_tuning.js | 102 ++++++++++++++++++++++++-------------- 3 files changed, 80 insertions(+), 41 deletions(-) diff --git a/src/js/fc.js b/src/js/fc.js index 0319d377..d85abc62 100644 --- a/src/js/fc.js +++ b/src/js/fc.js @@ -486,7 +486,8 @@ const FC = { levelAngleLimit: 0, levelSensitivity: 0, itermThrottleThreshold: 0, - itermAcceleratorGain: 0, + itermAcceleratorGain: 0, // depecrated in API 1.45 + antiGravityGain: 0, // was itermAccelatorGain till API 1.45 itermRotation: 0, smartFeedforward: 0, itermRelax: 0, diff --git a/src/js/msp/MSPHelper.js b/src/js/msp/MSPHelper.js index 8ad9294c..3658a37a 100644 --- a/src/js/msp/MSPHelper.js +++ b/src/js/msp/MSPHelper.js @@ -1212,7 +1212,12 @@ MspHelper.prototype.process_data = function(dataHandler) { if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { FC.ADVANCED_TUNING.itermThrottleThreshold = data.readU16(); - FC.ADVANCED_TUNING.itermAcceleratorGain = data.readU16(); + + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + FC.ADVANCED_TUNING.antiGravityGain = data.readU16(); + } else { + FC.ADVANCED_TUNING.itermAcceleratorGain = data.readU16(); + } if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { FC.ADVANCED_TUNING.dtermSetpointWeight = data.readU16(); @@ -2214,8 +2219,13 @@ MspHelper.prototype.crunch = function(code) { .push8(FC.ADVANCED_TUNING.levelSensitivity); if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - buffer.push16(FC.ADVANCED_TUNING.itermThrottleThreshold) - .push16(FC.ADVANCED_TUNING.itermAcceleratorGain); + buffer.push16(FC.ADVANCED_TUNING.itermThrottleThreshold); + + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + buffer.push16(FC.ADVANCED_TUNING.antiGravityGain); + } else { + buffer.push16(FC.ADVANCED_TUNING.itermAcceleratorGain); + } if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { buffer.push16(FC.ADVANCED_TUNING.dtermSetpointWeight); diff --git a/src/js/tabs/pid_tuning.js b/src/js/tabs/pid_tuning.js index 4360c590..66221e50 100644 --- a/src/js/tabs/pid_tuning.js +++ b/src/js/tabs/pid_tuning.js @@ -181,39 +181,62 @@ pid_tuning.initialize = function (callback) { $('.pid_sensitivity').hide(); } + const antiGravitySwitch = $('#antiGravitySwitch'); + const antiGravityGain = $('.antigravity input[name="itermAcceleratorGain"]'); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { $('.pid_filter select[name="dtermLowpassType"]').val(FC.FILTER_CONFIG.dterm_lowpass_type); - $('.antigravity input[name="itermThrottleThreshold"]').val(FC.ADVANCED_TUNING.itermThrottleThreshold); - $('.antigravity input[name="itermAcceleratorGain"]').val(FC.ADVANCED_TUNING.itermAcceleratorGain / 1000); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - $('.antigravity input[name="itermAcceleratorGain"]').attr("min","0.1"); + + const ITERM_ACCELERATOR_GAIN_OFF = semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44) ? 0 : 1000; + + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + // we keep the same name in html - just switching variable. + antiGravityGain.val(FC.ADVANCED_TUNING.antiGravityGain); + + antiGravitySwitch.prop('checked', FC.ADVANCED_TUNING.antiGravityGain !== ITERM_ACCELERATOR_GAIN_OFF); + } else { + $('.antigravity input[name="itermThrottleThreshold"]').val(FC.ADVANCED_TUNING.itermThrottleThreshold); + antiGravityGain.val(FC.ADVANCED_TUNING.itermAcceleratorGain / 1000); + + antiGravitySwitch.prop('checked', FC.ADVANCED_TUNING.itermAcceleratorGain !== ITERM_ACCELERATOR_GAIN_OFF); + } + + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { + antiGravityGain.attr("min","0.1"); + } + + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + antiGravityGain.attr({ "min": "1", "max": "250", "step": "1" }); } - const antiGravitySwitch = $('#antiGravitySwitch'); - const ITERM_ACCELERATOR_GAIN_OFF = semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44) ? 0 : 1000; - antiGravitySwitch.prop('checked', FC.ADVANCED_TUNING.itermAcceleratorGain !== ITERM_ACCELERATOR_GAIN_OFF); antiGravitySwitch.change(function() { const checked = $(this).is(':checked'); + if (checked) { - if (FC.ADVANCED_TUNING.itermAcceleratorGain === ITERM_ACCELERATOR_GAIN_OFF) { + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + antiGravityGain.val(FC.ADVANCED_TUNING.antiGravityGain || 1); + } else { const DEFAULT_ACCELERATOR_GAIN = semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43) ? 3.5 : 1.1; - $('.antigravity input[name="itermAcceleratorGain"]').val(DEFAULT_ACCELERATOR_GAIN); - } else { - const itermAcceleratorGain = (FC.ADVANCED_TUNING.itermAcceleratorGain / 1000); - $('.antigravity input[name="itermAcceleratorGain"]').val(itermAcceleratorGain); + + if (FC.ADVANCED_TUNING.itermAcceleratorGain === ITERM_ACCELERATOR_GAIN_OFF) { + antiGravityGain.val(DEFAULT_ACCELERATOR_GAIN); + } else { + const itermAcceleratorGain = (FC.ADVANCED_TUNING.itermAcceleratorGain / 1000); + antiGravityGain.val(itermAcceleratorGain); + } } + $('.antigravity .suboption').show(); - if (FC.ADVANCED_TUNING.antiGravityMode == 0) { - $('.antigravity .antiGravityThres').hide(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - $('.antigravity .antiGravityMode').show(); - } else { - $('.antigravity .antiGravityMode').hide(); - } + $('.antigravity .antiGravityThres').toggle(semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45) && FC.ADVANCED_TUNING.itermAcceleratorGain === 0); + $('.antigravity .antiGravityMode').toggle(semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40) && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45)); } else { - $('.antigravity select[id="antiGravityMode"]').val(0); - $('.antigravity input[name="itermAcceleratorGain"]').val(ITERM_ACCELERATOR_GAIN_OFF / 1000); + if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + $('.antigravity select[id="antiGravityMode"]').val(0); + antiGravityGain.val(ITERM_ACCELERATOR_GAIN_OFF); + } else { + antiGravityGain.val(ITERM_ACCELERATOR_GAIN_OFF / 1000); + } + $('.antigravity .suboption').hide(); } }); @@ -308,20 +331,19 @@ pid_tuning.initialize = function (callback) { const feedforwardTransitionNumberElement = $('input[name="feedforwardTransition-number"]'); feedforwardTransitionNumberElement.val(FC.ADVANCED_TUNING.feedforwardTransition / 100); - // AntiGravity Mode - const antiGravityModeSelect = $('.antigravity select[id="antiGravityMode"]'); - antiGravityModeSelect.change(function () { - const antiGravityModeValue = $('.antigravity select[id="antiGravityMode"]').val(); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40) && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + // AntiGravity Mode + const antiGravityModeSelect = $('.antigravity select[id="antiGravityMode"]'); - // Smooth removes threshold - if (antiGravityModeValue == 0) { - $('.antiGravityThres').hide(); - } else { - $('.antiGravityThres').show(); - } - }); + antiGravityModeSelect.on('change', function () { + const antiGravityModeValue = antiGravityModeSelect.val(); - antiGravityModeSelect.val(FC.ADVANCED_TUNING.antiGravityMode).change(); + // Smooth removes threshold + $('.antiGravityThres').toggle(antiGravityModeValue !== 0); + }); + + antiGravityModeSelect.val(FC.ADVANCED_TUNING.antiGravityMode).trigger('change'); + } } else { $('.itermrotation').hide(); @@ -1201,10 +1223,16 @@ pid_tuning.initialize = function (callback) { } } + const antiGravityGain = $('.antigravity input[name="itermAcceleratorGain"]'); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { FC.FILTER_CONFIG.dterm_lowpass_type = parseInt($('.pid_filter select[name="dtermLowpassType"]').val()); - FC.ADVANCED_TUNING.itermThrottleThreshold = parseInt($('.antigravity input[name="itermThrottleThreshold"]').val()); - FC.ADVANCED_TUNING.itermAcceleratorGain = parseInt($('.antigravity input[name="itermAcceleratorGain"]').val() * 1000); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + FC.ADVANCED_TUNING.antiGravityGain = parseInt(antiGravityGain.val()); + } else { + FC.ADVANCED_TUNING.itermThrottleThreshold = parseInt($('.antigravity input[name="itermThrottleThreshold"]').val()); + FC.ADVANCED_TUNING.itermAcceleratorGain = parseInt(antiGravityGain.val() * 1000); + } } if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { @@ -1236,7 +1264,7 @@ pid_tuning.initialize = function (callback) { FC.ADVANCED_TUNING.feedforwardTransition = parseInt($('input[name="feedforwardTransition-number"]').val() * 100); - FC.ADVANCED_TUNING.antiGravityMode = $('select[id="antiGravityMode"]').val(); + FC.ADVANCED_TUNING.antiGravityMode = semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45) ? $('select[id="antiGravityMode"]').val() : 0; } if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) {