Skip to content

AP_Common: add SITL check for matching alt frame in linearly_interpolate_alt#33079

Merged
peterbarker merged 1 commit into
ArduPilot:masterfrom
ja51d:wpnav-oa-altframe-check
May 20, 2026
Merged

AP_Common: add SITL check for matching alt frame in linearly_interpolate_alt#33079
peterbarker merged 1 commit into
ArduPilot:masterfrom
ja51d:wpnav-oa-altframe-check

Conversation

@ja51d

@ja51d ja51d commented May 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #32926. update_wpnav() calls linearly_interpolate_alt() against origin_loc and destination_loc for both the BendyRulerHorizontal and Dijkstras path-handling branches. That helper's contract is that its two endpoint Locations share an alt frame; mixing frames produces meaningless interpolated altitudes.

Today the two locations are always constructed from the same _is_terrain_alt_oabak conditional so the invariant holds, but there's no runtime check to catch a future change that breaks it. Added a SITL-only INTERNAL_ERROR right after the Locations are constructed.

Classification & Testing

  • 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
  • Tested on hardware

Built ArduCopter SITL on macOS (arm64). With the current code path the alt frames match by construction, so the new check does not fire (no behavior change). The check is guarded by #if CONFIG_HAL_BOARD == HAL_BOARD_SITL so production builds are unaffected.

@IamPete1

Copy link
Copy Markdown
Member

I would vote to put the check in the linearly_interpolate_alt function itself then we can check all users.

@ja51d ja51d force-pushed the wpnav-oa-altframe-check branch from abf7fb4 to 44915e7 Compare May 17, 2026 00:08
@ja51d ja51d changed the title AC_WPNav_OA: add SITL check for matching origin/destination alt frame AP_Common: add SITL check for matching alt frame in linearly_interpolate_alt May 17, 2026
@ja51d

ja51d commented May 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @IamPete1 , that's the better design. Moved the check into Location::linearly_interpolate_alt() so every caller is covered. Force-pushed the update.

@IamPete1 IamPete1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice! Thanks

…ate_alt

linearly_interpolate_alt() interpolates altitude between two Location
endpoints and only produces meaningful results when both endpoints
share an alt frame; mixing frames produces nonsense altitudes.

Add a SITL-only panic at the top of the function so the contract is
checked for every caller (BendyRulerHorizontal and Dijkstras path
handling in AC_WPNav_OA, plus any future callers), as suggested by
IamPete1 in code review.

Fixes ArduPilot#32926
@ja51d ja51d force-pushed the wpnav-oa-altframe-check branch from eb15852 to baebdb9 Compare May 19, 2026 11:36
@peterbarker peterbarker merged commit 586773e into ArduPilot:master May 20, 2026
109 of 110 checks passed
@peterbarker

Copy link
Copy Markdown
Contributor

Incidentally, throwing a "flow_of_control" internal error would have been perfectly valid - if it happens on a real aircraft bad things are going to happen.

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.

AC_WPNav_OA: add SITL check that origin and destination are of the same alt frame

4 participants