@ -585,6 +585,10 @@ static bool throttle_suppressed;
@@ -585,6 +585,10 @@ static bool throttle_suppressed;
AP_SpdHgtControl::FlightStage flight_stage = AP_SpdHgtControl::FLIGHT_NORMAL;
// probability of aircraft is currently in flight. range from 0 to 1 where 1 is 100% sure we're in flight
static float isFlyingProbability = 0;
static void determine_is_flying(void);
////////////////////////////////////////////////////////////////////////////////
// Loiter management
////////////////////////////////////////////////////////////////////////////////
@ -1024,6 +1028,9 @@ static void one_second_loop()
@@ -1024,6 +1028,9 @@ static void one_second_loop()
update_aux();
// determine if we are flying or not
determine_is_flying();
// update notify flags
AP_Notify::flags.pre_arm_check = arming.pre_arm_checks(false);
AP_Notify::flags.pre_arm_gps_check = true;
@ -1536,6 +1543,52 @@ static void update_flight_stage(void)
@@ -1536,6 +1543,52 @@ static void update_flight_stage(void)
airspeed.set_EAS2TAS(barometer.get_EAS2TAS());
}
/*
Do we think we are flying?
Probabilistic method where a bool is low-passed and considered a probability.
*/
static void determine_is_flying(void)
{
float aspeed;
bool isFlyingBool;
bool airspeedMovement = ahrs.airspeed_estimate(&aspeed) && (aspeed >= 5);
// If we don't have a GPS lock then don't use GPS for this test
bool gpsMovement = (gps.status() < AP_GPS::GPS_OK_FIX_2D ||
gps.ground_speed() >= 5);
if(ahrs.get_armed()) {
// when armed, we need overwhelming evidence that we ARE NOT flying
isFlyingBool = airspeedMovement || gpsMovement;
} else {
// when disarmed, we need overwhelming evidence that we ARE flying
isFlyingBool = airspeedMovement && gpsMovement;
}
// low-pass the result.
isFlyingProbability = (0.8 * isFlyingProbability) + (0.2*(float)isFlyingBool);
}
static bool is_flying(void)
{
if(ahrs.get_armed()) {
// when armed, assume we're flying unless we probably aren't
return (isFlyingProbability >= 0.1);
}
else
{
// when disarmed, assume we're not flying unless we probably are
return (isFlyingProbability >= 0.9);
}
}
#if OPTFLOW == ENABLED
// called at 50hz
static void update_optical_flow(void)