-
-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I made a new type of nonlinear filter which seems to work nicely on the d-term #748
base: master
Are you sure you want to change the base?
Conversation
Added the LULU filter as an option for D-term and gyro filter It's garbage for gyro filtering. Don't do it. Set the DTerm filter to type LULU in the CLI. Not accessible via GUI. This has been fixed to N=10 in filter.h, changeable to anything you like PROTOTYPE CODE USE AT OWN RISK
Added debug info Removed LULU on gyro
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of idea/considerations. I'm going to try this filter on a mine feature where I need a good dTerm filtering!
typedef enum { | ||
FILTER_PT1 = 0, | ||
FILTER_BIQUAD, | ||
FILTER_PT2, | ||
FILTER_PT3, | ||
FILTER_PT4, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the trailing comma is used just for these situations, to make an addition to not cause a change in an already existing line.
You should leave it there (and put one on your entry too)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix this up, thank you and appreciated!
src/main/common/filter.c
Outdated
@@ -273,3 +273,103 @@ FAST_CODE float ptnFilterApply(ptnFilter_t *filter, float input) { | |||
|
|||
return filter->state[filter->order]; | |||
} // ptnFilterApply | |||
|
|||
void luluFilterInit(luluFilter_t *filter, int N) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would create a new file dedicated to this filter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do!
src/main/cms/cms_menu_imu.c
Outdated
@@ -101,7 +104,10 @@ static const char * const cms_mixerImplTypeLabels[] = { | |||
}; | |||
|
|||
static const char * const cms_FilterType[] = { | |||
"PT1", "BIQUAD", "PT2", "PT3", "PT4", | |||
"PT1", "BIQUAD", "PT2", "PT3", "PT4" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should leave the trailing comma, is there for a reason (explained below) :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies, will fix
Fixed IMU menu Fixed trailing commas
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. |
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. |
to reduce aliasing and remove all bump sizes up to N Heavily optimized Roadmaker's algorithm
Added lulu.c to speed-optimized part of compiled code
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