From b39f7df5f7b1da7c0e8fd2e495e8365552340a14 Mon Sep 17 00:00:00 2001 From: IvoFPV Date: Sat, 10 Aug 2019 14:48:30 +0200 Subject: [PATCH] Add dyn notch to UI try2 --- locales/en/messages.json | 30 ++++++++++++++++++ src/css/tabs/pid_tuning.css | 10 ++++++ src/js/fc.js | 4 +++ src/js/msp/MSPHelper.js | 12 +++++++ src/js/tabs/pid_tuning.js | 34 ++++++++++++++++++++ src/tabs/pid_tuning.html | 63 +++++++++++++++++++++++++++++++++++++ 6 files changed, 153 insertions(+) diff --git a/locales/en/messages.json b/locales/en/messages.json index 10f0cb94..47b1a304 100644 --- a/locales/en/messages.json +++ b/locales/en/messages.json @@ -3120,6 +3120,36 @@ "pidTuningNotchFilterHelp": { "message": "The Notch Filter has a Center and a Cutoff. The filter is symmetrical. The Center Frequency is the center of the filter and the Cutoff Frequency is where Notch filter starts. For example with Notch Cutoff of 160 and Notch Center of 260 it means the range is 160-360Hz with most attenuation around center" }, + "pidTuningDynamicNotchFilterGroup": { + "message": "Dynamic Notch Filter" + }, + "pidTuningDynamicNotchFilterHelp": { + "message": "Dynamic Notch Filter tracks peak motors noise frequency and places one or two notch filters with their center at that frequency." + }, + "pidTuningDynamicNotchRange": { + "message": "Dynamic Notch Filter Range" + }, + "pidTuningDynamicNotchWidthPercent": { + "message": "Dynamic Notch Width Percent" + }, + "pidTuningDynamicNotchQ": { + "message": "Dynamic Notch Q" + }, + "pidTuningDynamicNotchMinHz": { + "message": "Dynamic Notch Min Hz" + }, + "pidTuningDynamicNotchRangeHelp": { + "message": "The dynamic notch has three frequency ranges in which it can operate: LOW(80-330hz) for lower revving quads like 6+ inches, MEDIUM(140-550hz) for a normal 5 inch quad, HIGH(230-800hz) for very high revving 2.5-3 inch quads. AUTO option selects the range depending on the value of the Dynamic Lowpass Filter's max cutoff frequency." + }, + "pidTuningDynamicNotchWidthPercentHelp": { + "message": "This sets the width between two dynamic notch filters. Setting it at 0 will disable the second dynamic notch filter and will reduce filter delay, however it may make motor temperatures higher." + }, + "pidTuningDynamicNotchQHelp": { + "message": "Q factor adjust how narrow or wide the dynamic notch filters are. Higher value makes it narrower and more precise and lower value makes it wider and broader. Having a really low value will greatly increase filter delay." + }, + "pidTuningDynamicNotchMinHzHelp": { + "message": "Defines the lowest dynamic notch center frequency below which the dynamic notch will not go." + }, "pidTuningLowpassFilterHelp": { "message": "The Lowpass Filters can have two variants: static and dynamic. For a determined lowpass filter number only one (static or dynamic) can be enabled at the same time. The static only has a Cutoff that is a value that defines in some way where the filter starts. The dynamic defines a min and max values, that is the range where the Cutoff is placed. This Cutoff moves from min to max at the same time than you move the throttle stick." }, diff --git a/src/css/tabs/pid_tuning.css b/src/css/tabs/pid_tuning.css index 037103e7..3efac04e 100644 --- a/src/css/tabs/pid_tuning.css +++ b/src/css/tabs/pid_tuning.css @@ -366,7 +366,13 @@ border-radius: 0px; } +.tab-pid_tuning .subtab-filter table input { + width: 77px; + float: right; +} + .tab-pid_tuning table select { + width: 77px; text-align-last: right; } @@ -541,6 +547,10 @@ margin-top: 1px; } +.tab-pid_tuning .subtab-filter .newFilter .helpicon { + margin-right: 2px; +} + .tab-pid_tuning .number .helpicon { margin-top: 3px; margin-right: 0px; diff --git a/src/js/fc.js b/src/js/fc.js index 02bc242c..456746c1 100644 --- a/src/js/fc.js +++ b/src/js/fc.js @@ -377,6 +377,10 @@ var FC = { dterm_notch_hz: 0, dterm_notch_cutoff: 0, yaw_lowpass_hz: 0, + dyn_notch_range: 0, + dyn_notch_width_percent: 0, + dyn_notch_q: 0, + dyn_notch_min_hz: 0, }; ADVANCED_TUNING = { diff --git a/src/js/msp/MSPHelper.js b/src/js/msp/MSPHelper.js index 56b52be1..e959a487 100644 --- a/src/js/msp/MSPHelper.js +++ b/src/js/msp/MSPHelper.js @@ -987,6 +987,12 @@ MspHelper.prototype.process_data = function(dataHandler) { FILTER_CONFIG.gyro_lowpass_dyn_max_hz = data.readU16(); FILTER_CONFIG.dterm_lowpass_dyn_min_hz = data.readU16(); FILTER_CONFIG.dterm_lowpass_dyn_max_hz = data.readU16(); + if (semver.gte(CONFIG.apiVersion, "1.42.0")) { + FILTER_CONFIG.dyn_notch_range = data.readU8(); + FILTER_CONFIG.dyn_notch_width_percent = data.readU8(); + FILTER_CONFIG.dyn_notch_q = data.readU16(); + FILTER_CONFIG.dyn_notch_min_hz = data.readU16(); + } } } } @@ -1747,6 +1753,12 @@ MspHelper.prototype.crunch = function(code) { .push16(FILTER_CONFIG.dterm_lowpass_dyn_min_hz) .push16(FILTER_CONFIG.dterm_lowpass_dyn_max_hz); } + if (semver.gte(CONFIG.apiVersion, "1.42.0")) { + buffer.push8(FILTER_CONFIG.dyn_notch_range) + .push8(FILTER_CONFIG.dyn_notch_width_percent) + .push16(FILTER_CONFIG.dyn_notch_q) + .push16(FILTER_CONFIG.dyn_notch_min_hz); + } } break; case MSPCodes.MSP_SET_PID_ADVANCED: diff --git a/src/js/tabs/pid_tuning.js b/src/js/tabs/pid_tuning.js index 7cf6e6ab..7cee0600 100644 --- a/src/js/tabs/pid_tuning.js +++ b/src/js/tabs/pid_tuning.js @@ -352,8 +352,20 @@ TABS.pid_tuning.initialize = function (callback) { if (semver.gte(CONFIG.apiVersion, "1.42.0")) { $('.smartfeedforward').hide(); $('.itermRelaxCutoff').show(); + + if (FEATURE_CONFIG.features.isEnabled('DYNAMIC_FILTER')) { + $('.dynamicNotch').show(); + } else { + $('.dynamicNotch').hide(); + } + + $('.pid_filter select[name="dynamicNotchRange"]').val(FILTER_CONFIG.dyn_notch_range); + $('.pid_filter input[name="dynamicNotchWidthPercent"]').val(FILTER_CONFIG.dyn_notch_width_percent); + $('.pid_filter input[name="dynamicNotchQ"]').val(FILTER_CONFIG.dyn_notch_q); + $('.pid_filter input[name="dynamicNotchMinHz"]').val(FILTER_CONFIG.dyn_notch_min_hz); } else { $('.itermRelaxCutoff').hide(); + $('.dynamicNotch').hide(); } $('input[id="useIntegratedYaw"]').change(function() { @@ -685,6 +697,12 @@ TABS.pid_tuning.initialize = function (callback) { ADVANCED_TUNING.useIntegratedYaw = $('input[id="useIntegratedYaw"]').is(':checked') ? 1 : 0; } + if (semver.gte(CONFIG.apiVersion, "1.42.0")) { + FILTER_CONFIG.dyn_notch_range = parseInt($('.pid_filter select[name="dynamicNotchRange"]').val()); + FILTER_CONFIG.dyn_notch_width_percent = parseInt($('.pid_filter input[name="dynamicNotchWidthPercent"]').val()); + FILTER_CONFIG.dyn_notch_q = parseInt($('.pid_filter input[name="dynamicNotchQ"]').val()); + FILTER_CONFIG.dyn_notch_min_hz = parseInt($('.pid_filter input[name="dynamicNotchMinHz"]').val()); + } } function showAllPids() { @@ -1068,6 +1086,22 @@ TABS.pid_tuning.initialize = function (callback) { dtermFilterSelect.append(''); }); } + // Added in API 1.42.0 + function loadDynamicNotchRangeValues() { + var dynamicNotchRangeValues = [ + "HIGH", "MEDIUM", "LOW", "AUTO", + ]; + return dynamicNotchRangeValues; + } + function populateDynamicNotchRangeSelect(selectDynamicNotchRangeValues) { + var dynamicNotchRangeSelect = $('select[name="dynamicNotchRange"]'); + selectDynamicNotchRangeValues.forEach(function(value, key) { + dynamicNotchRangeSelect.append(''); + }); + } + if (semver.gte(CONFIG.apiVersion, "1.42.0")) { + populateDynamicNotchRangeSelect(loadDynamicNotchRangeValues()); + } populateFilterTypeSelector('gyroLowpassType', loadFilterTypeValues()); populateFilterTypeSelector('gyroLowpassDynType', loadFilterTypeValues()); diff --git a/src/tabs/pid_tuning.html b/src/tabs/pid_tuning.html index 16e94cb6..7ea4d565 100644 --- a/src/tabs/pid_tuning.html +++ b/src/tabs/pid_tuning.html @@ -888,6 +888,69 @@ + + + +
+
+
+
+ + + + + + + +
+ +
+
+ + + + + + + +
+ +
+
+ + + + + + + +
+ +
+
+ + + + + + + +
+ +
+
+ +