LULU filter by C.H. Rohwer -- nonlinear filter which seems to work nicely on the d-term
Hi!
As in the title :)
It's an implementation of the LULU filter by C.H. Rohwer at a university in our country. For reference: https://en.wikipedia.org/wiki/Lulu_smoothing
I've optimized it to O(N) complexity and it seems to work OK now. It's still quite slow so check CPU use before flying.
I've enabled it on the d-term only. If anyone wants a gyro filter with this, I checked it and I don't think it's the best use of it, but perhaps my experience was not the most representative so let me know?
In the CLI or on the OSD you can set a new lowpass filter type, LULU. In the advanced PID options on the OSD, right at the end there's now a LULU N value. Set N to an appropriate value, see the CPU usage, test, repeat. It's a global N value as a two LULU filters over each other with different N values just keep the highest N value, it's the nature of the mathematics. Don't do two lulu filters, it's supposed to do nothing except add delay (assuming I implemented correctly).
I've added OSD elements and a debug trace in case someone wants to see what the D-term looks like before and after the d-term. Debug on the pitch and roll only, before and after d-term filter. The debug bit still needs to be properly tested, it was a late night.
Above is too little LULU. It makes squarewave type stuff on the d-term. N=6 .
This is a better amount of LULU, 8kpid N=12. Still not perfect, but given that this is the only static filter I use on the above in addition to dynamic filter and kalman, think that's quite alright.
If someone wants to test it, here it is. I believe the delay in the filter is approximately N+1 samples, so if you're running 8kpid with lulu_n_val at 12, that's 13/8000 = 1.625ms delay for this filter, which I believe is quite alright!
I've found my MATEKF411 target likes N=6 or N=7 at 4k pid, while my HGLRCF722 is alright with N=12 about at 8kpid. Graphs from HGLRCF722, don't have a logger on the other one.
Kind regards, pjpei
I added the changes to my repo as requested, and fixed an OSD issue I caused that didn't allow LULU to be selected as a DTERM filter from the OSD. It was only accessible via CLI.
Just a couple of idea/considerations. I'm going to try this filter on a mine feature where I need a good dTerm filtering!
Let me know how it goes! I'm unreasonably excited about this, it took me a month to test and optimize until it worked fast enough for use in a flight controller at reasonable speed.