From 23d0a8eb5f3fce03e682b756aaad4236685b6ac2 Mon Sep 17 00:00:00 2001 From: mikeller Date: Wed, 12 Oct 2016 01:48:03 +1300 Subject: [PATCH] Added gyro notch 2 filter. --- _locales/en/messages.json | 18 ++++++++++++------ js/fc.js | 8 +++++--- js/msp/MSPHelper.js | 17 ++++++++++++----- tabs/pid_tuning.html | 34 ++++++++++++++++++++++++++++++---- tabs/pid_tuning.js | 16 ++++++++++++---- 5 files changed, 71 insertions(+), 22 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index a24f8b60..576d2baa 100755 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1649,16 +1649,22 @@ "pidTuningGyroLowpassFrequencyHelp": { "message": "Gyro Soft Lowpass Frequency (Hz)" }, - "pidTuningGyroNotchFrequency": { - "message": "Gyro Notch Filter Frequency (Hz)" + "pidTuningGyroNotch1Frequency": { + "message": "Gyro Notch Filter 1 Frequency (Hz)" + }, + "pidTuningGyroNotch2Frequency": { + "message": "Gyro Notch Filter 2 Frequency (Hz)" }, "pidTuningGyroNotchFrequencyHelp": { "message": "Gyro Notch Filter Frequency in Hz (0 means disabled)" }, - "pidTuningGyroNotchCutoff": { - "message": "Gyro Notch Filter Cutoff Frequency (Hz)" - }, - "pidTuningGyroNotchCutoffHelp": { + "pidTuningGyroNotch1Cutoff": { + "message": "Gyro Notch Filter Cutoff 1 Frequency (Hz)" + }, + "pidTuningGyroNotch2Cutoff": { + "message": "Gyro Notch Filter Cutoff 2 Frequency (Hz)" + }, + "pidTuningGyroNotchCutoffHelp": { "message": "Gyro Notch Filter Cutoff Frequency in Hz (This is where notch filter starts. For example with notch filter 160 and notch hz of 260 it means the range is 160-360hz with most attenuation around center)" }, "pidTuningFilterSettings": { diff --git a/js/fc.js b/js/fc.js index bd237c23..6c533989 100644 --- a/js/fc.js +++ b/js/fc.js @@ -261,10 +261,12 @@ var FC = { gyro_soft_lpf_hz: 0, dterm_lpf_hz: 0, yaw_lpf_hz: 0, - gyro_soft_notch_hz: 0, - gyro_soft_notch_cutoff: 0, + gyro_soft_notch_hz_1: 0, + gyro_soft_notch_cutoff_1: 0, dterm_notch_hz: 0, - dterm_notch_cutoff: 0 + dterm_notch_cutoff: 0, + gyro_soft_notch_hz_2: 0, + gyro_soft_notch_cutoff_2: 0 }; ADVANCED_TUNING = { diff --git a/js/msp/MSPHelper.js b/js/msp/MSPHelper.js index 222c0f00..85e86cb9 100644 --- a/js/msp/MSPHelper.js +++ b/js/msp/MSPHelper.js @@ -591,13 +591,16 @@ MspHelper.prototype.process_data = function(dataHandler) { FILTER_CONFIG.dterm_lpf_hz = data.readU16(); FILTER_CONFIG.yaw_lpf_hz = data.readU16(); if (semver.gte(CONFIG.apiVersion, "1.20.0")) { - FILTER_CONFIG.gyro_soft_notch_hz = data.readU16(); - FILTER_CONFIG.gyro_soft_notch_cutoff = data.readU16(); + FILTER_CONFIG.gyro_soft_notch_hz_1 = data.readU16(); + FILTER_CONFIG.gyro_soft_notch_cutoff_1 = data.readU16(); FILTER_CONFIG.dterm_notch_hz = data.readU16(); FILTER_CONFIG.dterm_notch_cutoff = data.readU16(); + if (semver.gte(CONFIG.apiVersion, "1.21.0")) { + FILTER_CONFIG.gyro_soft_notch_hz_2 = data.readU16(); + FILTER_CONFIG.gyro_soft_notch_cutoff_2 = data.readU16(); + } } break; - case MSPCodes.MSP_SET_PID_ADVANCED: console.log("Advanced PID settings saved"); break; @@ -1124,10 +1127,14 @@ MspHelper.prototype.crunch = function(code) { .push16(FILTER_CONFIG.dterm_lpf_hz) .push16(FILTER_CONFIG.yaw_lpf_hz); if (semver.gte(CONFIG.apiVersion, "1.20.0")) { - buffer.push16(FILTER_CONFIG.gyro_soft_notch_hz) - .push16(FILTER_CONFIG.gyro_soft_notch_cutoff) + buffer.push16(FILTER_CONFIG.gyro_soft_notch_hz_1) + .push16(FILTER_CONFIG.gyro_soft_notch_cutoff_1) .push16(FILTER_CONFIG.dterm_notch_hz) .push16(FILTER_CONFIG.dterm_notch_cutoff); + if (semver.gte(CONFIG.apiVersion, "1.21.0")) { + buffer.push16(FILTER_CONFIG.gyro_soft_notch_hz_2) + .push16(FILTER_CONFIG.gyro_soft_notch_cutoff_2) + } } break; case MSPCodes.MSP_SET_PID_ADVANCED: diff --git a/tabs/pid_tuning.html b/tabs/pid_tuning.html index c9d34ba1..579e2110 100755 --- a/tabs/pid_tuning.html +++ b/tabs/pid_tuning.html @@ -444,12 +444,12 @@ - +
@@ -457,12 +457,38 @@ - +
+
+
+ + + + + + + +
+ +
+
+ + + + + + + +
+
diff --git a/tabs/pid_tuning.js b/tabs/pid_tuning.js index 89310899..19ee2962 100755 --- a/tabs/pid_tuning.js +++ b/tabs/pid_tuning.js @@ -247,8 +247,8 @@ TABS.pid_tuning.initialize = function (callback) { } if (semver.gte(CONFIG.flightControllerVersion, '3.0.0')) { - $('.pid_filter input[name="gyroNotchFrequency"]').val(FILTER_CONFIG.gyro_soft_notch_hz); - $('.pid_filter input[name="gyroNotchCutoff"]').val(FILTER_CONFIG.gyro_soft_notch_cutoff); + $('.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); $('.pid_filter input[name="dTermNotchFrequency"]').val(FILTER_CONFIG.dterm_notch_hz); $('.pid_filter input[name="dTermNotchCutoff"]').val(FILTER_CONFIG.dterm_notch_cutoff); @@ -257,6 +257,10 @@ TABS.pid_tuning.initialize = function (callback) { $('input[name="dtermSetpoint-number"]').val(ADVANCED_TUNING.dtermSetpointWeight / 100); $('input[name="dtermSetpoint-range"]').val(ADVANCED_TUNING.dtermSetpointWeight / 100); + 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 .newFilter').hide(); } @@ -356,10 +360,14 @@ TABS.pid_tuning.initialize = function (callback) { ADVANCED_TUNING.ptermSetpointWeight = parseInt($('input[name="ptermSetpoint-number"]').val() * 100); ADVANCED_TUNING.dtermSetpointWeight = parseInt($('input[name="dtermSetpoint-number"]').val() * 100); - FILTER_CONFIG.gyro_soft_notch_hz = parseInt($('.pid_filter input[name="gyroNotchFrequency"]').val()); - FILTER_CONFIG.gyro_soft_notch_cutoff = parseInt($('.pid_filter input[name="gyroNotchCutoff"]').val()); + 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()); FILTER_CONFIG.dterm_notch_hz = parseInt($('.pid_filter input[name="dTermNotchFrequency"]').val()); FILTER_CONFIG.dterm_notch_cutoff = parseInt($('.pid_filter input[name="dTermNotchCutoff"]').val()); + 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()); + } } }