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 <dahl.jakejacob@gmail.com>
This commit is contained in:
Jacob Dahl authored and GitHub committed 2026-08-28 23:12:28 -06:00
1 parent ed93e5c87c
commit 0a441d9443
1 file changed
+9 -4
+9 -4
View File
@@ -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::px4::enums::arm_disarm_reason_t>(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;