Skip to content

Commit eaa1c05

Browse files
authored
Merge pull request #1348 from mikeller/fix_filter_settings
Fixed lowpass filter settings.
2 parents 0cf78ce + e9d83f6 commit eaa1c05

File tree

3 files changed

+53
-26
lines changed

3 files changed

+53
-26
lines changed

locales/en/messages.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,9 @@
16821682
"tuningHelp": {
16831683
"message": "<b>Tuning tips</b><br /><span class=\"message-negative\">IMPORTANT:</span> It is important to verify motor temperatures during first flights. The higher the filter value gets the better it may fly, but you also will get more noise into the motors. <br>Default value of 100Hz is optimal, but for noiser setups you can try lowering Dterm filter to 50Hz and possibly also the gyro filter."
16841684
},
1685+
"filterWarning": {
1686+
"message": "<span class=\"message-negative\"><b>Warning:</b></span> The amount of filtering you are using is dangerously low. This is likely to make the craft hard to control, and can result in flyaways. It is highly recommended that you <b>enable at least one of Gyro Dynamic Lowpass or Gyro Lowpass 1 and at least one of D Term Dynamic Lowpass or D Term Lowpass 1</b>."
1687+
},
16851688
"receiverThrottleMid": {
16861689
"message": "Throttle MID"
16871690
},

