Skip to content

FW autotune improvements#6681

Merged
avsaase merged 22 commits intoiNavFlight:masterfrom
avsaase:avs-fw-autotune
May 8, 2021
Merged

FW autotune improvements#6681
avsaase merged 22 commits intoiNavFlight:masterfrom
avsaase:avs-fw-autotune

Conversation

@avsaase
Copy link
Copy Markdown
Member

@avsaase avsaase commented Mar 6, 2021

Now tested and working

This PR improves the autotune mode on fixed wing by letting autotune set the correct rates for your airplane (closes #6025). There are three autotune 'modes': with AUTO autotune will automatically adjust the max rate settings according to the capabilities of the airplane by setting the rates consistent with 80% control surface deflection. This leaves 20% room for P and I to provide stabilization. LIMIT works the same as AUTO but the rates are never increased above the starting values. This could be useful if you have a very agile plane and want to limit the rates. With FIXED the rates are not changed.

The basic algorithm is as follows. When the stick input goes above 80%, autotune for 250ms records the target rate, the realized rate, and the PID output send to the mixer. After this period it will use the maximum observed values to calculate what the rotation rate would be at 80% control surface deflection. The rate setting is then updated from the current value towards this optimal value by 10% of the difference. For example, if the current rate is 150 deg/s and it calculates the optimal rate is 300 deg/s, then the new rate is 150 + (300 - 150) * 10% = 165. The FF update work in a similar fashion, where it calculates what FF value is needed to achieve the current rate target.

Here is some dvr with the AUTO mode:

Autotune.AUTO.mode.mp4

I made AUTO the default mode because this gives rates close to what they would be in manual mode. iNavFlight/inav-configurator#1188 will set conservative default rates that any airplane will be able to achieve. If users with more agile planes tune from that starting point then the other modes will cause small servo throws. This could cause a lot of support questions.

Thanks @b14ckyy for helping with testing and ironing out the kinks in the logic 👍

Copy link
Copy Markdown
Member

@digitalentity digitalentity left a comment

Choose a reason for hiding this comment

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

LGTM!

@avsaase
Copy link
Copy Markdown
Member Author

avsaase commented Mar 8, 2021

There is still one minor issue: the blackbox logs the rate updates as events just like the FF updates, but the new rates are not reflected in the setPointRate traces (at least as displayed in the explorer). They seem to just reflect the initial rates settings. This makes it difficult to verify the tune or troubleshoot other problems if you have done an autotune during the flight. Perhaps this can be fixed in a separate PR.

@avsaase
Copy link
Copy Markdown
Member Author

avsaase commented Mar 12, 2021

I added a setting to set the D-gain relative to the P-gain but left the default at zero for now. When the weather permits I will experiment with higher fw_autotune_ff_to_p_gain and fw_autotune_p_to_d_gain = 100 with a couple different airplanes. I hope we can find decent defaults.

@avsaase
Copy link
Copy Markdown
Member Author

avsaase commented Mar 20, 2021

Would it be worthwhile to also automatically set the max acceleration settings? I keep debating this with myself but I haven't reached a conclusion. rate_accel_limit_roll_pitch would need to be split into separate roll and pitch settings of course. @DzikuVx @digitalentity?

@avsaase avsaase marked this pull request as draft March 30, 2021 18:46
@avsaase avsaase marked this pull request as ready for review April 9, 2021 11:54
# Conflicts:
#	src/main/build/debug.h
#	src/main/fc/settings.yaml
@avsaase avsaase added the Release Notes Add this when a PR needs to be mentioned in the release notes label May 8, 2021
@avsaase avsaase merged commit 23ee11e into iNavFlight:master May 8, 2021
@avsaase avsaase deleted the avs-fw-autotune branch May 8, 2021 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Release Notes Add this when a PR needs to be mentioned in the release notes Testing Required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Let INAV figure out rates on FW

2 participants