Skip to content

Commit baebdb9

Browse files
committed
AP_Common: add SITL check for matching alt frame in linearly_interpolate_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 #32926
1 parent 17ce3c4 commit baebdb9

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

libraries/AP_Common/Location.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,13 @@ int32_t Location::limit_lattitude(int32_t lat)
681681
// this alt-frame will be updated to match the destination alt frame
682682
void Location::linearly_interpolate_alt(const Location &point1, const Location &point2)
683683
{
684+
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
685+
// alt frames must match; mixing frames produces meaningless interpolated altitudes
686+
if (point1.get_alt_frame() != point2.get_alt_frame()) {
687+
AP_HAL::panic("linearly_interpolate_alt: alt frames differ (point1=%u point2=%u)",
688+
(unsigned)point1.get_alt_frame(), (unsigned)point2.get_alt_frame());
689+
}
690+
#endif
684691
// new target's distance along the original track and then linear interpolate between the original origin and destination altitudes
685692
set_alt_cm(point1.alt + (point2.alt - point1.alt) * constrain_float(line_path_proportion(point1, point2), 0.0f, 1.0f), point2.get_alt_frame());
686693
}

0 commit comments

Comments
 (0)