Skip to content

Commit c14fd6a

Browse files
authored
Merge pull request #2415 from haslinghuis/fix_legacy_sliders_patch
Fix Legacy Tuning Slider Patch
2 parents d600bba + c832e97 commit c14fd6a

File tree

3 files changed

+49
-25
lines changed

3 files changed

+49
-25
lines changed

src/js/TuningSliders.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -321,21 +321,21 @@ TuningSliders.legacyCalculateNewPids = function() {
321321
// only used for 4.1 where calculation is not done in firmware
322322
if (this.dMinFeatureEnabled) {
323323
//dmin
324-
FC.ADVANCED_TUNING.dMinRoll = Math.floor(this.PID_DEFAULT[3] * this.sliderPDGain * this.sliderPDRatio);
325-
FC.ADVANCED_TUNING.dMinPitch = Math.floor(this.PID_DEFAULT[8] * this.sliderPDGain * this.sliderPDRatio);
324+
FC.ADVANCED_TUNING.dMinRoll = Math.round(this.PID_DEFAULT[3] * this.sliderPDGain * this.sliderPDRatio);
325+
FC.ADVANCED_TUNING.dMinPitch = Math.round(this.PID_DEFAULT[8] * this.sliderPDGain * this.sliderPDRatio);
326326
// dmax
327-
FC.PIDS[0][2] = Math.floor(this.PID_DEFAULT[2] * this.sliderPDGain * this.sliderPDRatio);
328-
FC.PIDS[1][2] = Math.floor(this.PID_DEFAULT[7] * this.sliderPDGain * this.sliderPDRatio);
327+
FC.PIDS[0][2] = Math.round(this.PID_DEFAULT[2] * this.sliderPDGain * this.sliderPDRatio);
328+
FC.PIDS[1][2] = Math.round(this.PID_DEFAULT[7] * this.sliderPDGain * this.sliderPDRatio);
329329
} else {
330330
FC.ADVANCED_TUNING.dMinRoll = 0;
331331
FC.ADVANCED_TUNING.dMinPitch = 0;
332-
FC.PIDS[0][2] = Math.floor((this.PID_DEFAULT[2] * D_MIN_RATIO) * this.sliderPDGain * this.sliderPDRatio);
333-
FC.PIDS[1][2] = Math.floor((this.PID_DEFAULT[7] * D_MIN_RATIO) * this.sliderPDGain * this.sliderPDRatio);
332+
FC.PIDS[0][2] = Math.round((this.PID_DEFAULT[2] * D_MIN_RATIO) * this.sliderPDGain * this.sliderPDRatio);
333+
FC.PIDS[1][2] = Math.round((this.PID_DEFAULT[7] * D_MIN_RATIO) * this.sliderPDGain * this.sliderPDRatio);
334334
}
335335

336-
FC.PIDS[0][0] = Math.floor(this.PID_DEFAULT[0] * this.sliderPDGain);
337-
FC.PIDS[1][0] = Math.floor(this.PID_DEFAULT[5] * this.sliderPDGain);
338-
FC.PIDS[2][0] = Math.floor(this.PID_DEFAULT[10] * this.sliderPDGain);
336+
FC.PIDS[0][0] = Math.round(this.PID_DEFAULT[0] * this.sliderPDGain);
337+
FC.PIDS[1][0] = Math.round(this.PID_DEFAULT[5] * this.sliderPDGain);
338+
FC.PIDS[2][0] = Math.round(this.PID_DEFAULT[10] * this.sliderPDGain);
339339
// ff
340340
FC.ADVANCED_TUNING.feedforwardRoll = Math.round(this.PID_DEFAULT[4] * this.sliderFFGain);
341341
FC.ADVANCED_TUNING.feedforwardPitch = Math.round(this.PID_DEFAULT[9] * this.sliderFFGain);
@@ -361,19 +361,18 @@ TuningSliders.legacyCalculateNewPids = function() {
361361
FC.ADVANCED_TUNING.feedforwardYaw = Math.min(Math.round(FC.ADVANCED_TUNING.feedforwardYaw * this.sliderMasterMultiplier), MAX_FF_GAIN);
362362

363363
if (this.dMinFeatureEnabled) {
364-
FC.ADVANCED_TUNING.dMinRoll = Math.min(Math.floor(FC.ADVANCED_TUNING.dMinRoll * this.sliderMasterMultiplier), MAX_DMIN_GAIN);
365-
FC.ADVANCED_TUNING.dMinPitch = Math.min(Math.floor(FC.ADVANCED_TUNING.dMinPitch * this.sliderMasterMultiplier), MAX_DMIN_GAIN);
366-
FC.ADVANCED_TUNING.dMinYaw = Math.min(Math.floor(FC.ADVANCED_TUNING.dMinYaw * this.sliderMasterMultiplier), MAX_DMIN_GAIN);
364+
FC.ADVANCED_TUNING.dMinRoll = Math.min(Math.round(FC.ADVANCED_TUNING.dMinRoll * this.sliderMasterMultiplier), MAX_DMIN_GAIN);
365+
FC.ADVANCED_TUNING.dMinPitch = Math.min(Math.round(FC.ADVANCED_TUNING.dMinPitch * this.sliderMasterMultiplier), MAX_DMIN_GAIN);
366+
FC.ADVANCED_TUNING.dMinYaw = Math.min(Math.round(FC.ADVANCED_TUNING.dMinYaw * this.sliderMasterMultiplier), MAX_DMIN_GAIN);
367367
}
368368

369-
this.updateFormPids();
370-
371369
$('.pid_tuning input[name="dMinRoll"]').val(FC.ADVANCED_TUNING.dMinRoll);
372370
$('.pid_tuning input[name="dMinPitch"]').val(FC.ADVANCED_TUNING.dMinPitch);
373371
$('.pid_tuning input[name="dMinYaw"]').val(FC.ADVANCED_TUNING.dMinYaw);
374372
$('.pid_tuning .ROLL input[name="f"]').val(FC.ADVANCED_TUNING.feedforwardRoll);
375373
$('.pid_tuning .PITCH input[name="f"]').val(FC.ADVANCED_TUNING.feedforwardPitch);
376374
$('.pid_tuning .YAW input[name="f"]').val(FC.ADVANCED_TUNING.feedforwardYaw);
375+
this.updateFormPids();
377376
};
378377

379378
TuningSliders.calculateNewPids = function() {
@@ -409,19 +408,18 @@ TuningSliders.calculateNewPids = function() {
409408

410409
Promise.resolve(true)
411410
.then(() => { return MSP.promise(MSPCodes.MSP_SET_TUNING_SLIDERS, mspHelper.crunch(MSPCodes.MSP_SET_TUNING_SLIDERS)); })
412-
.then(() => { return MSP.send_message(MSPCodes.MSP_SET_PID); })
413-
.then(() => { return MSP.send_message(MSPCodes.MSP_SET_PID_ADVANCED); });
411+
.then(() => { return MSP.send_message(MSPCodes.MSP_PID); })
412+
.then(() => { return MSP.send_message(MSPCodes.MSP_PID_ADVANCED); });
414413
}
415414

416-
this.updateFormPids();
417-
418415
$('.pid_tuning input[name="dMinRoll"]').val(FC.ADVANCED_TUNING.dMinRoll);
419416
$('.pid_tuning input[name="dMinPitch"]').val(FC.ADVANCED_TUNING.dMinPitch);
420417
$('.pid_tuning input[name="dMinYaw"]').val(FC.ADVANCED_TUNING.dMinYaw);
421418
$('.pid_tuning .ROLL input[name="f"]').val(FC.ADVANCED_TUNING.feedforwardRoll);
422419
$('.pid_tuning .PITCH input[name="f"]').val(FC.ADVANCED_TUNING.feedforwardPitch);
423420
$('.pid_tuning .YAW input[name="f"]').val(FC.ADVANCED_TUNING.feedforwardYaw);
424421

422+
this.updateFormPids();
425423
TABS.pid_tuning.updatePIDColors();
426424
};
427425

src/js/tabs/pid_tuning.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1803,10 +1803,36 @@ TABS.pid_tuning.initialize = function (callback) {
18031803

18041804
$('#sliderPidsModeSelect').val(FC.TUNING_SLIDERS.slider_pids_mode);
18051805

1806+
$('#dMinSwitch').change(function() {
1807+
if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
1808+
TuningSliders.setDMinFeatureEnabled($(this).is(':checked'));
1809+
// switch dmin and dmax values on dmin on/off if sliders available
1810+
if (!TuningSliders.pidSlidersUnavailable) {
1811+
if (TuningSliders.dMinFeatureEnabled) {
1812+
ADVANCED_TUNING.dMinRoll = FC.PIDs[0][2];
1813+
ADVANCED_TUNING.dMinPitch = FC.PIDs[1][2];
1814+
ADVANCED_TUNING.dMinYaw = FC.PIDs[2][2];
1815+
} else {
1816+
FC.PIDs[0][2] = ADVANCED_TUNING.dMinRoll;
1817+
FC.PIDs[1][2] = ADVANCED_TUNING.dMinPitch;
1818+
FC.PIDs[2][2] = ADVANCED_TUNING.dMinYaw;
1819+
}
1820+
TuningSliders.calculateNewPids();
1821+
}
1822+
}
1823+
});
1824+
18061825
// integrated yaw doesn't work with sliders therefore sliders are disabled
18071826
$('input[id="useIntegratedYaw"]').change(() => TuningSliders.updatePidSlidersDisplay());
18081827

1809-
const allPidTuningSliders = $('#sliderMasterMultiplier, #sliderRollPitchRatio, #sliderIGain, #sliderPDRatio, #sliderPDGain, #sliderDMinRatio, #sliderFFGain');
1828+
let allPidTuningSliders;
1829+
if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
1830+
allPidTuningSliders = $('#sliderMasterMultiplier, #sliderPDRatio, #sliderPDGain, #sliderFFGain');
1831+
$('.tab-pid_tuning .firmwareSlider').hide();
1832+
} else {
1833+
allPidTuningSliders = $('#sliderMasterMultiplier, #sliderRollPitchRatio, #sliderIGain, #sliderPDRatio, #sliderPDGain, #sliderDMinRatio, #sliderFFGain');
1834+
$('.tab-pid-tuning .firmwareSlider').show();
1835+
}
18101836

