fix(fw_mode_manager): ignore setpoints from before Offboard (#29279)

Run() chose the setpoint source with the control mode of the previous
cycle, because vehicle_control_mode_poll() ran after that choice, and
on entering Offboard it still held the last setpoint read, for example
the one from Offboard as a multicopter before the transition (NaN
position, finite velocity, marked valid). The first fixed-wing
Offboard cycles followed that setpoint until a new trajectory_setpoint
arrived.

Poll the control mode before choosing the setpoint source, and mark
the current setpoint invalid when Offboard starts.

Assisted-by: Claude:claude-opus-5-5

Signed-off-by: A.Burak Tektas <15087318+Abtektas@users.noreply.github.com>
This commit is contained in:
Ahmet Burak Tektas authored and GitHub committed 2026-10-27 13:25:32 +01:00
1 parent 15c16dd3ba
commit 77aaa2f6da
1 file changed
+9 -1
@@ -111,6 +111,7 @@ FixedWingModeManager::vehicle_control_mode_poll()
{
if (_control_mode_sub.updated()) {
const bool was_armed = _control_mode.flag_armed;
const bool was_offboard = _control_mode.flag_control_offboard_enabled;
if (_control_mode_sub.copy(&_control_mode)) {
@@ -119,6 +120,11 @@ FixedWingModeManager::vehicle_control_mode_poll()
reset_takeoff_state();
reset_landing_state();
}
// only follow setpoints received in this Offboard session, not what an earlier mode left behind
if (!was_offboard && _control_mode.flag_control_offboard_enabled) {
_position_setpoint_current_valid = false;
}
}
}
}
@@ -2191,6 +2197,9 @@ FixedWingModeManager::Run()
_go_direct_to_destination = true;
}
// the control mode decides below where the setpoint is taken from, so it has to be current
vehicle_control_mode_poll();
if (_control_mode.flag_control_offboard_enabled) {
trajectory_setpoint_s trajectory_setpoint;
@@ -2289,7 +2298,6 @@ FixedWingModeManager::Run()
vehicle_attitude_poll();
vehicle_attitude_setpoint_poll();
vehicle_command_poll();
vehicle_control_mode_poll();
wind_poll(now);
if (_vehicle_land_detected_sub.updated()) {