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.
This commit is contained in:
Yang Hau authored and GitHub committed 2026-10-31 14:55:20 -06:00
1 parent ed3c3c5553
commit eea568dcda
1 file changed
+2 -2
+2 -2
View File
@@ -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