fix(navigator): guard terrain altitude check for position mission items (#27306)

* fix(navigator): guard terrain altitude check for position mission items

updateAltToAvoidTerrainCollisionAndRepublishTriplet() calls
get_absolute_altitude_for_item() on the current mission item without first
checking whether the item contains a position.

For non-position mission items, the altitude field has no setpoint meaning.
Using it in the terrain descent condition can make the check operate on an
invalid mission-item altitude.

Add the same item_contains_position() guard used by other mission altitude
handling paths before reading the mission item altitude.

* navigator: remove redundant mission item checks

Remove checks already covered by item_contains_position() and update the
terrain avoidance comment to match the current condition.
This commit is contained in:
Eurus authored and GitHub committed 2026-05-10 11:15:17 -06:00
1 parent f4c38daa38
commit b5f08754bf
1 file changed
+3 -3
+3 -3
View File
@@ -1004,7 +1004,7 @@ void MissionBlock::startPrecLand(uint16_t land_precision)
void MissionBlock::updateAltToAvoidTerrainCollisionAndRepublishTriplet(const mission_item_s &mission_item)
{
// Avoid flying into terrain using the distance sensor. Enable through the parameter NAV_MIN_GND_DIST.
// Only active during commanded descents with vz>0 (to prevent climb-aways), excluding landing and VTOL transitions.
// Only active during commanded descents with vz>0 (to prevent climb-aways) on position mission items, excluding landing.
// It changes the altitude setpoint in the triplet to maintain the current altitude and republish the triplet.
// We also change the mission item altitude used for acceptance calculations to prevent getting stuck in a loop.
@@ -1014,8 +1014,8 @@ void MissionBlock::updateAltToAvoidTerrainCollisionAndRepublishTriplet(const mis
if (_navigator->get_nav_min_gnd_dist_param() > FLT_EPSILON && _mission_item.nav_cmd != NAV_CMD_LAND
&& _mission_item.nav_cmd != NAV_CMD_VTOL_LAND && _mission_item.nav_cmd != NAV_CMD_DO_VTOL_TRANSITION
&& _mission_item.nav_cmd != NAV_CMD_IDLE
&& _mission_item.nav_cmd != NAV_CMD_VTOL_LAND
&& item_contains_position(mission_item)
&& _navigator->get_local_position()->dist_bottom_valid
&& _navigator->get_local_position()->dist_bottom < _navigator->get_nav_min_gnd_dist_param()
&& _navigator->get_local_position()->vz > FLT_EPSILON