18111837
allPidTuningSliders.on('input', function() {
18121838
const slider = $(this);

src/tabs/pid_tuning.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170

171171
<!-- TUNING SLIDERS-->
172172
<div id="slidersPidsBox" class="gui_box grey topspacer tuningPIDSliders">
173-
<table class="pid_titlebar">
173+
<table class="pid_titlebar firmwareSlider">
174174
<tr>
175175
<th scope="col" class="sm-min">
176176
<select id="sliderPidsModeSelect">
@@ -208,12 +208,12 @@
208208
<div class="helpicon cf_tip" i18n_title="pidTuningMasterSliderHelp"></div>
209209
</td>
210210
</tr>
211-
<tr class="xs sliderHeaders">
211+
<tr class="xs sliderHeaders firmwareSlider">
212212
<td colspan="5">
213213
<span i18n="pidTuningPDRatioSlider"></span>
214214
</td>
215215
</tr>
216-
<tr>
216+
<tr class="firmwareSlider">
217217
<td class="sm-min">
218218
<span i18n="pidTuningRollPitchRatioSlider"/>
219219
</td>
@@ -227,7 +227,7 @@
227227
<div class="helpicon cf_tip" i18n_title="pidTuningRollPitchRatioSliderHelp"></div>
228228
</td>
229229
</tr>
230-
<tr>
230+
<tr class="firmwareSlider">
231231
<td>
232232
<span i18n="pidTuningIGainSlider"/>
233233
</td>
@@ -274,12 +274,12 @@
274274
<div class="helpicon cf_tip" i18n_title="pidTuningPDGainSliderHelp"></div>
275275
</td>
276276
</tr>
277-
<tr class="xs sliderHeaders">
277+
<tr class="xs sliderHeaders firmwareSlider">
278278
<td colspan="5">
279279
<span i18n="pidTuningResponseSlider"></span>
280280
</td>
281281
</tr>
282-
<tr>
282+
<tr class="firmwareSlider">
283283
<td class="sm-min">
284284
<span i18n="pidTuningDMinRatioSlider"/>
285285
</td>

0 commit comments

Comments
 (0)