-
-
Notifications
You must be signed in to change notification settings - Fork 117
LULU filter by C.H. Rohwer -- nonlinear filter which seems to work nicely on the d-term #748
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
Draft
pjpei
wants to merge
22
commits into
emuflight:master
Choose a base branch
from
pjpei:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
47d96a4
PROTOTYPE CODE USE AT OWN RISK
pjpei 3da5808
Added OSD elements
f18c420
Fixed up #ifdef for LULU filters
5b3f7c9
Split off LULU into another file
8762e8d
Added LULU filters
e48349a
Removed MSP changes (sorry)
fe9c811
Replaced the lulu algorithm with the full Roadmaker's algorithm
195ebd1
Further optimized lulu operation
57ab476
Updated min/max functionality
7fa7b30
Updated LULU to latest version
pjpei c9fb598
Updated document spacing
pjpei a40f1dc
Fixed indentation and spacing
pjpei 30c466e
Update src/main/flight/pid.c
pjpei 2b821a8
Fixed spaces
pjpei bd65899
Update src/main/common/lulu.h
nerdCopter 0cb3179
Update src/main/common/lulu.h
nerdCopter 226311b
Update src/main/common/filter.c
nerdCopter 4887d94
Update src/main/fc/fc_core.c
nerdCopter f17f26f
Fixed gyro filter impl to original version
pjpei f442e79
Fixed minor bug in code
pjpei acfb125
Improved on algorithm
pjpei 716f095
Update src/main/io/osd.c
pjpei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,5 +77,6 @@ const char * const debugModeNames[DEBUG_COUNT] = { | |
| "IMU", | ||
| "KALMAN", | ||
| "ANGLE", | ||
| "HORIZON" | ||
| "HORIZON", | ||
| "LULU" | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,6 +96,7 @@ typedef enum { | |
| DEBUG_KALMAN, | ||
| DEBUG_ANGLE, | ||
| DEBUG_HORIZON, | ||
| DEBUG_LULU, | ||
| DEBUG_COUNT | ||
| } debugType_e; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| #include "lulu.h" | ||
|
|
||
| #include <stdbool.h> | ||
| #include <stdint.h> | ||
| #include <string.h> | ||
| #include <math.h> | ||
|
|
||
| #include "platform.h" | ||
|
|
||
| #include "common/filter.h" | ||
| #include "common/maths.h" | ||
| #include "common/utils.h" | ||
|
|
||
| #ifdef __ARM_ACLE | ||
| #include <arm_acle.h> | ||
| #endif /* __ARM_ACLE */ | ||
| #include <fenv.h> | ||
|
|
||
| void luluFilterInit(luluFilter_t *filter, int N) { | ||
| if (N > 15) { | ||
| N = 15; | ||
| } | ||
| if (N < 1) { | ||
| N = 1; | ||
| } | ||
| filter->N = N; | ||
| filter->windowSize = filter->N * 2 + 1; | ||
| filter->windowBufIndex = 0; | ||
|
|
||
| memset(filter->luluInterim, 0, sizeof(float) * (filter->windowSize)); | ||
| memset(filter->luluInterimB, 0, sizeof(float) * (filter->windowSize)); | ||
| } | ||
|
|
||
| FAST_CODE float fixRoad(float *series, float *seriesB, int index, int filterN, int windowSize) { | ||
| register float curVal = 0; | ||
| register float curValB = 0; | ||
| for (int N = 1; N <= filterN; N++) { | ||
| int indexNeg = (index + windowSize - 2 * N) % windowSize; | ||
| register int curIndex = (indexNeg + 1) % windowSize; | ||
| register float prevVal = series[indexNeg]; | ||
| register float prevValB = seriesB[indexNeg]; | ||
| register int indexPos = (curIndex + N) % windowSize; | ||
| for (int i = windowSize - 2 * N; i < windowSize - N; i++) { | ||
| if (indexPos >= windowSize) { | ||
| indexPos = 0; | ||
| } | ||
| if (curIndex >= windowSize) { | ||
| curIndex = 0; | ||
| } | ||
|
|
||
| curVal = series[curIndex]; | ||
| curValB = seriesB[curIndex]; | ||
| register float nextVal = series[indexPos]; | ||
| register float nextValB = seriesB[indexPos]; | ||
|
|
||
| if (prevVal < curVal && curVal > nextVal) { | ||
| float maxValue = MAX(prevVal, nextVal); | ||
| series[curIndex] = maxValue; | ||
| } | ||
|
|
||
| if (prevValB < curValB && curValB > nextValB) { | ||
| float maxValue = MAX(prevValB, nextValB); | ||
| seriesB[curIndex] = maxValue; | ||
| } | ||
| prevVal = curVal; | ||
| prevValB = curValB; | ||
| curIndex++; | ||
| indexPos++; | ||
| } | ||
|
|
||
| curIndex = (indexNeg + 1) % windowSize; | ||
| prevVal = series[indexNeg]; | ||
| prevValB = seriesB[indexNeg]; | ||
| indexPos = (curIndex + N) % windowSize; | ||
| for (int i = windowSize - 2 * N; i < windowSize - N; i++) { | ||
| if (indexPos >= windowSize) { | ||
| indexPos = 0; | ||
| } | ||
| if (curIndex >= windowSize) { | ||
| curIndex = 0; | ||
| } | ||
|
|
||
| curVal = series[curIndex]; | ||
| curValB = seriesB[curIndex]; | ||
| register float nextVal = series[indexPos]; | ||
| register float nextValB = seriesB[indexPos]; | ||
|
|
||
| if (prevVal > curVal && curVal < nextVal) { | ||
| float minValue = MIN(prevVal, nextVal); | ||
| series[curIndex] = minValue; | ||
| } | ||
|
|
||
| if (prevValB > curValB && curValB < nextValB) { | ||
| float minValue = MIN(prevValB, nextValB); | ||
| seriesB[curIndex] = minValue; | ||
| } | ||
| prevVal = curVal; | ||
| prevValB = curValB; | ||
| curIndex++; | ||
| indexPos++; | ||
| } | ||
| } | ||
| int finalIndex = (index + windowSize - filterN) % windowSize; | ||
| curVal = series[finalIndex]; | ||
| curValB = seriesB[finalIndex]; | ||
| return (curVal - curValB) / 2; | ||
| } | ||
|
|
||
| FAST_CODE float luluFilterPartialApply(luluFilter_t *filter, float input) { | ||
| // This is the value N of the LULU filter. | ||
| register int filterN = filter->N; | ||
| // This is the total window size for the rolling buffer | ||
| register int filterWindow = filter->windowSize; | ||
|
|
||
| register int windowIndex = filter->windowBufIndex; | ||
| register float inputVal = input; | ||
| register int newIndex = (windowIndex + 1) % filterWindow; | ||
| filter->windowBufIndex = newIndex; | ||
| filter->luluInterim[windowIndex] = inputVal; | ||
| filter->luluInterimB[windowIndex] = -inputVal; | ||
| return fixRoad(filter->luluInterim, filter->luluInterimB, windowIndex, filterN, filterWindow); | ||
| } | ||
|
|
||
| FAST_CODE float luluFilterApply(luluFilter_t *filter, float input) { | ||
| // This is the UL filter | ||
| float resultA = luluFilterPartialApply(filter, input); | ||
| // We use the median interpretation of this filter to remove bias in the output | ||
| return resultA; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #pragma once | ||
|
|
||
| //Max N = 15 | ||
| typedef struct { | ||
| int windowSize; | ||
| int windowBufIndex; | ||
| int N; | ||
| float luluInterim[32] __attribute__ ((aligned (128))); | ||
| float luluInterimB[32]; | ||
| } luluFilter_t; | ||
|
|
||
| void luluFilterInit(luluFilter_t *filter, int N); | ||
| float luluFilterApply(luluFilter_t *filter, float input); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.