Files
ardupilot/libraries/AC_Fence
Peter BarkerandClaude Opus 5 af2a1bafc8 AC_Fence: compare the altitude limits in a common frame
FENCE_ALT_MIN and FENCE_ALT_MAX each carry their own reference frame,
but pre_arm_check() compared their raw values.  Those values are
measured from different datums whenever the frames differ, so the
comparison is between unlike quantities: a floor 20m above home, held
as an absolute 604.09, read as being above a 100m ceiling which is also
20m above the floor, and the vehicle refused to arm with

    PreArm: FENCE_ALT_MAX < FENCE_ALT_MIN

The FENCE_MARGIN check immediately below subtracts the same two values
and had the same problem.

Convert the minimum into the maximum's frame before comparing.  Where
the frames already match nothing is converted, so a comparison which
used to work without home, an origin or terrain data still does.  Where
the conversion is not possible - an above-terrain limit with no terrain
height, or above-home with no home - the check reports that rather than
comparing regardless.

Found by an autotest: ArduCopter's MinAltFence sets an absolute floor
in its first sub-case and takes off again in the second, and whether it
failed depended on the fence still being enabled at that moment.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-28 17:21:29 +10:00
..