From eea568dcda2df8faa7e89a321552d6d14be2e5a3 Mon Sep 17 00:00:00 2001 From: Yang Hau Date: Sun, 1 Nov 2026 04:55:20 +0800 Subject: [PATCH] fix(mavlink): correct altitude of relative-frame global offboard setpoints (#29326) SET_POSITION_TARGET_GLOBAL_INT in MAV_FRAME_GLOBAL_RELATIVE_ALT_INT computed the local z setpoint as home_alt - rel_alt - ref_alt instead of ref_alt - (home_alt + rel_alt). The result is only correct when home and the EKF origin are at the same altitude; otherwise the setpoint is off by twice their difference, e.g. after re-arming at a site 30 m above the origin a 10 m relative setpoint ends up 20 m below the origin, driving the vehicle into the ground. Tested in SIH: with home moved 30 m above the origin, a 10 m relative setpoint now gives z = -40 m (previously +20 m) and the vehicle holds it. --- src/modules/mavlink/mavlink_receiver.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/mavlink/mavlink_receiver.cpp b/src/modules/mavlink/mavlink_receiver.cpp index 7625f7fa1ee..da9fa0180f6 100644 --- a/src/modules/mavlink/mavlink_receiver.cpp +++ b/src/modules/mavlink/mavlink_receiver.cpp @@ -1396,8 +1396,8 @@ MavlinkReceiver::handle_message_set_position_target_global_int(mavlink_message_t _home_position_sub.copy(&home_position); if (home_position.valid_alt) { - const float alt = home_position.alt - target_global_int.alt; - setpoint.position[2] = alt - local_pos.ref_alt; + const float alt = home_position.alt + target_global_int.alt; + setpoint.position[2] = local_pos.ref_alt - alt; } else { // home altitude required