Skip to content
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

Calculate throttle based harmonic notch using FFT averaging #20230

Merged
merged 9 commits into from May 4, 2022

Conversation

andyp1per
Copy link
Collaborator

@andyp1per andyp1per commented Mar 6, 2022

Users struggle with harmonic notch setup. On 2Mb boards we have the possibility of using the in-flight FFT to setup the throttle-based harmonic notch. Normally the in-flight FFT can struggle to track noise peaks in noisy builds, but if the FFT's are averaged over a factor of N then the noise is reduced by 1/sqrt(N). This PR introduces the ability to average FFTs in-flight controlled by RC input (function 163). The user hovers, engages 163, hovers for some period, disengages 163 and the lands. The function will setup the appropriate harmonic notch options and scaling factors such that if the user then reboots they will have an enabled and accurate throttle-based notch.

Setup procedure:

  1. Enable the FFT - FFT_ENABLE = 1
  2. Reboot
  3. Put function 162 on an RC switch, e.g. SERVO9_OPTION = 162
  4. Make sure the servo channel is low
  5. Take off and hover
  6. Set the servo channel to high
  7. Hover for 30s or longer
  8. Set the channel to low again. The notch will have been configured and engaged at this point so you may see improvements in flight performance. To see more improvements rerun autotune
  9. You can repeat this procedure if you are not happy with the results

@amilcarlucas
Copy link
Contributor

Can you add a PR description?

@andyp1per
Copy link
Collaborator Author

Done

Copy link
Contributor

@tridge tridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider allocating when disarmed if the RCn_OPTION exists

@tridge tridge removed the DevCallEU label Mar 9, 2022
@andyp1per andyp1per force-pushed the pr-fft-average branch 2 times, most recently from 8f4f180 to dc44a0a Compare March 10, 2022 11:59
@andyp1per andyp1per requested a review from tridge March 10, 2022 13:08
@andyp1per
Copy link
Collaborator Author

@tridge I have addressed your comments and tightened up the testing. Currently it's not possible to enable the notch dynamically because it involves allocating the filters which is done at startup. It would be possible to change this to be dynamic with some work, but probably should be a separate PR and I am still not sure about creating filters in-flight. Another option would be simply to enable the notch by default but keep the reference at 0. This would allocate the data structures without them being used.

@andyp1per
Copy link
Collaborator Author

andyp1per commented Mar 10, 2022

@tridge actually making the default for INS_HNTCH_ENABLE = 1 works quite well. This seems like a good solution.

@andyp1per
Copy link
Collaborator Author

@tridge we could also consider switching on FFT by default on H7

@andyp1per andyp1per force-pushed the pr-fft-average branch 6 times, most recently from f7ac2cc to 3b000b8 Compare March 10, 2022 20:27
Copy link
Contributor

@tridge tridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to find what memory cost this is compared to master

@andyp1per andyp1per force-pushed the pr-fft-average branch 3 times, most recently from debaeb1 to acc21a8 Compare March 18, 2022 19:21
@andyp1per andyp1per force-pushed the pr-fft-average branch 2 times, most recently from 562527e to 20e7377 Compare April 23, 2022 09:31
notch tuning using FFT averaging
allocate scratch space for peak finding
return all detected peaks to caller
calculate averaged FFT frequency and enable notch
scale notch frequency down to FFT_MINHZ
calculate harmonics for averaging correctly
expose enable flag
add harmonic test for FFT averaging
reduce configuration for averaged FFT test
enable harmonic notch in-flight
allocate harmonic notch filter if FFT is enabled
@andyp1per
Copy link
Collaborator Author

Tested on my miniquad

@andyp1per
Copy link
Collaborator Author

andyp1per commented May 2, 2022

Memory on this branch:

