mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-26 17:55:24 +03:00
Change Sliders and defaults
0-1-2 ranges ff and dmax gui fixes Fix master slider Fix TODO Fix enable slider when PID has changed Fix RP mode editing manual values Restore backward compatibility Rearrange order of 4.3 sliders and add divider for expert mode d_lowpass slider range changed, 75-150 defaults Fix filter sliders Optimise FF, DMax and filter slider steps Fix doubleclick on pid sliders stop D lowpass slider position moving left on save update gyro and dterm lowpass filter messages fix some bugs Fix spacing in messages Little fixes Respect slider mode Fix legacy mode and slider values Code cleanup Add slider defaults rename dmin ratio to dmax gain Fix legacy sliders again Enable Expert Mode
This commit is contained in:
parent
2dad799a78
commit
1dbe298abd
10 changed files with 1048 additions and 508 deletions
|
@ -1,14 +1,22 @@
|
|||
'use strict';
|
||||
|
||||
const TuningSliders = {
|
||||
sliderPidsMode: 2,
|
||||
sliderMasterMultiplier: 1,
|
||||
sliderRollPitchRatio: 1,
|
||||
sliderIGain: 1,
|
||||
// Legacy Sliders
|
||||
sliderMasterMultiplierLegacy: 1,
|
||||
sliderPDRatio: 1,
|
||||
sliderPDGain: 1,
|
||||
sliderDMinRatio: 1,
|
||||
sliderFeedforwardGainLegacy: 1,
|
||||
// Firmware Sliders introduced in API 1.44
|
||||
sliderPidsMode: 2,
|
||||
sliderDGain: 1,
|
||||
sliderPIGain: 1,
|
||||
sliderFeedforwardGain: 1,
|
||||
sliderDMaxGain: 1,
|
||||
sliderIGain: 1,
|
||||
sliderRollPitchRatio: 1,
|
||||
sliderPitchPIGain: 1,
|
||||
sliderMasterMultiplier: 1,
|
||||
|
||||
pidSlidersUnavailable: false,
|
||||
GyroSliderUnavailable: false,
|
||||
DTermSliderUnavailable: false,
|
||||
|
@ -23,6 +31,8 @@ const TuningSliders = {
|
|||
defaultPDRatio: 0,
|
||||
PID_DEFAULT: [],
|
||||
FILTER_DEFAULT: {},
|
||||
SLIDER_DEFAULT: {},
|
||||
initialSettings: {},
|
||||
|
||||
cachedPidSliderValues: false,
|
||||
cachedGyroSliderValues: false,
|
||||
|
@ -33,6 +43,60 @@ const TuningSliders = {
|
|||
|
||||
const D_MIN_RATIO = 0.85;
|
||||
|
||||
TuningSliders.saveInitialSettings = function () {
|
||||
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
||||
this.initialSettings.sliderPidsMode = FC.TUNING_SLIDERS.slider_pids_mode;
|
||||
this.initialSettings.sliderDGain = FC.TUNING_SLIDERS.slider_d_gain / 100;
|
||||
this.initialSettings.sliderPIGain = FC.TUNING_SLIDERS.slider_pi_gain / 100;
|
||||
this.initialSettings.sliderFeedforwardGain = FC.TUNING_SLIDERS.slider_feedforward_gain / 100;
|
||||
this.initialSettings.sliderDMaxGain = FC.TUNING_SLIDERS.slider_dmax_gain / 100;
|
||||
this.initialSettings.sliderIGain = FC.TUNING_SLIDERS.slider_i_gain / 100;
|
||||
this.initialSettings.sliderRollPitchRatio = FC.TUNING_SLIDERS.slider_roll_pitch_ratio / 100;
|
||||
this.initialSettings.sliderPitchPIGain = FC.TUNING_SLIDERS.slider_pitch_pi_gain / 100;
|
||||
this.initialSettings.sliderMasterMultiplier = FC.TUNING_SLIDERS.slider_master_multiplier / 100;
|
||||
this.initialSettings.sliderGyroFilter = FC.TUNING_SLIDERS.slider_gyro_filter;
|
||||
this.initialSettings.sliderGyroFilterMultiplier = FC.TUNING_SLIDERS.slider_gyro_filter_multiplier / 100;
|
||||
this.initialSettings.sliderDTermFilter = FC.TUNING_SLIDERS.slider_dterm_filter;
|
||||
this.initialSettings.sliderDTermFilterMultiplier = FC.TUNING_SLIDERS.slider_dterm_filter_multiplier / 100;
|
||||
}
|
||||
};
|
||||
|
||||
TuningSliders.restoreInitialSettings = function () {
|
||||
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
||||
if (this.sliderModeHasChanged && this.initialSetting.sliderPidsMode !== this.sliderPidsmode) {
|
||||
$('#sliderPidsModeSelect').val(this.initialSettings.sliderPidsMode).trigger('change');
|
||||
}
|
||||
|
||||
FC.TUNING_SLIDERS.slider_pids_mode = this.initialSettings.sliderPidsMode;
|
||||
|
||||
FC.TUNING_SLIDERS.slider_d_gain = Math.round(this.initialSettings.sliderDGain * 20) * 5;
|
||||
FC.TUNING_SLIDERS.slider_pi_gain = Math.round(this.initialSettings.sliderPIGain * 20) * 5;
|
||||
FC.TUNING_SLIDERS.slider_feedforward_gain = Math.round(this.initialSettings.sliderFeedforwardGain * 20) * 5;
|
||||
FC.TUNING_SLIDERS.slider_dmax_gain = Math.round(this.initialSettings.sliderDMaxGain * 20) * 5;
|
||||
FC.TUNING_SLIDERS.slider_i_gain = Math.round(this.initialSettings.sliderIGain * 20) * 5;
|
||||
FC.TUNING_SLIDERS.slider_roll_pitch_ratio = Math.round(this.initialSettings.sliderRollPitchRatio * 20) * 5;
|
||||
FC.TUNING_SLIDERS.slider_pitch_pi_gain = Math.round(this.initialSettings.sliderPitchPIGain * 20) * 5;
|
||||
FC.TUNING_SLIDERS.slider_master_multiplier = Math.round(this.initialSettings.sliderMasterMultiplier * 20) * 5;
|
||||
|
||||
FC.TUNING_SLIDERS.slider_gyro_filter = this.initialSettings.sliderGyroFilter;
|
||||
FC.TUNING_SLIDERS.slider_gyro_filter_multiplier = this.initialSettings.sliderGyroFilterMultiplier * 100;
|
||||
FC.TUNING_SLIDERS.slider_dterm_filter = this.initialSettings.sliderDTermFilter;
|
||||
FC.TUNING_SLIDERS.slider_dterm_filter_multiplier = this.initialSettings.sliderDTermFilterMultiplier * 100;
|
||||
|
||||
MSP.promise(MSPCodes.MSP_SET_TUNING_SLIDERS, mspHelper.crunch(MSPCodes.MSP_SET_TUNING_SLIDERS))
|
||||
.then(() => MSP.promise(MSPCodes.MSP_PID))
|
||||
.then(() => MSP.promise(MSPCodes.MSP_PID_ADVANCED))
|
||||
.then(() => MSP.promise(MSPCodes.MSP_FILTER_CONFIG))
|
||||
.then(() => {
|
||||
TABS.pid_tuning.configChanges = {};
|
||||
if (GUI.active_tab === 'pid_tuning') {
|
||||
this.updateFormPids();
|
||||
TABS.pid_tuning.updatePIDColors();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
TuningSliders.setDMinFeatureEnabled = function(dMinFeatureEnabled) {
|
||||
this.dMinFeatureEnabled = dMinFeatureEnabled;
|
||||
if (this.dMinFeatureEnabled) {
|
||||
|
@ -45,6 +109,7 @@ TuningSliders.setDMinFeatureEnabled = function(dMinFeatureEnabled) {
|
|||
TuningSliders.initialize = function() {
|
||||
this.PID_DEFAULT = FC.getPidDefaults();
|
||||
this.FILTER_DEFAULT = FC.getFilterDefaults();
|
||||
this.SLIDER_DEFAULT = FC.getSliderDefaults();
|
||||
|
||||
if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
||||
this.setDMinFeatureEnabled($('#dMinSwitch').is(':checked'));
|
||||
|
@ -67,20 +132,27 @@ TuningSliders.initialize = function() {
|
|||
|
||||
TuningSliders.setExpertMode = function() {
|
||||
this.expertMode = isExpertModeEnabled();
|
||||
$('#slidersPidsBox, #slidersFilterBox').toggleClass('nonExpertModeSliders', !this.expertMode);
|
||||
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
||||
const dMinShow = parseInt($('.pid_tuning input[name="dMinRoll"]').val()) !== 0;
|
||||
$('.tab-pid_tuning .MasterSlider').toggle(this.expertMode);
|
||||
$('.tab-pid_tuning .DMinRatioSlider').toggle(this.expertMode && dMinShow);
|
||||
// TODO: reset nonExpertModeSliders - changes after first movement
|
||||
|
||||
$('.tab-pid_tuning .DMaxGainSlider').toggle(this.expertMode);
|
||||
$('.tab-pid_tuning .advancedSlider').toggle(this.expertMode);
|
||||
$('.tab-pid_tuning .masterSlider').toggle(this.expertMode);
|
||||
$('.tab-pid_tuning .legacySlider').hide();
|
||||
$('.subtab-pid .nonExpertModeSlidersNote').toggle(!this.pidSlidersUnavailable && !this.expertMode);
|
||||
$('.subtab-filter .nonExpertModeSlidersNote').toggle((!this.GyroSliderUnavailable || !this.DTermSliderUnavailable) && !this.expertMode);
|
||||
} else {
|
||||
$('#slidersPidsBox, #slidersFilterBox').toggleClass('nonExpertModeSliders', !this.expertMode);
|
||||
const dMinShow = parseInt($('.pid_tuning input[name="dMinRoll"]').val()) !== 0;
|
||||
$('.tab-pid_tuning .DMaxGainSlider').toggle(this.expertMode && dMinShow);
|
||||
$('.tab-pid_tuning .advancedSlider').hide();
|
||||
$('.tab-pid_tuning .DMinRatioSlider').hide();
|
||||
$('.tab-pid_tuning .DMaxGainSlider').hide();
|
||||
$('.tab-pid_tuning .baseSlider').hide();
|
||||
}
|
||||
};
|
||||
|
||||
TuningSliders.scaleSliderValue = function(value) {
|
||||
if (value > 1) {
|
||||
if (value > 0) {
|
||||
return Math.round(((value - 1) * 2 + 1) * 100) / 100;
|
||||
} else {
|
||||
return value;
|
||||
|
@ -88,7 +160,7 @@ TuningSliders.scaleSliderValue = function(value) {
|
|||
};
|
||||
|
||||
TuningSliders.downscaleSliderValue = function(value) {
|
||||
if (value > 1) {
|
||||
if (value > 0) {
|
||||
return (value - 1) / 2 + 1;
|
||||
} else {
|
||||
return value;
|
||||
|
@ -96,43 +168,56 @@ TuningSliders.downscaleSliderValue = function(value) {
|
|||
};
|
||||
|
||||
TuningSliders.initPidSlidersPosition = function() {
|
||||
if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
||||
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
||||
this.sliderPidsMode = FC.TUNING_SLIDERS.slider_pids_mode;
|
||||
this.sliderDGain = FC.TUNING_SLIDERS.slider_d_gain / 100;
|
||||
this.sliderPIGain = FC.TUNING_SLIDERS.slider_pi_gain / 100;
|
||||
this.sliderFeedforwardGain = FC.TUNING_SLIDERS.slider_feedforward_gain / 100;
|
||||
this.sliderDMaxGain = FC.TUNING_SLIDERS.slider_dmax_gain / 100;
|
||||
this.sliderIGain = FC.TUNING_SLIDERS.slider_i_gain / 100;
|
||||
this.sliderRollPitchRatio = FC.TUNING_SLIDERS.slider_roll_pitch_ratio / 100;
|
||||
this.sliderPitchPIGain = FC.TUNING_SLIDERS.slider_pitch_pi_gain / 100;
|
||||
this.sliderMasterMultiplier = FC.TUNING_SLIDERS.slider_master_multiplier / 100;
|
||||
|
||||
$('output[name="sliderDGain-number"]').val(this.sliderDGain);
|
||||
$('output[name="sliderPIGain-number"]').val(this.sliderPIGain);
|
||||
$('output[name="sliderFeedforwardGain-number"]').val(this.sliderFeedforwardGain);
|
||||
$('output[name="sliderDMaxGain-number"]').val(this.sliderDMaxGain);
|
||||
$('output[name="sliderIGain-number"]').val(this.sliderIGain);
|
||||
$('output[name="sliderRollPitchRatio-number"]').val(this.sliderRollPitchRatio);
|
||||
$('output[name="sliderPitchPIGain-number"]').val(this.sliderPitchPIGain);
|
||||
$('output[name="sliderMasterMultiplier-number"]').val(this.sliderMasterMultiplier);
|
||||
|
||||
$('#sliderDGain').val(this.downscaleSliderValue(this.sliderDGain));
|
||||
$('#sliderPIGain').val(this.downscaleSliderValue(this.sliderPIGain));
|
||||
$('#sliderFeedforwardGain').val(this.sliderFeedforwardGain);
|
||||
$('#sliderDMaxGain').val(this.sliderDMaxGain);
|
||||
$('#sliderIGain').val(this.downscaleSliderValue(this.sliderIGain));
|
||||
$('#sliderRollPitchRatio').val(this.downscaleSliderValue(this.sliderRollPitchRatio));
|
||||
$('#sliderPitchPIGain').val(this.downscaleSliderValue(this.sliderPitchPIGain));
|
||||
$('#sliderMasterMultiplier').val(this.downscaleSliderValue(this.sliderMasterMultiplier));
|
||||
} else {
|
||||
// used to estimate PID slider positions based on PIDF values, and set respective slider position
|
||||
// provides only an estimation due to limitation of feature without firmware support, to be improved in later versions
|
||||
this.sliderMasterMultiplier = Math.round(FC.PIDS[2][1] / this.PID_DEFAULT[11] * 10) / 10;
|
||||
this.sliderMasterMultiplierLegacy = Math.round(FC.PIDS[2][1] / this.PID_DEFAULT[11] * 10) / 10;
|
||||
this.sliderPDRatio = Math.round(FC.PIDS[0][2] / FC.PIDS[0][0] / this.defaultPDRatio * 10) / 10;
|
||||
if (this.dMinFeatureEnabled) {
|
||||
this.sliderPDGain = Math.round(FC.ADVANCED_TUNING.dMinRoll / this.sliderPDRatio / this.sliderMasterMultiplier / this.PID_DEFAULT[3] * 10) / 10;
|
||||
this.sliderPDGain = Math.round(FC.ADVANCED_TUNING.dMinRoll / this.sliderPDRatio / this.sliderMasterMultiplierLegacy / this.PID_DEFAULT[3] * 10) / 10;
|
||||
} else {
|
||||
this.sliderPDGain = Math.round(FC.PIDS[0][0] / this.sliderMasterMultiplier / (this.PID_DEFAULT[2] * (1 / D_MIN_RATIO)) * 10) / 10;
|
||||
this.sliderPDGain = Math.round(FC.PIDS[0][0] / this.sliderMasterMultiplierLegacy / (this.PID_DEFAULT[2] * (1 / D_MIN_RATIO)) * 10) / 10;
|
||||
}
|
||||
this.sliderFeedforwardGain = Math.round(FC.ADVANCED_TUNING.feedforwardRoll / this.sliderMasterMultiplier / this.PID_DEFAULT[4] * 10) / 10;
|
||||
} else {
|
||||
this.sliderPidsMode = FC.TUNING_SLIDERS.slider_pids_mode;
|
||||
this.sliderMasterMultiplier = FC.TUNING_SLIDERS.slider_master_multiplier / 100;
|
||||
this.sliderRollPitchRatio = FC.TUNING_SLIDERS.slider_roll_pitch_ratio / 100;
|
||||
this.sliderIGain = FC.TUNING_SLIDERS.slider_i_gain / 100;
|
||||
this.sliderPDRatio = FC.TUNING_SLIDERS.slider_pd_ratio / 100;
|
||||
this.sliderPDGain = FC.TUNING_SLIDERS.slider_pd_gain / 100;
|
||||
this.sliderDMinRatio = FC.TUNING_SLIDERS.slider_dmin_ratio / 100;
|
||||
this.sliderFeedforwardGain = FC.TUNING_SLIDERS.slider_feedforward_gain / 100;
|
||||
this.sliderFeedforwardGainLegacy = Math.round(FC.ADVANCED_TUNING.feedforwardRoll / this.sliderMasterMultiplierLegacy / this.PID_DEFAULT[4] * 10) / 10;
|
||||
|
||||
$('output[name="sliderMasterMultiplierLegacy-number"]').val(this.sliderMasterMultiplierLegacy);
|
||||
$('output[name="sliderPDRatio-number"]').val(this.sliderPDRatio);
|
||||
$('output[name="sliderPDGain-number"]').val(this.sliderPDGain);
|
||||
$('output[name="sliderFeedforwardGainLegacy-number"]').val(this.sliderFeedforwardGainLegacy);
|
||||
|
||||
$('#sliderMasterMultiplierLegacy').val(this.downscaleSliderValue(this.sliderMasterMultiplierLegacy));
|
||||
$('#sliderPDRatio').val(this.downscaleSliderValue(this.sliderPDRatio));
|
||||
$('#sliderPDGain').val(this.downscaleSliderValue(this.sliderPDGain));
|
||||
$('#sliderFeedforwardGainLegacy').val(this.downscaleSliderValue(this.sliderFeedforwardGainLegacy));
|
||||
}
|
||||
|
||||
$('output[name="sliderMasterMultiplier-number"]').val(this.sliderMasterMultiplier);
|
||||
$('output[name="sliderRollPitchRatio-number"]').val(this.sliderRollPitchRatio);
|
||||
$('output[name="sliderIGain-number"]').val(this.sliderIGain);
|
||||
$('output[name="sliderPDRatio-number"]').val(this.sliderPDRatio);
|
||||
$('output[name="sliderPDGain-number"]').val(this.sliderPDGain);
|
||||
$('output[name="sliderDMinRatio-number"]').val(this.sliderDMinRatio);
|
||||
$('output[name="sliderFeedforwardGain-number"]').val(this.sliderFeedforwardGain);
|
||||
|
||||
$('#sliderMasterMultiplier').val(this.downscaleSliderValue(this.sliderMasterMultiplier));
|
||||
$('#sliderRollPitchRatio').val(this.downscaleSliderValue(this.sliderRollPitchRatio));
|
||||
$('#sliderIGain').val(this.downscaleSliderValue(this.sliderIGain));
|
||||
$('#sliderPDRatio').val(this.downscaleSliderValue(this.sliderPDRatio));
|
||||
$('#sliderPDGain').val(this.downscaleSliderValue(this.sliderPDGain));
|
||||
$('#sliderDMinRatio').val(this.downscaleSliderValue(this.sliderDMinRatio));
|
||||
$('#sliderFeedforwardGain').val(this.downscaleSliderValue(this.sliderFeedforwardGain));
|
||||
};
|
||||
|
||||
TuningSliders.initGyroFilterSliderPosition = function() {
|
||||
|
@ -158,30 +243,57 @@ TuningSliders.initDTermFilterSliderPosition = function() {
|
|||
}
|
||||
|
||||
$('output[name="sliderDTermFilterMultiplier-number"]').val(this.sliderDTermFilterMultiplier);
|
||||
$('#sliderDTermFilterMultiplier').val(this.downscaleSliderValue(this.sliderDTermFilterMultiplier));
|
||||
$('#sliderDTermFilterMultiplier').val(this.sliderDTermFilterMultiplier);
|
||||
};
|
||||
|
||||
TuningSliders.resetDefault = function() {
|
||||
FC.TUNING_SLIDERS.slider_pids_mode = this.SLIDER_DEFAULT.slider_pids_mode;
|
||||
FC.TUNING_SLIDERS.slider_d_gain = this.SLIDER_DEFAULT.slider_d_gain;
|
||||
FC.TUNING_SLIDERS.slider_pi_gain = this.SLIDER_DEFAULT.slider_pi_gain;
|
||||
FC.TUNING_SLIDERS.slider_feedforward_gain = this.SLIDER_DEFAULT.slider_feedforward_gain;
|
||||
FC.TUNING_SLIDERS.slider_dmax_gain = this.SLIDER_DEFAULT.slider_dmax_gain;
|
||||
FC.TUNING_SLIDERS.slider_i_gain = this.SLIDER_DEFAULT.slider_i_gain;
|
||||
FC.TUNING_SLIDERS.slider_roll_pitch_ratio = this.SLIDER_DEFAULT.slider_roll_pitch_ratio;
|
||||
FC.TUNING_SLIDERS.slider_pitch_pi_gain = this.SLIDER_DEFAULT.slider_pitch_pi_gain;
|
||||
FC.TUNING_SLIDERS.slider_master_multiplier = this.SLIDER_DEFAULT.slider_master_multiplier;
|
||||
|
||||
FC.TUNING_SLIDERS.slider_gyro_filter = this.SLIDER_DEFAULT.slider_gyro_filter;
|
||||
FC.TUNING_SLIDERS.slider_gyro_filter_multiplier = this.SLIDER_DEFAULT.slider_gyro_filter_multiplier;
|
||||
FC.TUNING_SLIDERS.slider_dterm_filter = this.SLIDER_DEFAULT.slider_dterm_filter;
|
||||
FC.TUNING_SLIDERS.slider_dterm_filter_multiplier = this.SLIDER_DEFAULT.slider_dterm_filter_multiplier;
|
||||
};
|
||||
|
||||
TuningSliders.resetPidSliders = function() {
|
||||
if (!this.cachedPidSliderValues) {
|
||||
this.sliderMasterMultiplier = 1;
|
||||
this.sliderRollPitchRatio = 1;
|
||||
this.sliderIGain = 1;
|
||||
this.sliderPDRatio = 1;
|
||||
this.sliderPDGain = 1;
|
||||
this.sliderDMinRatio = 1;
|
||||
this.sliderFeedforwardGain = 1;
|
||||
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
||||
this.sliderDGain = this.SLIDER_DEFAULT.slider_d_gain / 100;
|
||||
this.sliderPIGain = this.SLIDER_DEFAULT.slider_pi_gain / 100;
|
||||
this.sliderFeedforwardGain = this.SLIDER_DEFAULT.slider_feedforward_gain / 100;
|
||||
this.sliderDMaxGain = this.SLIDER_DEFAULT.slider_dmax_gain / 100;
|
||||
this.sliderIGain = this.SLIDER_DEFAULT.slider_i_gain / 100;
|
||||
this.sliderRollPitchRatio = this.SLIDER_DEFAULT.slider_roll_pitch_ratio / 100;
|
||||
this.sliderPitchPIGain = this.SLIDER_DEFAULT.slider_pitch_pi_gain / 100;
|
||||
this.sliderMasterMultiplier = this.SLIDER_DEFAULT.slider_master_multiplier / 100;
|
||||
} else {
|
||||
this.sliderMasterMultiplierLegacy = 1;
|
||||
this.sliderPDRatio = 1;
|
||||
this.sliderPDGain = 1;
|
||||
this.sliderFeedforwardGainLegacy = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
||||
$('#sliderMasterMultiplier').val(this.downscaleSliderValue(this.sliderMasterMultiplier));
|
||||
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
||||
this.calculateNewPids();
|
||||
this.updateFormPids();
|
||||
this.initPidSlidersPosition();
|
||||
this.updatePidSlidersDisplay();
|
||||
} else {
|
||||
$('#sliderMasterMultiplierLegacy').val(this.downscaleSliderValue(this.sliderMasterMultiplierLegacy));
|
||||
$('#sliderPDRatio').val(this.downscaleSliderValue(this.sliderPDRatio));
|
||||
$('#sliderPDGain').val(this.downscaleSliderValue(this.sliderPDGain));
|
||||
$('#sliderFeedforwardGain').val(this.downscaleSliderValue(this.sliderFeedforwardGain));
|
||||
} else {
|
||||
this.initPidSlidersPosition();
|
||||
$('#sliderFeedforwardGainLegacy').val(this.downscaleSliderValue(this.sliderFeedforwardGainLegacy));
|
||||
this.calculateNewPids();
|
||||
}
|
||||
|
||||
this.calculateNewPids();
|
||||
};
|
||||
|
||||
TuningSliders.resetGyroFilterSlider = function() {
|
||||
|
@ -252,24 +364,57 @@ TuningSliders.legacyUpdateFilterSlidersDisplay = function() {
|
|||
}
|
||||
};
|
||||
|
||||
TuningSliders.updateSwitchBoxes = function() {
|
||||
const FF_SWITCH = FC.ADVANCED_TUNING.feedforwardRoll || FC.ADVANCED_TUNING.feedforwardPitch || FC.ADVANCED_TUNING.feedforwardYaw;
|
||||
$('input[id="feedforwardGroup"]').prop('checked', FF_SWITCH).trigger('change');
|
||||
|
||||
const DMIN_SWITCH = FC.PIDS[0][2] !== FC.ADVANCED_TUNING.dMinRoll || FC.PIDS[1][2] !== FC.ADVANCED_TUNING.dMinPitch || FC.PIDS[2][2] !== FC.ADVANCED_TUNING.dMinYaw;
|
||||
$('#dMinSwitch').prop('checked', DMIN_SWITCH).trigger('change');
|
||||
};
|
||||
|
||||
TuningSliders.updateSlidersWarning = function(slidersUnavailable = false) {
|
||||
const WARNING_P_GAIN = 70;
|
||||
let WARNING_I_GAIN = 120;
|
||||
const WARNING_DMAX_GAIN = 60;
|
||||
const WARNING_DMIN_GAIN = 40;
|
||||
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
||||
WARNING_I_GAIN = 2.5 * FC.PIDS[1][0];
|
||||
}
|
||||
$('.subtab-pid .slidersWarning').toggle((FC.PIDS[1][0] > WARNING_P_GAIN || FC.PIDS[1][1] > WARNING_I_GAIN || FC.PIDS[1][2] > WARNING_DMAX_GAIN ||
|
||||
FC.ADVANCED_TUNING.dMinPitch > WARNING_DMIN_GAIN) && !slidersUnavailable);
|
||||
};
|
||||
|
||||
TuningSliders.updateFilterSlidersWarning = function(gyroSliderUnavailable = false, DTermSliderUnavailable = false) {
|
||||
const WARNING_FILTER_LOW_GAIN = 0.7;
|
||||
let WARNING_FILTER_GYRO_HIGH_GAIN = 1.4;
|
||||
let WARNING_FILTER_DTERM_HIGH_GAIN = 1.4;
|
||||
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
||||
WARNING_FILTER_GYRO_HIGH_GAIN = 1.5;
|
||||
WARNING_FILTER_DTERM_HIGH_GAIN = 1.1;
|
||||
}
|
||||
$('.subtab-filter .slidersWarning').toggle(((this.sliderGyroFilterMultiplier >= WARNING_FILTER_GYRO_HIGH_GAIN ||
|
||||
this.sliderGyroFilterMultiplier <= WARNING_FILTER_LOW_GAIN) && !gyroSliderUnavailable) ||
|
||||
((this.sliderDTermFilterMultiplier >= WARNING_FILTER_DTERM_HIGH_GAIN ||
|
||||
this.sliderDTermFilterMultiplier <= WARNING_FILTER_LOW_GAIN) && !DTermSliderUnavailable));
|
||||
};
|
||||
|
||||
|
||||
TuningSliders.updatePidSlidersDisplay = function() {
|
||||
// check if pid values changed manually by comparing the current values with those calculated by the sliders,
|
||||
// if all of them are equal the values haven't been changed manually
|
||||
const WARNING_P_GAIN = 70;
|
||||
const WARNING_I_GAIN = 120;
|
||||
const WARNING_DMAX_GAIN = 60;
|
||||
const WARNING_DMIN_GAIN = 40;
|
||||
|
||||
this.pidSlidersUnavailable = false;
|
||||
|
||||
if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
||||
let rows = 3;
|
||||
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
||||
rows = FC.TUNING_SLIDERS.slider_pids_mode === 1 ? 2 : 3;
|
||||
} else {
|
||||
this.calculateNewPids(true);
|
||||
}
|
||||
|
||||
FC.PID_NAMES.forEach(function (elementPid, indexPid) {
|
||||
const pidElements = $(`.pid_tuning .${elementPid} input`);
|
||||
pidElements.each(function (indexInput) {
|
||||
if (indexPid < 3 && indexInput < 3) {
|
||||
if (indexPid < rows && indexInput < rows) {
|
||||
if (parseInt($(this).val()) !== FC.PIDS[indexPid][indexInput]) {
|
||||
TuningSliders.pidSlidersUnavailable = true;
|
||||
}
|
||||
|
@ -281,7 +426,7 @@ TuningSliders.updatePidSlidersDisplay = function() {
|
|||
this.pidSlidersUnavailable = true;
|
||||
}
|
||||
|
||||
if (!this.pidSlidersUnavailable && !semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
||||
if (!this.pidSlidersUnavailable) {
|
||||
this.cachedPidSliderValues = true;
|
||||
}
|
||||
|
||||
|
@ -294,28 +439,22 @@ TuningSliders.updatePidSlidersDisplay = function() {
|
|||
|
||||
$('.tuningPIDSliders').toggle(!this.pidSlidersUnavailable);
|
||||
$('.subtab-pid .slidersDisabled').toggle(this.pidSlidersUnavailable);
|
||||
$('.subtab-pid .nonExpertModeSlidersNote').toggle(!this.pidSlidersUnavailable && !this.expertMode && !semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44));
|
||||
$('.subtab-pid .slidersWarning').toggle((FC.PIDS[1][0] > WARNING_P_GAIN || FC.PIDS[1][1] > WARNING_I_GAIN || FC.PIDS[1][2] > WARNING_DMAX_GAIN ||
|
||||
FC.ADVANCED_TUNING.dMinPitch > WARNING_DMIN_GAIN) && !this.pidSlidersUnavailable);
|
||||
$('.subtab-pid .nonExpertModeSlidersNote').toggle(!this.pidSlidersUnavailable && !this.expertMode);
|
||||
|
||||
this.updateSlidersWarning();
|
||||
};
|
||||
|
||||
TuningSliders.updateFilterSlidersDisplay = function() {
|
||||
// check if filters changed manually by comapring current value and those based on slider position
|
||||
const WARNING_FILTER_HIGH_GAIN = 1.4;
|
||||
const WARNING_FILTER_LOW_GAIN = 0.7;
|
||||
|
||||
// check if filters changed manually by comparing current value and those based on slider position
|
||||
this.GyroSliderUnavailable = false;
|
||||
this.DTermSliderUnavailable = false;
|
||||
|
||||
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
||||
if (FC.TUNING_SLIDERS.slider_gyro_filter === 0) {
|
||||
this.GyroSliderUnavailable = true;
|
||||
}
|
||||
if (FC.TUNING_SLIDERS.slider_dterm_filter === 0) {
|
||||
this.DTermSliderUnavailable = true;
|
||||
}
|
||||
this.GyroSliderUnavailable = !FC.TUNING_SLIDERS.slider_gyro_filter;
|
||||
this.DTermSliderUnavailable = !FC.TUNING_SLIDERS.slider_dterm_filter;
|
||||
|
||||
if (parseInt($('.pid_filter input[name="gyroLowpassDynMinFrequency"]').val()) !==
|
||||
Math.round(this.FILTER_DEFAULT.gyro_lowpass_dyn_min_hz * this.sliderGyroFilterMultiplier) ||
|
||||
Math.floor(this.FILTER_DEFAULT.gyro_lowpass_dyn_min_hz * this.sliderGyroFilterMultiplier) ||
|
||||
parseInt($('.pid_filter input[name="gyroLowpassDynMaxFrequency"]').val()) !==
|
||||
Math.floor(this.FILTER_DEFAULT.gyro_lowpass_dyn_max_hz * this.sliderGyroFilterMultiplier) ||
|
||||
parseInt($('.pid_filter select[name="gyroLowpassDynType"]').val()) !== this.FILTER_DEFAULT.gyro_lowpass_type ||
|
||||
|
@ -346,7 +485,6 @@ TuningSliders.updateFilterSlidersDisplay = function() {
|
|||
this.legacyUpdateFilterSlidersDisplay();
|
||||
}
|
||||
|
||||
|
||||
if (this.GyroSliderUnavailable) {
|
||||
$('.tuningFilterSliders .sliderLabels tr:nth-child(2)').hide();
|
||||
} else {
|
||||
|
@ -362,10 +500,7 @@ TuningSliders.updateFilterSlidersDisplay = function() {
|
|||
$('.tuningFilterSliders').toggle(!(this.GyroSliderUnavailable && this.DTermSliderUnavailable));
|
||||
$('.subtab-filter .slidersDisabled').toggle(this.GyroSliderUnavailable || this.DTermSliderUnavailable);
|
||||
$('.subtab-filter .nonExpertModeSlidersNote').toggle((!this.GyroSliderUnavailable || !this.DTermSliderUnavailable) && !this.expertMode);
|
||||
$('.subtab-filter .slidersWarning').toggle(((this.sliderGyroFilterMultiplier >= WARNING_FILTER_HIGH_GAIN ||
|
||||
this.sliderGyroFilterMultiplier <= WARNING_FILTER_LOW_GAIN) && !this.GyroSliderUnavailable) ||
|
||||
((this.sliderDTermFilterMultiplier >= WARNING_FILTER_HIGH_GAIN ||
|
||||
this.sliderDTermFilterMultiplier <= WARNING_FILTER_LOW_GAIN) && !this.DTermSliderUnavailable));
|
||||
this.updateFilterSlidersWarning(this.GyroSliderUnavailable, this.DTermSliderUnavailable);
|
||||
};
|
||||
|
||||
TuningSliders.updateFormPids = function(updateSlidersOnly = false) {
|
||||
|
@ -387,14 +522,21 @@ TuningSliders.updateFormPids = function(updateSlidersOnly = false) {
|
|||
$('.pid_tuning .YAW input[name="f"]').val(FC.ADVANCED_TUNING.feedforwardYaw);
|
||||
}
|
||||
|
||||
$('output[name="sliderMasterMultiplier-number"]').val(this.sliderMasterMultiplier);
|
||||
$('output[name="sliderRollPitchRatio-number"]').val(this.sliderRollPitchRatio);
|
||||
$('output[name="sliderIGain-number"]').val(this.sliderIGain);
|
||||
$('output[name="sliderPDRatio-number"]').val(this.sliderPDRatio);
|
||||
$('output[name="sliderPDGain-number"]').val(this.sliderPDGain);
|
||||
$('output[name="sliderDMinRatio-number"]').val(this.sliderDMinRatio);
|
||||
$('output[name="sliderFeedforwardGain-number"]').val(this.sliderFeedforwardGain);
|
||||
|
||||
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
||||
$('output[name="sliderDGain-number"]').val(this.sliderDGain);
|
||||
$('output[name="sliderPIGain-number"]').val(this.sliderPIGain);
|
||||
$('output[name="sliderFeedforwardGain-number"]').val(this.sliderFeedforwardGain);
|
||||
$('output[name="sliderDMaxGain-number"]').val(this.sliderDMaxGain);
|
||||
$('output[name="sliderIGain-number"]').val(this.sliderIGain);
|
||||
$('output[name="sliderRollPitchRatio-number"]').val(this.sliderRollPitchRatio);
|
||||
$('output[name="sliderPitchPIGain-number"]').val(this.sliderPitchPIGain);
|
||||
$('output[name="sliderMasterMultiplier-number"]').val(this.sliderMasterMultiplier);
|
||||
} else {
|
||||
$('output[name="sliderMasterMultiplierLegacy-number"]').val(this.sliderMasterMultiplierLegacy);
|
||||
$('output[name="sliderPDRatio-number"]').val(this.sliderPDRatio);
|
||||
$('output[name="sliderPDGain-number"]').val(this.sliderPDGain);
|
||||
$('output[name="sliderFeedforwardGainLegacy-number"]').val(this.sliderFeedforwardGainLegacy);
|
||||
}
|
||||
};
|
||||
|
||||
TuningSliders.legacyCalculatePids = function(updateSlidersOnly = false) {
|
||||
|
@ -421,9 +563,9 @@ TuningSliders.legacyCalculatePids = function(updateSlidersOnly = false) {
|
|||
FC.PIDS[1][0] = Math.round(this.PID_DEFAULT[5] * this.sliderPDGain);
|
||||
FC.PIDS[2][0] = Math.round(this.PID_DEFAULT[10] * this.sliderPDGain);
|
||||
// feedforward
|
||||
FC.ADVANCED_TUNING.feedforwardRoll = Math.round(this.PID_DEFAULT[4] * this.sliderFeedforwardGain);
|
||||
FC.ADVANCED_TUNING.feedforwardPitch = Math.round(this.PID_DEFAULT[9] * this.sliderFeedforwardGain);
|
||||
FC.ADVANCED_TUNING.feedforwardYaw = Math.round(this.PID_DEFAULT[14] * this.sliderFeedforwardGain);
|
||||
FC.ADVANCED_TUNING.feedforwardRoll = Math.round(this.PID_DEFAULT[4] * this.sliderFeedforwardGainLegacy);
|
||||
FC.ADVANCED_TUNING.feedforwardPitch = Math.round(this.PID_DEFAULT[9] * this.sliderFeedforwardGainLegacy);
|
||||
FC.ADVANCED_TUNING.feedforwardYaw = Math.round(this.PID_DEFAULT[14] * this.sliderFeedforwardGainLegacy);
|
||||
// master slider part
|
||||
// these are not calculated anywhere other than master slider multiplier therefore set at default before every calculation
|
||||
FC.PIDS[0][1] = this.PID_DEFAULT[1];
|
||||
|
@ -436,18 +578,18 @@ TuningSliders.legacyCalculatePids = function(updateSlidersOnly = false) {
|
|||
//master slider multiplication, max value 200 for main PID values
|
||||
for (let i = 0; i < 3; i++) {
|
||||
for (let j = 0; j < 3; j++) {
|
||||
FC.PIDS[j][i] = Math.min(Math.round(FC.PIDS[j][i] * this.sliderMasterMultiplier), MAX_PID_GAIN);
|
||||
FC.PIDS[j][i] = Math.min(Math.round(FC.PIDS[j][i] * this.sliderMasterMultiplierLegacy), MAX_PID_GAIN);
|
||||
}
|
||||
}
|
||||
|
||||
FC.ADVANCED_TUNING.feedforwardRoll = Math.min(Math.round(FC.ADVANCED_TUNING.feedforwardRoll * this.sliderMasterMultiplier), MAX_FEEDFORWARD_GAIN);
|
||||
FC.ADVANCED_TUNING.feedforwardPitch = Math.min(Math.round(FC.ADVANCED_TUNING.feedforwardPitch * this.sliderMasterMultiplier), MAX_FEEDFORWARD_GAIN);
|
||||
FC.ADVANCED_TUNING.feedforwardYaw = Math.min(Math.round(FC.ADVANCED_TUNING.feedforwardYaw * this.sliderMasterMultiplier), MAX_FEEDFORWARD_GAIN);
|
||||
FC.ADVANCED_TUNING.feedforwardRoll = Math.min(Math.round(FC.ADVANCED_TUNING.feedforwardRoll * this.sliderMasterMultiplierLegacy), MAX_FEEDFORWARD_GAIN);
|
||||
FC.ADVANCED_TUNING.feedforwardPitch = Math.min(Math.round(FC.ADVANCED_TUNING.feedforwardPitch * this.sliderMasterMultiplierLegacy), MAX_FEEDFORWARD_GAIN);
|
||||
FC.ADVANCED_TUNING.feedforwardYaw = Math.min(Math.round(FC.ADVANCED_TUNING.feedforwardYaw * this.sliderMasterMultiplierLegacy), MAX_FEEDFORWARD_GAIN);
|
||||
|
||||
if (this.dMinFeatureEnabled) {
|
||||
FC.ADVANCED_TUNING.dMinRoll = Math.min(Math.round(FC.ADVANCED_TUNING.dMinRoll * this.sliderMasterMultiplier), MAX_DMIN_GAIN);
|
||||
FC.ADVANCED_TUNING.dMinPitch = Math.min(Math.round(FC.ADVANCED_TUNING.dMinPitch * this.sliderMasterMultiplier), MAX_DMIN_GAIN);
|
||||
FC.ADVANCED_TUNING.dMinYaw = Math.min(Math.round(FC.ADVANCED_TUNING.dMinYaw * this.sliderMasterMultiplier), MAX_DMIN_GAIN);
|
||||
FC.ADVANCED_TUNING.dMinRoll = Math.min(Math.round(FC.ADVANCED_TUNING.dMinRoll * this.sliderMasterMultiplierLegacy), MAX_DMIN_GAIN);
|
||||
FC.ADVANCED_TUNING.dMinPitch = Math.min(Math.round(FC.ADVANCED_TUNING.dMinPitch * this.sliderMasterMultiplierLegacy), MAX_DMIN_GAIN);
|
||||
FC.ADVANCED_TUNING.dMinYaw = Math.min(Math.round(FC.ADVANCED_TUNING.dMinYaw * this.sliderMasterMultiplierLegacy), MAX_DMIN_GAIN);
|
||||
}
|
||||
|
||||
this.updateFormPids(updateSlidersOnly);
|
||||
|
@ -458,28 +600,29 @@ TuningSliders.legacyCalculatePids = function(updateSlidersOnly = false) {
|
|||
TuningSliders.calculateNewPids = function(updateSlidersOnly = false) {
|
||||
// this is the main calculation for PID sliders, inputs are in form of slider position values
|
||||
// values get set both into forms and their respective variables
|
||||
if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
||||
this.legacyCalculatePids(updateSlidersOnly);
|
||||
}
|
||||
|
||||
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
|
||||
FC.TUNING_SLIDERS.slider_pids_mode = parseInt($('#sliderPidsModeSelect').val());
|
||||
//rounds slider values to nearies multiple of 5 and passes to the FW. Avoid dividing calc by (* x 100)/5 = 20
|
||||
FC.TUNING_SLIDERS.slider_master_multiplier = Math.round(this.sliderMasterMultiplier * 20) * 5;
|
||||
FC.TUNING_SLIDERS.slider_roll_pitch_ratio = Math.round(this.sliderRollPitchRatio * 20) * 5;
|
||||
FC.TUNING_SLIDERS.slider_i_gain = Math.round(this.sliderIGain * 20) * 5;
|
||||
FC.TUNING_SLIDERS.slider_pd_ratio = Math.round(this.sliderPDRatio * 20) * 5;
|
||||
FC.TUNING_SLIDERS.slider_pd_gain = Math.round(this.sliderPDGain * 20) * 5;
|
||||
FC.TUNING_SLIDERS.slider_dmin_ratio = Math.round(this.sliderDMinRatio * 20) * 5;
|
||||
FC.TUNING_SLIDERS.slider_d_gain = Math.round(this.sliderDGain * 20) * 5;
|
||||
FC.TUNING_SLIDERS.slider_pi_gain = Math.round(this.sliderPIGain * 20) * 5;
|
||||
FC.TUNING_SLIDERS.slider_feedforward_gain = Math.round(this.sliderFeedforwardGain * 20) * 5;
|
||||
FC.TUNING_SLIDERS.slider_dmax_gain = Math.round(this.sliderDMaxGain * 20) * 5;
|
||||
FC.TUNING_SLIDERS.slider_i_gain = Math.round(this.sliderIGain * 20) * 5;
|
||||
FC.TUNING_SLIDERS.slider_roll_pitch_ratio = Math.round(this.sliderRollPitchRatio * 20) * 5;
|
||||
FC.TUNING_SLIDERS.slider_pitch_pi_gain = Math.round(this.sliderPitchPIGain * 20) * 5;
|
||||
FC.TUNING_SLIDERS.slider_master_multiplier = Math.round(this.sliderMasterMultiplier * 20) * 5;
|
||||
|
||||
MSP.promise(MSPCodes.MSP_SET_TUNING_SLIDERS, mspHelper.crunch(MSPCodes.MSP_SET_TUNING_SLIDERS))
|
||||
.then(() => MSP.promise(MSPCodes.MSP_PID))
|
||||
.then(() => MSP.promise(MSPCodes.MSP_PID_ADVANCED))
|
||||
.then(() => {
|
||||
this.updateFormPids(updateSlidersOnly);
|
||||
TABS.pid_tuning.updatePIDColors();
|
||||
this.updateSlidersWarning();
|
||||
this.updateSwitchBoxes();
|
||||
});
|
||||
} else {
|
||||
this.legacyCalculatePids(updateSlidersOnly);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -533,10 +676,10 @@ TuningSliders.calculateNewDTermFilters = function() {
|
|||
|
||||
TuningSliders.writeFilterSliders = function () {
|
||||
MSP.promise(MSPCodes.MSP_SET_TUNING_SLIDERS, mspHelper.crunch(MSPCodes.MSP_SET_TUNING_SLIDERS))
|
||||
.then(() => MSP.promise(MSPCodes.MSP_EEPROM_WRITE))
|
||||
.then(() => MSP.promise(MSPCodes.MSP_FILTER_CONFIG))
|
||||
.then(() => {
|
||||
TuningSliders.updateLowpassValues();
|
||||
TuningSliders.updateFilterSlidersWarning();
|
||||
if (this.FilterReset) {
|
||||
this.FilterReset = false;
|
||||
this.updateFilterSlidersDisplay();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue