Repository navigation
AC_AutoTune: use radians and convert the twitch measurements to the test direction once - #35058
Conversation
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
| 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; |
Global Size Summary (Total Flash delta in bytes)Built from 3ad1f77 rebased onto 182796a
|
|
This will conflict with my PR #34993 but I'm happy to fixup my PR which is much simpler |
896d3cf to
62a138e
Compare
Previous review (2026-11-14)Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting. Reviewed at head 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)
|
62a138e to
6d26151
Compare
Previous review (2026-11-16)Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting. Reviewed at head 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)
|
6d26151 to
1031d8e
Compare
|
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. |
Previous review (2026-11-16)Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting. Reviewed at head 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. |
Previous review (2026-11-16)Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting. Reviewed at head 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)
|
e9a72ef to
3ad1f77
Compare
|
Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting. Reviewed at head 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. |
|
Merged, thanks! |

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)
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.