src/js/tabs/pid_tuning.js

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -382,114 +382,120 @@ TABS.pid_tuning.initialize = function (callback) {
382382
$('input[id="gyroNotch1Enabled"]').change(function() {
383383
var checked = $(this).is(':checked');
384384
var hz = FILTER_CONFIG.gyro_notch_hz > 0 ? FILTER_CONFIG.gyro_notch_hz : FILTER_DEFAULT.gyro_notch_hz;
385-
var cutoff = FILTER_CONFIG.gyro_notch_cutoff > 0 ? FILTER_CONFIG.gyro_notch_cutoff : FILTER_DEFAULT.gyro_notch_cutoff;
386385

387386
$('.pid_filter input[name="gyroNotch1Frequency"]').val(checked ? hz : 0).attr('disabled', !checked)
388387
.attr("min", checked ? 1 : 0).change();
389-
$('.pid_filter input[name="gyroNotch1Cutoff"]').val(checked ? cutoff : 0).attr('disabled', !checked).change();
388+
$('.pid_filter input[name="gyroNotch1Cutoff"]').attr('disabled', !checked).change();
390389
});
391390

392391
$('input[id="gyroNotch2Enabled"]').change(function() {
393392
var checked = $(this).is(':checked');
394393
var hz = FILTER_CONFIG.gyro_notch2_hz > 0 ? FILTER_CONFIG.gyro_notch2_hz : FILTER_DEFAULT.gyro_notch2_hz;
395-
var cutoff = FILTER_CONFIG.gyro_notch2_cutoff > 0 ? FILTER_CONFIG.gyro_notch2_cutoff : FILTER_DEFAULT.gyro_notch2_cutoff;
396394

397395
$('.pid_filter input[name="gyroNotch2Frequency"]').val(checked ? hz : 0).attr('disabled', !checked)
398396
.attr("min", checked ? 1 : 0).change();
399-
$('.pid_filter input[name="gyroNotch2Cutoff"]').val(checked ? cutoff : 0).attr('disabled', !checked).change();
397+
$('.pid_filter input[name="gyroNotch2Cutoff"]').attr('disabled', !checked).change();
400398
});
401399

402400
$('input[id="dtermNotchEnabled"]').change(function() {
403401
var checked = $(this).is(':checked');
404402
var hz = FILTER_CONFIG.dterm_notch_hz > 0 ? FILTER_CONFIG.dterm_notch_hz : FILTER_DEFAULT.dterm_notch_hz;
405-
var cutoff = FILTER_CONFIG.dterm_notch_cutoff > 0 ? FILTER_CONFIG.dterm_notch_cutoff : FILTER_DEFAULT.dterm_notch_cutoff;
406403

407404
$('.pid_filter input[name="dTermNotchFrequency"]').val(checked ? hz : 0).attr('disabled', !checked)
408405
.attr("min", checked ? 1 : 0).change();
409-
$('.pid_filter input[name="dTermNotchCutoff"]').val(checked ? cutoff : 0).attr('disabled', !checked).change();
406+
$('.pid_filter input[name="dTermNotchCutoff"]').attr('disabled', !checked).change();
410407
});
411408

412409
$('input[id="gyroLowpassEnabled"]').change(function() {
413410
var checked = $(this).is(':checked');
411+
var disabledByDynamicLowpass = $('input[id="gyroLowpassDynEnabled"]').is(':checked');
412+
414413
var cutoff = FILTER_CONFIG.gyro_lowpass_hz > 0 ? FILTER_CONFIG.gyro_lowpass_hz : FILTER_DEFAULT.gyro_lowpass_hz;
415-
var type = FILTER_CONFIG.gyro_lowpass_type > 0 ? FILTER_CONFIG.gyro_lowpass_type : FILTER_DEFAULT.gyro_lowpass_type;
414+
var type = FILTER_CONFIG.gyro_lowpass_hz > 0 ? FILTER_CONFIG.gyro_lowpass_type : FILTER_DEFAULT.gyro_lowpass_type;
416415

417-
$('.pid_filter input[name="gyroLowpassFrequency"]').val(checked ? cutoff : 0).attr('disabled', !checked);
418-
$('.pid_filter select[name="gyroLowpassType"]').val(checked ? type : 0).attr('disabled', !checked);
416+
$('.pid_filter input[name="gyroLowpassFrequency"]').val((checked || disabledByDynamicLowpass) ? cutoff : 0).attr('disabled', !checked);
417+
$('.pid_filter select[name="gyroLowpassType"]').val(type).attr('disabled', !checked);
419418

420419
if (checked) {
421420
$('input[id="gyroLowpassDynEnabled"]').prop('checked', false).change();
422421
}
423-
422+
self.updateFilterWarning();
424423
});
425424

426425
$('input[id="gyroLowpassDynEnabled"]').change(function() {
427426
var checked = $(this).is(':checked');
428427
var cutoff_min = FILTER_DEFAULT.gyro_lowpass_dyn_min_hz;
429-
var cutoff_max = FILTER_DEFAULT.gyro_lowpass_dyn_max_hz;
428+
var type = FILTER_DEFAULT.gyro_lowpass_type;
430429
if (FILTER_CONFIG.gyro_lowpass_dyn_min_hz > 0 && FILTER_CONFIG.gyro_lowpass_dyn_min_hz < FILTER_CONFIG.gyro_lowpass_dyn_max_hz) {
431430
cutoff_min = FILTER_CONFIG.gyro_lowpass_dyn_min_hz;
432-
cutoff_max = FILTER_CONFIG.gyro_lowpass_dyn_max_hz;
431+
type = FILTER_CONFIG.gyro_lowpass_type;
433432
}
434-
var type = FILTER_CONFIG.gyro_lowpass_type > 0 ? FILTER_CONFIG.gyro_lowpass_type : FILTER_DEFAULT.gyro_lowpass_type;
435433

436434
$('.pid_filter input[name="gyroLowpassDynMinFrequency"]').val(checked ? cutoff_min : 0).attr('disabled', !checked);
437435
$('.pid_filter input[name="gyroLowpassDynMaxFrequency"]').attr('disabled', !checked);
438-
$('.pid_filter select[name="gyroLowpassDynType"]').val(checked ? type : 0).attr('disabled', !checked);
436+
$('.pid_filter select[name="gyroLowpassDynType"]').val(type).attr('disabled', !checked);
439437

440438
if (checked) {
441439
$('input[id="gyroLowpassEnabled"]').prop('checked', false).change();
440+
} else if (FILTER_CONFIG.gyro_lowpass_hz > 0 && !$('input[id="gyroLowpassEnabled"]').is(':checked')) {
441+
$('input[id="gyroLowpassEnabled"]').prop('checked', true).change();
442442
}
443+
self.updateFilterWarning();
443444
});
444445

445446
$('input[id="gyroLowpass2Enabled"]').change(function() {
446447
var checked = $(this).is(':checked');
447448
var cutoff = FILTER_CONFIG.gyro_lowpass2_hz > 0 ? FILTER_CONFIG.gyro_lowpass2_hz : FILTER_DEFAULT.gyro_lowpass2_hz;
448-
var type = FILTER_CONFIG.gyro_lowpass2_type > 0 ? FILTER_CONFIG.gyro_lowpass2_type : FILTER_DEFAULT.gyro_lowpass2_type;
449+
var type = FILTER_CONFIG.gyro_lowpass2_hz > 0 ? FILTER_CONFIG.gyro_lowpass2_type : FILTER_DEFAULT.gyro_lowpass2_type;
449450

450451
$('.pid_filter input[name="gyroLowpass2Frequency"]').val(checked ? cutoff : 0).attr('disabled', !checked);
451-
$('.pid_filter select[name="gyroLowpass2Type"]').val(checked ? type : 0).attr('disabled', !checked);
452+
$('.pid_filter select[name="gyroLowpass2Type"]').val(type).attr('disabled', !checked);
452453
});
453454

454455
$('input[id="dtermLowpassEnabled"]').change(function() {
455456
var checked = $(this).is(':checked');
457+
var disabledByDynamicLowpass = $('input[id="dtermLowpassDynEnabled"]').is(':checked');
458+
456459
var cutoff = FILTER_CONFIG.dterm_lowpass_hz > 0 ? FILTER_CONFIG.dterm_lowpass_hz : FILTER_DEFAULT.dterm_lowpass_hz;
457-
var type = FILTER_CONFIG.dterm_lowpass_type > 0 ? FILTER_CONFIG.dterm_lowpass_type : FILTER_DEFAULT.dterm_lowpass_type;
460+
var type = FILTER_CONFIG.dterm_lowpass_hz > 0 ? FILTER_CONFIG.dterm_lowpass_type : FILTER_DEFAULT.dterm_lowpass_type;
458461

459-
$('.pid_filter input[name="dtermLowpassFrequency"]').val(checked ? cutoff : 0).attr('disabled', !checked);
460-
$('.pid_filter select[name="dtermLowpassType"]').val(checked ? type : 0).attr('disabled', !checked);
462+
$('.pid_filter input[name="dtermLowpassFrequency"]').val((checked || disabledByDynamicLowpass) ? cutoff : 0).attr('disabled', !checked);
463+
$('.pid_filter select[name="dtermLowpassType"]').val(type).attr('disabled', !checked);
461464

462465
if (checked) {
463466
$('input[id="dtermLowpassDynEnabled"]').prop('checked', false).change();
464467
}
468+
self.updateFilterWarning();
465469
});
466470

467471
$('input[id="dtermLowpassDynEnabled"]').change(function() {
468472
var checked = $(this).is(':checked');
469473
var cutoff_min = FILTER_DEFAULT.dterm_lowpass_dyn_min_hz;
470-
var cutoff_max = FILTER_DEFAULT.dterm_lowpass_dyn_max_hz;
474+
var type = FILTER_DEFAULT.dterm_lowpass_type;
471475
if (FILTER_CONFIG.dterm_lowpass_dyn_min_hz > 0 && FILTER_CONFIG.dterm_lowpass_dyn_min_hz < FILTER_CONFIG.dterm_lowpass_dyn_max_hz) {
472476
cutoff_min = FILTER_CONFIG.dterm_lowpass_dyn_min_hz;
473-
cutoff_max = FILTER_CONFIG.dterm_lowpass_dyn_max_hz;
477+
type = FILTER_CONFIG.dterm_lowpass_type;
474478
}
475-
var type = FILTER_CONFIG.dterm_lowpass_type > 0 ? FILTER_CONFIG.dterm_lowpass_type : FILTER_DEFAULT.dterm_lowpass_type;
476479

477480
$('.pid_filter input[name="dtermLowpassDynMinFrequency"]').val(checked ? cutoff_min : 0).attr('disabled', !checked);
478-
$('.pid_filter input[name="dtermLowpassDynMaxFrequency"]').val(checked ? cutoff_max : 0).attr('disabled', !checked);
479-
$('.pid_filter select[name="dtermLowpassDynType"]').val(checked ? type : 0).attr('disabled', !checked);
481+
$('.pid_filter input[name="dtermLowpassDynMaxFrequency"]').attr('disabled', !checked);
482+
$('.pid_filter select[name="dtermLowpassDynType"]').val(type).attr('disabled', !checked);
480483

481484
if (checked) {
482485
$('input[id="dtermLowpassEnabled"]').prop('checked', false).change();
486+
} else if (FILTER_CONFIG.dterm_lowpass_hz > 0 && !$('input[id="dtermLowpassEnabled"]').is(':checked')) {
487+
$('input[id="dtermLowpassEnabled"]').prop('checked', true).change();
483488
}
489+
self.updateFilterWarning();
484490
});
485491

486492
$('input[id="dtermLowpass2Enabled"]').change(function() {
487493
var checked = $(this).is(':checked');
488494
var cutoff = FILTER_CONFIG.dterm_lowpass2_hz > 0 ? FILTER_CONFIG.dterm_lowpass2_hz : FILTER_DEFAULT.dterm_lowpass2_hz;
489-
var type = FILTER_CONFIG.dterm_lowpass2_type > 0 ? FILTER_CONFIG.dterm_lowpass2_type : FILTER_DEFAULT.dterm_lowpass2_type;
495+
var type = FILTER_CONFIG.dterm_lowpass2_hz > 0 ? FILTER_CONFIG.dterm_lowpass2_type : FILTER_DEFAULT.dterm_lowpass2_type;
490496

491497
$('.pid_filter input[name="dtermLowpass2Frequency"]').val(checked ? cutoff : 0).attr('disabled', !checked);
492-
$('.pid_filter select[name="dtermLowpass2Type"]').val(checked ? type : 0).attr('disabled', !checked);
498+
$('.pid_filter select[name="dtermLowpass2Type"]').val(type).attr('disabled', !checked);
493499
});
494500

495501
$('input[id="yawLowpassEnabled"]').change(function() {
@@ -1759,3 +1765,16 @@ TABS.pid_tuning.updateRatesLabels = function() {
17591765
}
17601766
}
17611767
};
1768+
1769+
TABS.pid_tuning.updateFilterWarning = function() {
1770+
var gyroDynamicLowpassEnabled = $('input[id="gyroLowpassDynEnabled"]').is(':checked');
1771+
var gyroLowpass1Enabled = $('input[id="gyroLowpassEnabled"]').is(':checked');
1772+
var dtermDynamicLowpassEnabled = $('input[id="dtermLowpassDynEnabled"]').is(':checked');
1773+
var dtermLowpass1Enabled = $('input[id="dtermLowpassEnabled"]').is(':checked');
1774+
var warning_e = $('#pid-tuning .filterWarning');
1775+
if (!(gyroDynamicLowpassEnabled || gyroLowpass1Enabled) || !(dtermDynamicLowpassEnabled || dtermLowpass1Enabled)) {
1776+
warning_e.show();
1777+
} else {
1778+
warning_e.hide();
1779+
}
1780+
}

src/tabs/pid_tuning.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,11 @@
684684
<p i18n="tuningHelp"></p>
685685
</div>
686686
</div>
687+
<div class="note topspacer filterWarning" style="margin-top: 0px;">
688+
<div class="note_spacer">
689+
<p i18n="filterWarning"></p>
690+
</div>
691+
</div>
687692

688693
<div class="cf_column two_columns">
689694
<div class="gui_box grey topspacer pid_filter two_columns_first">

0 commit comments

Comments
 (0)