Skip to content

Commit a58d7e8

Browse files
authored
Expose RPM filter settings (#5057)
* Expose RPM filter settings * Update messages
1 parent 19a2bbd commit a58d7e8

4 files changed

Lines changed: 95 additions & 2 deletions

File tree

locales/en/messages.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5011,21 +5011,33 @@
50115011
"description": "Header text for the RPM Filter group"
50125012
},
50135013
"pidTuningRpmHarmonics": {
5014-
"message": "Gyro RPM Filter Harmonics Number",
5014+
"message": "Harmonics",
50155015
"description": "Text for one of the parameters of the RPM Filter"
50165016
},
50175017
"pidTuningRpmHarmonicsHelp": {
50185018
"message": "Number of harmonics per motor. A value of 3 (recommended for most aircraft) will generate 3 notch filters, per motor for each axis, totaling 36 notches. One at the base motor frequency and two harmonics at multiples of that base frequency.",
50195019
"description": "Help text for one of the parameters of the RPM Filter"
50205020
},
50215021
"pidTuningRpmMinHz": {
5022-
"message": "Gyro RPM Filter Min Frequency [Hz]",
5022+
"message": "Min Frequency [Hz]",
50235023
"description": "Text for one of the parameters of the RPM Filter"
50245024
},
50255025
"pidTuningRpmMinHzHelp": {
50265026
"message": "Minimum frequency that will be used by the RPM Filter.",
50275027
"description": "Help text for one of the parameters of the RPM Filter"
50285028
},
5029+
"pidTuningRpmFadeRangeHz": {
5030+
"message": "Fade Range [Hz]",
5031+
"description": "Text for one of the parameters of the RPM Filter"
5032+
},
5033+
"pidTuningRpmQ": {
5034+
"message": "Q Factor",
5035+
"description": "Text for one of the parameters of the RPM Filter"
5036+
},
5037+
"pidTuningRpmWeight": {
5038+
"message": "Weight {{index}}",
5039+
"description": "Text for the per-harmonic weight parameter of the RPM Filter"
5040+
},
50295041
"pidTuningFilterSettings": {
50305042
"message": "Profile dependent Filter Settings"
50315043
},

src/components/tabs/pid-tuning/FilterSubTab.vue

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,48 @@
272272
/>
273273
</div>
274274
</div>
275+
<div
276+
v-if="rpmFilterEnabled && hasExtendedRpmFilter"
277+
class="flex flex-wrap items-end gap-3 pl-8"
278+
>
279+
<div class="flex flex-col gap-1">
280+
<span class="text-xs text-dimmed">{{ $t("pidTuningRpmQ") }}</span>
281+
<UInputNumber
282+
size="xs"
283+
orientation="vertical"
284+
class="w-16"
285+
v-model="gyro_rpm_notch_q"
286+
:step="1"
287+
:min="250"
288+
:max="3000"
289+
/>
290+
</div>
291+
<div v-for="i in gyro_rpm_notch_harmonics" :key="i" class="flex flex-col gap-1">
292+
<span class="text-xs text-dimmed">{{ $t("pidTuningRpmWeight", { index: i }) }}</span>
293+
<UInputNumber
294+
size="xs"
295+
orientation="vertical"
296+
class="w-16"
297+
:model-value="gyro_rpm_notch_weights[i - 1]"
298+
@update:model-value="setRpmWeight(i - 1, $event)"
299+
:step="1"
300+
:min="0"
301+
:max="100"
302+
/>
303+
</div>
304+
<div class="flex flex-col gap-1">
305+
<span class="text-xs text-dimmed">{{ $t("pidTuningRpmFadeRangeHz") }}</span>
306+
<UInputNumber
307+
size="xs"
308+
orientation="vertical"
309+
class="w-16"
310+
v-model="gyro_rpm_notch_fade_range_hz"
311+
:step="1"
312+
:min="0"
313+
:max="1000"
314+
/>
315+
</div>
316+
</div>
275317
</div>
276318
</template>
277319

@@ -535,6 +577,8 @@ import {
535577
NON_EXPERT_SLIDER_MIN_DTERM,
536578
NON_EXPERT_SLIDER_MAX_DTERM,
537579
} from "@/composables/useTuningSliders";
580+
import semver from "semver";
581+
import { API_VERSION_1_48 } from "@/js/data_storage";
538582
import MSP from "@/js/msp";
539583
import MSPCodes from "@/js/msp/MSPCodes";
540584
import { mspHelper } from "@/js/msp/MSPHelper";
@@ -887,6 +931,7 @@ const gyro_notch2_cutoff = computed({
887931
});
888932
889933
// RPM Filter
934+
const hasExtendedRpmFilter = computed(() => semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_48));
890935
const dshotTelemetryEnabled = computed(() => FC.MOTOR_CONFIG.use_dshot_telemetry ?? false);
891936
892937
const rpmFilterEnabled = computed({
@@ -915,6 +960,22 @@ const gyro_rpm_notch_min_hz = computed({
915960
set: (value) => (FC.FILTER_CONFIG.gyro_rpm_notch_min_hz = value),
916961
});
917962
963+
const gyro_rpm_notch_fade_range_hz = computed({
964+
get: () => FC.FILTER_CONFIG.gyro_rpm_notch_fade_range_hz ?? 0,
965+
set: (value) => (FC.FILTER_CONFIG.gyro_rpm_notch_fade_range_hz = value),
966+
});
967+
968+
const gyro_rpm_notch_q = computed({
969+
get: () => FC.FILTER_CONFIG.gyro_rpm_notch_q ?? 0,
970+
set: (value) => (FC.FILTER_CONFIG.gyro_rpm_notch_q = value),
971+
});
972+
973+
const gyro_rpm_notch_weights = computed(() => FC.FILTER_CONFIG.gyro_rpm_notch_weights ?? [0, 0, 0]);
974+
975+
function setRpmWeight(index, value) {
976+
FC.FILTER_CONFIG.gyro_rpm_notch_weights[index] = value;
977+
}
978+
918979
// Dynamic Notch Filter
919980
const dynamicNotchEnabled = computed({
920981
get: () => FC.FILTER_CONFIG.dyn_notch_count !== 0,

src/js/fc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,9 @@ const FC = {
536536
dyn_notch_count: 0,
537537
gyro_rpm_notch_harmonics: 0,
538538
gyro_rpm_notch_min_hz: 0,
539+
gyro_rpm_notch_fade_range_hz: 0,
540+
gyro_rpm_notch_q: 0,
541+
gyro_rpm_notch_weights: [0, 0, 0],
539542
};
540543

541544
this.ADVANCED_TUNING = {

src/js/msp/MSPHelper.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,15 @@ MspHelper.prototype.process_data = function (dataHandler) {
11871187
// Introduced in 1.44
11881188
FC.FILTER_CONFIG.dyn_lpf_curve_expo = data.readU8();
11891189
FC.FILTER_CONFIG.dyn_notch_count = data.readU8();
1190+
// Introduced in 1.48
1191+
if (data.remaining() >= 7) {
1192+
FC.FILTER_CONFIG.gyro_rpm_notch_fade_range_hz = data.readU16();
1193+
FC.FILTER_CONFIG.gyro_rpm_notch_q = data.readU16();
1194+
FC.FILTER_CONFIG.gyro_rpm_notch_weights = [];
1195+
for (let i = 0; i < 3; i++) {
1196+
FC.FILTER_CONFIG.gyro_rpm_notch_weights.push(data.readU8());
1197+
}
1198+
}
11901199
break;
11911200
case MSPCodes.MSP_SET_PID_ADVANCED:
11921201
console.log("Advanced PID settings saved");
@@ -2181,6 +2190,14 @@ MspHelper.prototype.crunch = function (code, modifierCode = undefined) {
21812190

21822191
// Introduced in 1.44
21832192
buffer.push8(FC.FILTER_CONFIG.dyn_lpf_curve_expo).push8(FC.FILTER_CONFIG.dyn_notch_count);
2193+
2194+
// Introduced in 1.48
2195+
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_48)) {
2196+
buffer.push16(FC.FILTER_CONFIG.gyro_rpm_notch_fade_range_hz).push16(FC.FILTER_CONFIG.gyro_rpm_notch_q);
2197+
for (let i = 0; i < 3; i++) {
2198+
buffer.push8(FC.FILTER_CONFIG.gyro_rpm_notch_weights[i]);
2199+
}
2200+
}
21842201
break;
21852202
case MSPCodes.MSP_SET_PID_ADVANCED:
21862203
buffer

0 commit comments

Comments
 (0)