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

FW auto-trimming #22668

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

FW auto-trimming #22668

wants to merge 4 commits into from

Conversation

bresch
Copy link
Member

@bresch bresch commented Jan 23, 2024

Solved Problem

Trim values are used to unload the integrators from known constant disturbances. Setting them correctly improves the performance of the vehicle but those parameters are often neglected. Furthermore, re-trimming the aircraft after changing the payload is often required.

Solution

Automatically adjust the roll/pitch/yaw trim values during flight by using an average of the torque setpoint.

Algorithm:

  • average torque data during 5 seconds to obtain a "trim_estimate" (using Welford mean)
  • average torque data during 2 seconds to obtain a "trim_test" (using Welford mean)
  • update the trim if both estimates are statistically consistent (using measured variances) and the distance between them is small

Usage

  1. Set FW_ATRIM_MODE to "calibration" for the first flight. This allows the autotrim to commit the fill trim estimate back to the params
  2. During the first flight, fly large circles (bank angle < 10degrees) or straight lines for several periods of at least 7 seconds (the algorithm needs to continuously collect good data for 7 seconds to generate a valid trim estimate). You can check in listener auto_trim_status if trim_validated has non-zero values.
  3. Land and disarm to save the parameters. After this, FW_ATRIM_MODE automatically changes to "continuous" mode, where a small amount of trim is used to update the trim values after every flight.

Changelog Entry

For release notes:

Add auto-trimming for Fixed-wings
New parameter: FW_ATRIM_MODE
Documentation: https://github.com/PX4/PX4-user_guide/pull/3146

Test coverage

SITL vtol
Screenshot from 2024-01-23 16-31-09

TODO:

  • use auto-trim in FW rate controller
  • save new trim values (if specified via param)

We could also automatically set the DTRIM values if the vehicle is flown at various speeds.

Copy link
Contributor

@sfuhrer sfuhrer left a comment

Choose a reason for hiding this comment

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

The airspeed dependency would indeed be very cool to co-estimate. And we maybe only want to apply the trim that we got in level flight and not the one we estimate in climbs/descents, or at least not store it in the param in that case.
I would further consider limiting the maximum delta trim from one iteration to the next to avoid large steps in the controller (unless you handle it explicitly, the integrator will have to react), plus to add an extra protection against momentarily wrong trim estimates/estimates from short time vehicle flight states.

Do you plan to extend it to MC as well? Would that be a different module or the same? If the same then you can already drop the "FW" prefix in the module name.

msg/AutoTrimStatus.msg Outdated Show resolved Hide resolved
src/modules/fw_auto_trim/FwAutoTrim.cpp Outdated Show resolved Hide resolved
src/modules/fw_auto_trim/FwAutoTrim.hpp Outdated Show resolved Hide resolved
src/modules/fw_auto_trim/FwAutoTrim.cpp Outdated Show resolved Hide resolved
src/modules/fw_auto_trim/FwAutoTrim.cpp Outdated Show resolved Hide resolved
src/modules/fw_auto_trim/FwAutoTrim.cpp Outdated Show resolved Hide resolved
src/modules/fw_auto_trim/FwAutoTrim.cpp Outdated Show resolved Hide resolved
src/modules/fw_auto_trim/FwAutoTrim.cpp Outdated Show resolved Hide resolved
src/modules/fw_auto_trim/FwAutoTrim.cpp Outdated Show resolved Hide resolved
@sfuhrer
Copy link
Contributor

sfuhrer commented Mar 13, 2024

rebased on current main

@hamishwillee
Copy link
Contributor

Reminder - docs required for this?

@bresch
Copy link
Member Author

bresch commented Apr 2, 2024

@MaEtUgR
Copy link
Member

MaEtUgR commented Apr 13, 2024

@bresch I test flew this branch on my FunCub without airspeed and GPS in Stabilized and Manual:
https://review.px4.io/plot_app?log=600788e0-0211-4c54-8443-e42366987ea4
https://review.px4.io/plot_app?log=4c3812c4-8ca7-40d0-aa3b-08c5e23fdf83
Just flashed these commits and flew. Didn't notice a big difference. If at all it was rather mis-trimmed pulling a bit to the right in Manual mode. I also used the flaps every now and then such that you see it needing a pitch down trim in these cases. I hope this is useful. Hash doesn't match because I rebased on my land detection draft here: https://github.com/PX4/PX4-Autopilot/tree/maetugr/fixed-wing-land-detector-improvements

@hamishwillee
Copy link
Contributor

G'day, is this going into PX4 v1.15? Just planning the next couple of weeks docs work.

@ryanjAA
Copy link
Contributor

ryanjAA commented Jun 5, 2024

I'd like to get at least 50-100 flights on this across several aircraft to see some data. I'll post the logs when we can devote some time to this.

Looks great by the way.

@bresch
Copy link
Member Author

bresch commented Jun 5, 2024

@ryanjAA Would you be able to do a couple of tests?

@ryanjAA
Copy link
Contributor

ryanjAA commented Jun 5, 2024

Sure - Flight testing tomorrow and Friday - as long as everything else goes fine we can put a few tests with this on. What do you want to see and which commit, etc?

@bresch
Copy link
Member Author

bresch commented Jun 11, 2024

as long as everything else goes fine we can put a few tests with this on. What do you want to see and which commit, etc?

Thanks, just fly this PR, make at least a couple of straight lines of >7 seconds or large circles (bank angle < 10degrees).

@hamishwillee
Copy link
Contributor

Howdy, is this going into PX4 v1.15? If so, are further updates required for #3146 following work done since you created that?

@bresch
Copy link
Member Author

bresch commented Jun 25, 2024

@hamishwillee I think we'll have to wait for more flight tests before we can merge this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 👀 In review/test
Development

Successfully merging this pull request may close these issues.

5 participants