ThreadsV2
ISR           PRI=255 sp=0x20010000 STACK=1296/1536
ArduCopter    PRI=182 sp=0x20010600 STACK=5360/7168
idle          PRI=  1 sp=0x20023E10 STACK=144/352
UART_RX       PRI= 60 sp=0x2004EE98 STACK=768/1104
OTG1          PRI= 60 sp=0x2004E5B8 STACK=264/656
monitor       PRI=183 sp=0x20020DC8 STACK=1016/1360
timer         PRI=181 sp=0x200221E8 STACK=1488/1872
rcout         PRI=181 sp=0x200218D8 STACK=432/848
rcin          PRI=177 sp=0x20021350 STACK=936/1360
io            PRI= 58 sp=0x20020440 STACK=1496/2384
storage       PRI= 59 sp=0x20021C60 STACK=832/1360
UART1         PRI= 60 sp=0x2004DE68 STACK=312/656
UART3         PRI= 60 sp=0x2004D788 STACK=248/656
UART6         PRI= 60 sp=0x2004D0A8 STACK=304/656
UART7         PRI= 60 sp=0x2004C9C8 STACK=368/656
I2C0          PRI=176 sp=0x2004AF88 STACK=904/1360
UART2         PRI= 60 sp=0x20046A38 STACK=368/656
OSD           PRI= 59 sp=0x20047128 STACK=920/1616
log_io        PRI= 59 sp=0x20047A48 STACK=1504/1912
SPI4          PRI=181 sp=0x20038DB0 STACK=720/1360
apm_fft       PRI= 58 sp=0x20037FC0 STACK=720/1360
FTP           PRI= 58 sp=0x20034BA0 STACK=1440/2896

MemInfoV1
START=0x20010000 LEN=256k FREE=  2488 LRG=  1032 TYPE=0
START=0x20000000 LEN= 64k FREE= 51232 LRG= 51176 TYPE=1

with notch tuning active:

MemInfoV1
START=0x20010000 LEN=256k FREE=  2488 LRG=  1032 TYPE=0
START=0x20000000 LEN= 64k FREE= 51232 LRG= 51176 TYPE=1

with notch tuning disabled:

MemInfoV1
START=0x20010000 LEN=256k FREE=  1976 LRG=  1032 TYPE=0
START=0x20000000 LEN= 64k FREE= 51232 LRG= 51176 TYPE=1

master:

ThreadsV2
ISR           PRI=255 sp=0x20010000 STACK=1288/1536
ArduCopter    PRI=182 sp=0x20010600 STACK=5320/7168
idle          PRI=  1 sp=0x20023E10 STACK=144/352
UART_RX       PRI= 60 sp=0x2004EE98 STACK=768/1104
OTG1          PRI= 60 sp=0x2004E5B8 STACK=264/656
monitor       PRI=183 sp=0x20020DC8 STACK=1016/1360
timer         PRI=181 sp=0x200221E8 STACK=1488/1872
rcout         PRI=181 sp=0x200218D8 STACK=432/848
rcin          PRI=177 sp=0x20021350 STACK=904/1360
io            PRI= 58 sp=0x20020440 STACK=1496/2384
storage       PRI= 59 sp=0x20021C60 STACK=832/1360
UART1         PRI= 60 sp=0x2004DE68 STACK=288/656
UART3         PRI= 60 sp=0x2004D788 STACK=248/656
UART6         PRI= 60 sp=0x2004D0A8 STACK=304/656
UART7         PRI= 60 sp=0x2004C9C8 STACK=368/656
I2C0          PRI=176 sp=0x2004AF88 STACK=904/1360
OSD           PRI= 59 sp=0x20046D18 STACK=920/1616
UART2         PRI= 60 sp=0x20047A38 STACK=368/656
log_io        PRI= 59 sp=0x20047D18 STACK=1504/1912
SPI4          PRI=181 sp=0x20038E28 STACK=720/1360
apm_fft       PRI= 58 sp=0x20037FD0 STACK=720/1360
FTP           PRI= 58 sp=0x20034BF0 STACK=1440/2896

MemInfoV1
START=0x20010000 LEN=256k FREE=  3464 LRG=  1032 TYPE=0
START=0x20000000 LEN= 64k FREE= 51232 LRG= 51176 TYPE=1

with FFT disabled:

MemInfoV1
START=0x20010000 LEN=256k FREE=  2928 LRG=   512 TYPE=0
START=0x20000000 LEN= 64k FREE= 52176 LRG= 52120 TYPE=1

So difficult to see much of an effect outside of noise

@tridge tridge merged commit e0b7e5f into ArduPilot:master May 4, 2022
@andyp1per andyp1per deleted the pr-fft-average branch May 4, 2022 07:07
@andyp1per andyp1per added the WikiNeeded needs wiki update label Jul 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants