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

APM_Control: add AP_FW_Controller as common base class to roll and pitch controlers #27747

Merged
merged 8 commits into from
Feb 3, 2025

Conversation

IamPete1
Copy link
Member

@IamPete1 IamPete1 commented Aug 4, 2024

This moves to a shared base class between the plane roll and pitch controllers, there is lots of shared code which was duplicated. This helps with future tidyups as they now only need to happen in one place.

@IamPete1 IamPete1 added the Plane label Aug 4, 2024
@IamPete1
Copy link
Member Author

IamPete1 commented Aug 4, 2024

This is a example of something it would simplify. #27694

@peterbarker
Copy link
Contributor

I tried this on for size and got bounced: #22023

"Needs a lot of testing" was not the only comment made.

From the meeting notes:

UTC0016 - [APM_Control: factor out an AP_PitchRollController base class by peterbarker · Pull Request #22023 · ArduPilot/ardupilot · GitHub](https://github.com/ArduPilot/ardupilot/pull/22023/files)

    Parameter conversion
    Check scale factor
    Pitch tracking in TECS

... and it was also stated that increasing complexity in this area was not wanted and burning those extra bytes was fine.

@timtuxworth
Copy link
Contributor

This is awesome. It's a very nice structural change that should make some other things much easier in future.

@IamPete1 IamPete1 force-pushed the APM_Control_fw_base branch from efa7a8e to 209cd68 Compare November 8, 2024 14:00
@IamPete1
Copy link
Member Author

IamPete1 commented Nov 8, 2024

Rebased and added enum for autotune type so the autotune_start function can be in the base class. Still need to come-up with a test to prove correctness.

@robustini
Copy link
Contributor

Thanks Peter, this would be great for a smoother management evolution of automatic controls in the future.

@IamPete1 IamPete1 force-pushed the APM_Control_fw_base branch 2 times, most recently from cce4107 to 755b9ac Compare January 16, 2025 00:26
@IamPete1
Copy link
Member Author

I have added a test that runs a 60 second chirp through the roll and pitch controllers. This is then run in a test matrix with a range of roll/pitch/airspeed/flags. Total runs of 882 (441 for roll and 441 for pitch). The sweep is dumped to a csv with time, angle error, output, rate target, rate actual, rate error, P, I D, FF, DFF, DMod, slew rate, limit flag, PD limit flag, reset flag and I term set flag. The floating point values are printed to four decimal places. There is no change in these output files with the rework.

A plot of one run using the included python:
image

image

image

image

image

@Ryanf55
Copy link
Collaborator

Ryanf55 commented Jan 20, 2025

Nice cut on H743!

Binary Name      Text [B]         Data [B]     BSS (B)      Total Flash Change [B] (%)      Flash Free After PR (B)
---------------  ---------------  -----------  -----------  ----------------------------  -------------------------
arducopter-heli  0 (0.0000%)      0 (0.0000%)  0 (0.0000%)  0 (0.0000%)                                      120344
antennatracker   0 (0.0000%)      0 (0.0000%)  0 (0.0000%)  0 (0.0000%)                                      548160
arducopter       0 (0.0000%)      0 (0.0000%)  0 (0.0000%)  0 (0.0000%)                                      118840
ardurover        0 (0.0000%)      0 (0.0000%)  0 (0.0000%)  0 (0.0000%)                                      [26](https://github.com/ArduPilot/ardupilot/actions/runs/12799510722/job/35685705920?pr=27747#step:10:27)4632
arduplane        -568 (-0.0363%)  0 (0.0000%)  0 (0.0000%)  -568 (-0.0362%)                                  136864
blimp            0 (0.0000%)      0 (0.0000%)  0 (0.0000%)  0 (0.0000%)                                      5[27](https://github.com/ArduPilot/ardupilot/actions/runs/12799510722/job/35685705920?pr=27747#step:10:28)156
ardusub          0 (0.0000%)      0 (0.0000%)  0 (0.0000%)  0 (0.0000%)                                      311404

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.

I'd like to see some manual testing on:

  • inverted flight
  • auto-tune

@IamPete1 IamPete1 force-pushed the APM_Control_fw_base branch 2 times, most recently from f42c303 to faee37b Compare February 1, 2025 16:05
@IamPete1
Copy link
Member Author

IamPete1 commented Feb 1, 2025

  • inverted flight

Wider range of roll and pitch added to the test sweep. Roll from -170 to +180 in 10 get steps, pitch from -80 to + 80 in 10 deg steps. This brings the total number of test runs to 11016, still no change in output.

@IamPete1 IamPete1 force-pushed the APM_Control_fw_base branch from c7bbc65 to 244248f Compare February 2, 2025 14:11
@IamPete1
Copy link
Member Author

IamPete1 commented Feb 2, 2025

  • auto-tune

Added results checking to the existing autotest. Roll is very consistent, values within 2% every time. Pitch is not, there seems to be three solutions for P and two for D. There is no change as a result of this PR, but we might want to look into it...

…mter is withing a given percentage of the expected value
@IamPete1 IamPete1 force-pushed the APM_Control_fw_base branch from 244248f to e944e73 Compare February 2, 2025 14:54
@IamPete1
Copy link
Member Author

IamPete1 commented Feb 2, 2025

I have added some more cases to the pitch result checker, I ran it 25 times localy and got this:
image

No guarantees that it won't fail occasionally, but it does seem to be a genuine problem that we should try and understand, roll is the same every time.

@tridge tridge merged commit 31fe3d3 into ArduPilot:master Feb 3, 2025
100 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants