Skip to content

autotest: fix and re-enable Plane.TerrainRally - #34517

Merged
peterbarker merged 1 commit into
ArduPilot:masterfrom
Abtektas:fix/plane-terrainrally
Oct 12, 2026
Merged

peterbarker merged 1 commit into
ArduPilot:masterfrom
Abtektas:fix/plane-terrainrally

Conversation

@Abtektas

@Abtektas Abtektas commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #33740. Plane.TerrainRally now checks the altitudes it is meant to check, and it is removed from the disabled tests.

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

Tools/autotest/autotest.py build.Plane test.Plane.TerrainRally on macOS (arm64) SITL, with an empty terrain cache for each run:

  • master: terrain loading stalls at pending=56 and the test times out before takeoff.
  • with only the terrain wait fixed: the vehicle flies about 580m above the target (vdist=582m), as described in the issue.
  • this PR: passed 3/3 runs. Both rally checks now hold their position for 10s, and the vertical error there is about 1.5m.
  • negative checks:
    • forcing TERRAIN_FOLLOW=0 for the first leg makes the test fail (below 50m AGL).
    • checking the first leg against 100m above terrain with a 10s hold fails: the plane settles at 686.5m AMSL, 14m below that target.

All workflows pass on the fork.

Description

Altitude frames. The guided and rally targets were AMSL values sent in the terrain frame. Now:

  • the guided target is 99m above terrain
  • the first rally point is uploaded 100m above home. With TERRAIN_FOLLOW, RTL follows terrain on the way. change_alt_frame() keeps the AMSL height, so the plane arrives at home+100m, and that is what the test checks.
  • the second rally point is uploaded 100m above terrain, with TERRAIN_FOLLOW=0, and is checked against 100m above terrain.
  • both rally checks use minimum_duration=10, so they check where the plane settles, not a moment during the descent.

terrain_wait_path. It sent TERRAIN_CHECKs in a tight loop. With an empty terrain cache the vehicle answered with ~450k TERRAIN_REPORTs, left no room on the link for TERRAIN_REQUEST, and loading never finished. This PR:

  • paces the loop at 1Hz, so terrain loads within a few seconds
  • also checks the path's end point
  • waits for terrain toward the guided location too, so its height is known before wait_location converts the target to AMSL

Note: the TERRAIN_FOLLOW parameter docs say rally altitudes are taken as height above terrain, but the code keeps the AMSL height. This PR tests what the firmware does today and does not change that.

This contribution was AI-assisted (Claude Code): it investigated the failure, wrote the change and ran the SITL checks above. I have not reviewed the code myself. @robertlong13 agreed on the issue to me opening this PR.

🤖 Generated with Claude Code

@AP-Review

AP-Review commented Sep 28, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-09-28)

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

Reviewed at head 69b10d7b92. Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/2026_09_28_AIReview/devcall_pr_reviews.html#pr34517

Most of this works — the terrain loading pacing, the guided legs and the second rally leg all check the right thing — but the first rally check asserts an altitude the plane never holds, and passes only on a transient. Three independent passes reached the same conclusion.

Bug

  • Tools/autotest/arduplane.py:1961: the first rally leg expects 100 m above terrain at the rally point, but that is not what the firmware flies.
    • With TERRAIN_FOLLOW, setup_terrain_target_alt() calls Location::change_alt_frame(ABOVE_TERRAIN) (ArduPlane/altitude.cpp:547), which preserves the AMSL height (Location.cpp:195 adds home, :249 subtracts terrain). The home-relative 100 m rally point is therefore flown at home+100 ≈ 685 m AMSL, about 85 m above terrain there — not 700.6 m.
    • Measured in SITL after "Reached rally point with TERRAIN_FOLLOW": the plane loitered at 684-687 m AMSL, 14-16 m from the test's target, against a 10 m tolerance.
    • It passes because wait_location has no minimum_duration, so it succeeds on the first sample inside 200 m while the plane is still descending from the higher terrain. With minimum_duration=10 and the PR's target the test fails (settled vdist 14.0 m). And a firmware mutation that makes the plane genuinely fly 100 m AGL there also passes, so this check cannot tell the two behaviours apart.
    • Fix: check leg 1 against rally_loc_home (what the firmware flies) and reword the comment at :1925. That passed 3/3 locally.

Suggestion

  • Tools/autotest/arduplane.py:1989: add minimum_duration=10 to both rally wait_location calls. Leg 2 currently succeeds right at the edge of its tolerance (vdist 10.0-10.9 m on the line before success in every logged run — the margin you mention); its settled loiter is 99-101 m AGL, so a hold check is robust. Passed 3/3.

Note (out of scope for this PR)

  • ArduPlane/Parameters.cpp:325: the TERRAIN_FOLLOW doc says rally altitudes are taken as height above terrain; the code keeps the AMSL height. Worth a maintainer deciding which is intended — this test should check what the firmware does today.

Checked

  • test.Plane.TerrainRally passed 10/10 locally under a private netns (9 from an empty terrain cache). Terrain is served from the in-tree tilecache, no network needed.
  • Removing the new 1 Hz pacing in terrain_wait_path stalls loading at pending=56 and fails, so the pacing fix is needed.
  • The 50 m-AGL hook catches both RTL ignoring TERRAIN_FOLLOW and AP_Rally ignoring the rally altitude frame.
  • Removal from the disabled list is correct; flake8 is clean.

@Abtektas
Abtektas force-pushed the fix/plane-terrainrally branch from 69b10d7 to 2f4394d Compare September 28, 2026 20:02
@AP-Review

AP-Review commented Sep 28, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-09-28)

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

Re-reviewed at head 2f4394d514 (you were last told 69b10d7b92); my earlier comment above is superseded. Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/2026_09_29_AIReview/devcall_pr_reviews.html#pr34517

No blockers. Both findings from my previous comment are resolved; the out-of-scope doc note is unchanged, which is fine for this PR.

Resolved

  • First rally leg target: Tools/autotest/arduplane.py:1962 now checks rally_loc_home (home+100 m, 685 m AMSL), which is what the firmware flies, and the comment at :1925 matches. This leg now catches problems in both directions: checking it against 100 m AGL fails (settles 14 m low), and a firmware change that really flies the rally point at 100 m AGL also fails (loiters ~17 m high). At the previous head that firmware change still passed.
  • minimum_duration=10 is on both rally checks (:1966, :1995).

Still open (out of scope)

  • ArduPlane/Parameters.cpp:325: the TERRAIN_FOLLOW doc still says rally altitudes are treated as height above terrain. You note this in the description; it's for a maintainer to decide separately.

Checked

  • test.Plane.TerrainRally passed 21/21 in a private netns (11 with an empty terrain cache, 10 warm). Across those runs the vertical error during the hold stayed within 9.9 m on both legs (tolerance 10 m) and ended about 1.5 m from the target.
  • Forcing TERRAIN_FOLLOW=0 for the first leg fails 2/2 on the 50 m-AGL check.
  • The test is removed from the disabled list and nothing else references it; flake8 is clean.

Comment thread Tools/autotest/arduplane.py Outdated
guided_loc = Location(-35.39723762, 149.07284612, 99.0, AltFrame.ABOVE_TERRAIN)
# uploaded relative to home; TERRAIN_FOLLOW makes RTL follow
# terrain on the way, but it arrives at the same AMSL height
rally_loc_home = Location(-35.3654952000, 149.1558698000, 100, AltFrame.ABOVE_HOME)

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.

Suggested change
rally_loc_home = Location(-35.3654952000, 149.1558698000, 100, AltFrame.ABOVE_HOME)
rally_loc_relhome = Location(-35.3654952000, 149.1558698000, 100, AltFrame.ABOVE_HOME)

The guided and rally locations carried AMSL altitudes while being sent
in the terrain frame, so the vehicle climbed several hundred metres
and the test could only pass vacuously.  Use a terrain-relative guided
location, upload the first rally point relative to home (TERRAIN_FOLLOW
makes RTL fly it relative to terrain) and the second in the terrain
frame, and check arrival against terrain-relative targets.

terrain_wait_path sent TERRAIN_CHECKs in a tight loop, which kept the
link saturated with TERRAIN_REPORTs so the vehicle never had room to
send TERRAIN_REQUEST and loading stalled on an empty terrain cache.
Pace it at 1Hz, and also check the path end points, including the
guided location, so their terrain height is known before arrival is
checked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Abtektas
Abtektas force-pushed the fix/plane-terrainrally branch from 2f4394d to 76c7051 Compare October 6, 2026 09:18
@Abtektas

Abtektas commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, done. rally_loc_home is now rally_loc_relhome in all four places the test uses it (the definition, the copy, the rally upload and the final wait_location). Nothing else has changed and it is still a single commit.

CI on the new commit: Plane.TerrainRally passes in sitltest-plane-tests1b. The one red job is sitltest-quadplane-tests1c, where QAUTOTUNE ends with "AutoTune: Failed to level" after repeated "Pitch Angle P Up 0%". That looks like the intermittent failure #33628 fixes, and this PR only touches Tools/autotest/arduplane.py, so I have not changed anything for it.

@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 76c7051bba.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/ardupilot/34517/1.html#pr34517

Re-reviewed at head 76c7051bba (you were last told 2f4394d514). No blockers.

The rename to rally_loc_relhome is applied in all four places (definition, copy, upload, leg-1 wait), and nothing else changed.

Checked

  • test.Plane.TerrainRally passed 3/3 locally at this head; both rally legs settle about 1.5 m from target.
  • flake8 and the branch-convention check are clean.

CI

  • The only red job is sitltest-quadplane-tests1c, and the only test that fails there is QAUTOTUNE ("Failed to level"). This PR doesn't touch that code.
  • sitltest-plane-tests1b shows TerrainRally PASSED.

Not re-run at this head
The longer soak and the negative mutations from the last round were done at 2f4394d514 and not repeated. Since this change is only a rename, they should still apply.

Optional nit
The commit body says arrival is checked "against terrain-relative targets", but leg 1 now checks the home-relative target. Rewording that clause would make the message match the code.

Still open, out of scope
The TERRAIN_FOLLOW doc at ArduPlane/Parameters.cpp:325 still says rally altitudes are treated as height above terrain. A maintainer should decide that separately.

@robertlong13 robertlong13 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.

Looks good to me. Crucially, it's actually testing terrain following low down this time.

Image

@peterbarker
peterbarker merged commit 557faa0 into ArduPilot:master Oct 12, 2026
32 of 33 checks passed
@Abtektas
Abtektas deleted the fix/plane-terrainrally branch October 18, 2026 17:19
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.

autotest: Plane.TerrainRally is broken

4 participants