FlightTask: Fix ekf2 reset race condition during task switch (#14692)

* FlightTask: Fix ekf2 reset race condition during task switch

During a loss of GPS data when using GPS as primary height source,
the height is reset to baro and the local position gets invalid at the
same time. This triggers a switch to altitude flight task and a setpoint
reset.
This combination of events had the effect to ignore the height reset,
the large sudden height error could create an abrupt change of altitude
or even a crash.
The ekf2 reset is now done at the beginning of each update call.
This commit is contained in:
Mathieu Bresciani
2020-04-22 13:18:35 +02:00
committed by GitHub
parent e82880d6d7
commit be2bb4a479
14 changed files with 85 additions and 42 deletions
@@ -68,6 +68,8 @@ bool FlightTaskOffboard::activate(vehicle_local_position_setpoint_s last_setpoin
bool FlightTaskOffboard::update()
{
bool ret = FlightTask::update();
// reset setpoint for every loop
_resetSetpoints();
@@ -106,7 +108,7 @@ bool FlightTaskOffboard::update()
}
// don't have to continue
return true;
return ret;
} else {
_position_lock.setAll(NAN);
@@ -124,7 +126,7 @@ bool FlightTaskOffboard::update()
}
// don't have to continue
return true;
return ret;
} else {
_position_lock.setAll(NAN);
@@ -144,7 +146,7 @@ bool FlightTaskOffboard::update()
}
// don't have to continue
return true;
return ret;
} else {
_position_lock.setAll(NAN);
@@ -155,7 +157,7 @@ bool FlightTaskOffboard::update()
_position_setpoint.setNaN(); // Don't require any position/velocity setpoints
_velocity_setpoint.setNaN();
_acceleration_setpoint = Vector3f(0.f, 0.f, 100.f); // High downwards acceleration to make sure there's no thrust
return true;
return ret;
}
// Possible inputs:
@@ -240,5 +242,5 @@ bool FlightTaskOffboard::update()
// use default conditions of upwards position or velocity to take off
_constraints.want_takeoff = _checkTakeoff();
return true;
return ret;
}