Betaflight 4.2 brings some very important changes to how various tasks are processed. Especially how gyro,m filtering and PID loop are working together.

First of all, the gyro is sampled always at the gyro native speed. This means, MPU6000 will be sampled at 8kHz. Always. At the same time, PID and filtering are working as a separate task at 8kHz, 4kHz, 2kHz and so on. Depending on user configuration and MCU processing speed.

5-inch mini quad with Betaflight 4.2

Since filtering and gyro acquisition are working at different rates, data fed to the filters can suffer from an effect called aliasing. Aliasing is something nasty. It makes some frequencies appear as different frequencies and pollute the signal. There is a great article on Wikipedia about it. I was also mentioning it in my different article "PID looptime: why it is not only about frequency".

Back to the aliasing and separate test for the gyro. To fight the aliasing problem, gyro LPF 2 is the only low pass filter in Betaflight 4.2 that is executed in a gyro task. Its task is to attenuate frequencies that can cause aliasing when passed to the filter task. As a rule of thumb, gyro LPF 2 cutoff frequency gyro_lowpass2_hz should never be set above half of PID and filter frequency. Also, in case of some PID looptimes it can be disabled, and in case of some, should never be disabled.

  • PID 8kHz - gyro LPF 2 can be disabled or used freely. As gyro and filters are both working at 8kHz, there will be no aliasing at all
  • PID 4kHz - gyro LPF2 can be disabled or used. If disabled, the averaging filter will handle downsampling and mitigate aliasing effect
  • PID 2kHz - gyro LPF2 should not be disabled as averaging filter performance will decline
  • PID frequency lower than 2kHz - do not disable gyro lowpass 2 filter

As a result, such an approach will have quite a few positive effects: total CPU usage will is lower than before and looptime jitter will is smaller.

In terms of suggested PID looptimes for different MCU families, not much changes:

  • F722, F745, F465 - can run 8kHz but 4kHz is suggested
  • F405 - can run 8kHz but 4kHz is suggested
  • F411 - 2kHz is suggested. 4kHz might not be stable and might require overclocking