Skip to content

AC_AutoTune: use radians and convert the twitch measurements to the test direction once - #35058

Merged
rmackay9 merged 2 commits into
ArduPilot:masterfrom
lthall:20261108_AutoTune_cd_to_rad
Nov 17, 2026
Merged

rmackay9 merged 2 commits into
ArduPilot:masterfrom
lthall:20261108_AutoTune_cd_to_rad

Conversation

@lthall

@lthall lthall commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Convert the Multi AutoTune twitch tests and the shared AutoTune state from centidegrees to radians, then convert the twitch measurements to the test direction once.

Classification & Testing (check all that apply and add your own)

  • Checked by a human programmer
  • Non-functional change
  • No-binary change
  • Infrastructure change (e.g. unit tests, helper scripts)
  • Automated test(s) verify changes (e.g. unit test, autotest)
  • Tested manually, description below (e.g. SITL)
  • Tested on hardware
  • Logs attached
  • Logs available on request

Description

The first commit converts the twitch tests, the level check, the abort limits and the shared start, lean and rate members to radians. Heli is only changed where it implements the shared interface. Log and GCS output values are unchanged, and ATUN ddt and the Max Accel message stay in deg/s/s.

The second commit filters the measured gyro rate, always seeded with the start rate, and works out the test-direction rate once as dir_sign * (rate - start rate). Because the filter is linear, every input to the twitch tests is unchanged. The only behaviour change is that ATDE.Rate is now always the rate change since the start of the twitch, matching ATDE.Angle, where the angle P tests previously logged it without subtracting the start rate.

@lthall lthall added the Copter label Nov 7, 2026
@lthall
lthall requested review from bnsgeyer and a balanced review from Copilot November 7, 2026 23:04
@lthall lthall added the WIP label Nov 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

3 open issues
What changed in this PR

This PR standardizes AutoTune’s internal angle/rate units to radians (and rad/s, rad/s²) and consolidates application of the test direction sign to a single place in the Multi twitch tests.

Changes:

  • Converted Multi twitch tests and shared AutoTune state from centidegrees to radians.
  • Centralized test-direction math in Multi by separating measured body rate from direction-flipped “test rate”.
  • Updated logging conversions so output remains in the same human-friendly units.
File Description
libraries/​AC_AutoTune/​AC_AutoTune_Multi.h Renames target/limit APIs and state members to rad-based naming.
libraries/​AC_AutoTune/​AC_AutoTune_Multi.cpp Converts Multi test logic to radians and centralizes direction application + logging conversions.
libraries/​AC_AutoTune/​AC_AutoTune_Heli.h Updates overridden interface methods to rad-based naming.
libraries/​AC_AutoTune/​AC_AutoTune_Heli.cpp Converts preserved heli angle constants and accel tracking to radians/rad/s² with log/GCS conversions.
libraries/​AC_AutoTune/​AC_AutoTune.h Updates shared AutoTune state and virtual interface to rad-based units.
libraries/​AC_AutoTune/​AC_AutoTune.cpp Converts level-check thresholds and start angle/rate capture to radians/rad/s.

Review effort: Lite

float test_accel_max_cdss; // maximum acceleration variable
float start_angle_rad; // start angle in radians
float start_rate_rads; // start rate in radians/second - parent and multi
float test_accel_max_radss; // maximum acceleration variable in radians/second/second

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

radians/second/second is an acceleration, which is what this is.

#define AUTOTUNE_ANGLE_TARGET_MAX_Y_RAD radians(30.0) // target angle during TESTING_RATE step that will cause us to move to next step
#define AUTOTUNE_ANGLE_TARGET_MIN_Y_RAD radians(5.0) // target angle during TESTING_RATE step that will cause us to move to next step
#define AUTOTUNE_ANGLE_MAX_RP_RAD radians(30.0) // maximum allowable angle during testing
#define AUTOTUNE_ANGLE_NEG_RPY_RAD radians(10.0) // maximum allowable angle during testing

@lthall lthall Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines +199 to 213
const float angle_step_rad = dir_sign * target_angle_rad;
switch (test_axis) {
case AxisType::ROLL:
// request roll to 20deg
attitude_control->input_angle_step_bf_roll_pitch_yaw_rad(dir_sign * cd_to_rad(target_angle), 0.0, 0.0);
attitude_control->input_angle_step_bf_roll_pitch_yaw_rad(angle_step_rad, 0.0, 0.0);
break;
case AxisType::PITCH:
// request pitch to 20deg
attitude_control->input_angle_step_bf_roll_pitch_yaw_rad(0.0, dir_sign * cd_to_rad(target_angle), 0.0);
attitude_control->input_angle_step_bf_roll_pitch_yaw_rad(0.0, angle_step_rad, 0.0);
break;
case AxisType::YAW:
case AxisType::YAW_D:
// request yaw to 20deg
attitude_control->input_angle_step_bf_roll_pitch_yaw_rad(0.0, 0.0, dir_sign * cd_to_rad(target_angle));
attitude_control->input_angle_step_bf_roll_pitch_yaw_rad(0.0, 0.0, angle_step_rad);
break;

@lthall lthall Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Global Size Summary (Total Flash delta in bytes)

Built from 3ad1f77 rebased onto 182796a

Board Periph tracker blimp bootloader copter heli iofw plane rover sub
DrotekP3Pro _ _ _ * _ _ _ _ _ _
Durandal _ * * _ -460 -48 _ * * *
Hitec-Airspeed * _ _ _ _ _ _ _ _ _
KakuteF7 _ * * _ -472 -52 _ * * *
MambaH743v4 _ * * _ -536 -56 _ * * *
MatekF405-CAN _ _ _ * _ _ _ _ _ _
MatekF405 _ * * _ -472 -52 _ * * *
MatekH743-bdshot _ * * _ -460 -48 _ * * *
Pixhawk1-1M _ * * _ -480 -52 _ * * *
disco _ * * _ -536 -20 _ * * *
f103-GPS * _ _ _ _ _ _ _ _ _

@rmackay9

rmackay9 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

This will conflict with my PR #34993 but I'm happy to fixup my PR which is much simpler

@lthall
lthall force-pushed the 20261108_AutoTune_cd_to_rad branch from 896d3cf to 62a138e Compare November 14, 2026 06:48
@AP-Review

AP-Review commented Nov 14, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-11-14)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head 62a138e101.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/ardupilot/35058/1.html#pr35058

