betaflight icon indicating copy to clipboard operation
betaflight copied to clipboard

ICM42688: configurabe AA & UI Filter

Open KarateBrot opened this issue 1 year ago • 10 comments

I exposed the ICM42688 registers in the CLI to quickly change the internal gyro filter settings for testing. Only flash this PR if you know what you are doing!

The CLI command gyro_hardware_lpf is not usable and gets ignored. See "Anti-Alias-Filter" to change the setting.

ICM42688 Documentation

Signal Path

grafik

Anti-Alias-Filter

The AAF can be adjusted using the corresponding values for gyro_delt, gyro_deltsqr and gyro_bitshift from the list below. grafik Documentation - Page 28

Defaults

The default values are set up for a bandwidth of 258Hz.

CLI command Value (default)
gyro_delt 6
gyro_deltsqr 36
gyro_bitshift 10

UI-Filter

The UI-Filter can be adjusted using gyro_ui_ord and gyro_ui. gyro_ui_ord is the filter order and can be adjusted from order 1 to order 3

gyro_ui_ord Filter Order
0 1
1 2 (default)
2 3

gyro_ui adjusts the UI-Filter bandwidth according to the list below (ODR is set to 8kHz in BF).

grafik Documentation - Page 80

Defaults

CLI command Value (default)
gyro_ui 14
gyro_ui_ord 1

KarateBrot avatar Feb 05 '24 22:02 KarateBrot

Do you want to test this code? You can flash it directly from Betaflight Configurator:

  • Simply put #13351 (this pull request number) in the Select commit field of the Configurator firmware flasher tab (you need to Enable expert mode, Show release candidates and Development).

WARNING: It may be unstable. Use only for testing!

github-actions[bot] avatar Feb 05 '24 22:02 github-actions[bot]

Thanks for this @KarateBrot

What I found confusing about the UI filter GYRO_UI_FILT_BW was these tables around page 31...

It seems to me, though I'm perhaps not understanding the tables correctly, that for 8k data rates, the first order filter has a cutoff of 2096.3Hz, regardless of the value of GYRO_UI_FILT_BW, group delay 0.2ms. Surprisingly, exactly the same values exactly apply for 2nd and 3rd order variations. This implies that only some kind of decimation filter is applied, and that the UI filter is only useful for sample rates of 1kHz or less.

It would be good to confirm whether changing the GYRO_UI_FILT_BW value has any effect at 8kHz.

Out of curiosity, at what frequency do we request Acc data?

Thanks for making it to adjust the AntiaAliasing filter. I suspect that a cutoff around 170Hz or even lower may be more appropriate for our purposes than the current value. They say it is a 2nd order filter, but don't quote group delay. I guess if we had two of them bolted one on top of the other, and disabled the AAF filter on one, we could use a 'tap' test to look at the delay.

ctzsnooze avatar Feb 06 '24 03:02 ctzsnooze

@KarateBrot : Code outside of 'ICM42xx' should be gated by #ifdefs.

And is this setting usable outside testing/development? Reasonable defaults should probably be used in default case.

ledvinap avatar Feb 06 '24 09:02 ledvinap

@ledvinap This PR is just a hack for finding better ICM42688 AAF settings.

@ctzsnooze the UI filter is not that interesting for us. We normally use BF filters instead but I still exposed the settings just in case. Acc ODR is set to 1khz but we are looking into the gyro filter settings. Acc is fine as far as I am aware.

KarateBrot avatar Feb 06 '24 13:02 KarateBrot

What I found confusing about the UI filter GYRO_UI_FILT_BW was these tables around page 31...

It seems to me, though I'm perhaps not understanding the tables correctly, that for 8k data rates, the first order filter has a cutoff of 2096.3Hz, regardless of the value of GYRO_UI_FILT_BW, group delay 0.2ms. Surprisingly, exactly the same values exactly apply for 2nd and 3rd order variations. This implies that only some kind of decimation filter is applied, and that the UI filter is only useful for sample rates of 1kHz or less.

Given how it is always showing the same group delay whether first, second, or third order third order might as well be tried to see if that gives any better results at removing 2khz+ noise for little to no extra delay.

Quick-Flash avatar Feb 06 '24 17:02 Quick-Flash

This PR is very helpful, for sure.

We need some kind of test rig with dual mounted, identical, ICM42688 gyro boards, subject to the same external noise, with different filter settings on each, logging at the same time.

ctzsnooze avatar Feb 06 '24 23:02 ctzsnooze

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within a week.

github-actions[bot] avatar Mar 08 '24 04:03 github-actions[bot]

got a very positive feedback about this PR from one of the fastest pilots in US: https://www.facebook.com/groups/639226756187329?multi_permalinks=7570899036353365 image

limonspb avatar Jun 18 '24 21:06 limonspb

got a very positive feedback about this PR from one of the fastest pilots in US: https://www.facebook.com/groups/639226756187329?multi_permalinks=7570899036353365 image

the ICM42688 is generally a bit noisier than the MPU6k, and he's replaced most of the internal LPF with a PT1 at 250hz so I'm not sure about this post. I tried a bunch of different setups on this PR and in the end - the stock default values we have is the best IMO.

Its true that the ICM can fly as well or better than the MPU6k tho.

SupaflyFPV avatar Jun 19 '24 00:06 SupaflyFPV

Just tried this from one of my quads, I do see some improvements in terms of gyro/d-term noise, not huge though, but I didn't get a chance to fly a lot of full throttles, which might show bigger improvements.

qdrk avatar Jun 23 '24 05:06 qdrk