From 0a441d94438aa6ba191efffe3f2e90c6ff2f80fe Mon Sep 17 00:00:00 2001 From: Jacob Dahl <37091262+dakejahl@users.noreply.github.com> Date: Fri, 28 Aug 2026 23:12:28 -0600 Subject: [PATCH] fix(commander): capture home on the ground before motors spin (#27734) Move the arm-time home capture to before ARMING_STATE_ARMED so it runs before the ESCs are enabled and prop wash perturbs the baro, and gate it on landed && (!_mission_in_progress || seq_current == 0). The previous !_mission_in_progress gate skipped the capture entirely when arming straight into a mission, leaving home referenced to a stale (cold-baro, fewer-sats) on-ground fix. seq_current distinguishes a genuine mission start from a mid-mission re-arm (land/disarm/continue), which must not move home. Part of #27730. Signed-off-by: Jacob Dahl --- src/modules/commander/Commander.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/modules/commander/Commander.cpp b/src/modules/commander/Commander.cpp index 5c6e365764a..9e2db830010 100644 --- a/src/modules/commander/Commander.cpp +++ b/src/modules/commander/Commander.cpp @@ -725,6 +725,15 @@ transition_result_t Commander::arm(arm_disarm_reason_t calling_reason, bool run_ } } + // Capture a fresh home position on the ground before the motors spin (prop wash perturbs the + // baro), but only at a real mission start: skip a mid-mission re-arm (seq_current > 0) and any + // in-air re-arm. + if (_param_com_home_en.get() && !_config_overrides.disable_auto_set_home + && _vehicle_land_detected.landed + && (!_mission_in_progress || _mission_result_sub.get().seq_current == 0)) { + _home_position.setHomePosition(); + } + _vehicle_status.armed_time = hrt_absolute_time(); _vehicle_status.arming_state = vehicle_status_s::ARMING_STATE_ARMED; _vehicle_status.latest_arming_reason = (uint8_t)calling_reason; @@ -733,10 +742,6 @@ transition_result_t Commander::arm(arm_disarm_reason_t calling_reason, bool run_ events::send(events::ID("commander_armed_by"), events::Log::Info, "Armed by {1}", calling_reason); - if (_param_com_home_en.get() && !_mission_in_progress && !_config_overrides.disable_auto_set_home) { - _home_position.setHomePosition(); - } - _status_changed = true; return TRANSITION_CHANGED;