The radian conversion and the single-place test-direction rework check out: the constants, filter equivalence and units were verified, and SITL Copter/Heli AutoTune runs pass with gains matching a merge-base control. Two small items remain.

Minor (2)
  • libraries/AC_AutoTune/AC_AutoTune_Multi.cpp:1230: ATDE.Rate is now the raw filtered body rate, but ATDE.Angle is still start-relative and flipped into the test direction, so on negative twitches Angle is positive while Rate is negative. Say in the ATDE @field text which frame each field uses, or log the test-direction rate so the two match.
  • PR description: it says ATUN ddt and the Max Accel message stay in cd/s², but both are already deg/s/s on master and still are here. The values are unchanged; only the unit wording needs fixing.

@lthall lthall added AIReview and removed WIP labels Nov 14, 2026
@lthall

lthall commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

This will conflict with my PR #34993 but I'm happy to fixup my PR which is much simpler

#34993 went in first, so I've rebased this on top of it and kept your deg/s/s output for ATUN ddt and the Max Accel messages

@lthall
lthall force-pushed the 20261108_AutoTune_cd_to_rad branch from 62a138e to 6d26151 Compare November 15, 2026 23:58
@AP-Review

AP-Review commented Nov 16, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-11-16)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head 6d261513a7.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/ardupilot/35058/2.html#pr35058

The radian conversion and single-place test-direction rework still check out at this head, and one minor description item remains.

Since the last review, ATDE.Rate logs the test-direction rate, so its sign now matches ATDE.Angle.

Minor (1)
  • PR description: unit and ATDE wording (still open). ATUN ddt and Max Accel are in deg/s/s, not cd/s². Since the rebase, ATDE.Rate logs the direction-flipped rate since the twitch start, not the measured body rate; against master, only angle P tests changed (they now subtract the start rate).

@lthall
lthall force-pushed the 20261108_AutoTune_cd_to_rad branch from 6d26151 to 1031d8e Compare November 16, 2026 01:06
@lthall lthall changed the title AC_AutoTune: use radians and apply the test direction in one place AC_AutoTune: use radians and convert the twitch measurements to the test direction once Nov 16, 2026
@lthall

lthall commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

Updated: the second commit is renamed to "convert the twitch measurements to the test direction once" and the angle P rate now has a named local explaining why it isn't offset by the start rate. The description is updated to deg/s/s and the corrected ATDE.Rate wording, and #35057 is merged so the dependency is gone.

@AP-Review

AP-Review commented Nov 16, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-11-16)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: ACCEPT

Reviewed at head 1031d8ee81.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/ardupilot/35058/3.html#pr35058

The radian conversion and single-place test-direction rework check out at head 1031d8e, and nothing remains open.

Since the last review, the PR description was corrected to deg/s/s and the current ATDE.Rate behaviour. The new angle-P local (AC_AutoTune_Multi.cpp:263) compiles to the same code as the previous head.

@bnsgeyer bnsgeyer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@AP-Review

AP-Review commented Nov 16, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-11-16)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head e9a72ef8bd.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/ardupilot/35058/4.html#pr35058

The radian conversion and test-direction rework still check out at head e9a72ef. One comment-wording nit is new.

Since the last review, a comment-only commit corrected the #define and ATDE comments and added a twitch description, and it matches the code apart from the item below.

Minor (1)
  • AC_AutoTune_Multi.cpp:50: step j) says angle P up stops on "a bounce back greater than AGGR of the maximum rate", but the code needs the rate to reverse past zero by more than AGGR of the maximum (meas_rate_min < -meas_rate_max * aggressiveness). Suggest "or passes the requested angle and the rate reverses by more than AGGR of the maximum rate".

@lthall
lthall force-pushed the 20261108_AutoTune_cd_to_rad branch from e9a72ef to 3ad1f77 Compare November 17, 2026 00:43
@AP-Review

Copy link
Copy Markdown

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: ACCEPT

Reviewed at head 3ad1f77bd4.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/ardupilot/35058/5.html#pr35058

The radian conversion and test-direction rework check out at head 3ad1f77, and nothing remains open.

Since the last review, the comment-only commit was folded into the two commits, and the step j) wording at AC_AutoTune_Multi.cpp:50 now matches the angle P stop condition. The code is token-identical to the previous head, and CI passed.

@rmackay9
rmackay9 merged commit a42f84a into ArduPilot:master Nov 17, 2026
111 checks passed
@rmackay9

Copy link
Copy Markdown
Contributor

Merged, thanks!

@lthall
lthall deleted the 20261108_AutoTune_cd_to_rad branch November 17, 2026 05:48
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.

6 participants