From b372d62f35f1829920d6512391c871ed09c5eba3 Mon Sep 17 00:00:00 2001 From: Paul Riseborough Date: Sat, 21 Nov 2020 08:39:55 +1100 Subject: [PATCH] AP_NavEKF2: Add accessor function for body frame airspeed vector --- libraries/AP_NavEKF2/AP_NavEKF2.cpp | 12 ++++++++++++ libraries/AP_NavEKF2/AP_NavEKF2.h | 5 +++++ libraries/AP_NavEKF2/AP_NavEKF2_Outputs.cpp | 16 ++++++++++++++++ libraries/AP_NavEKF2/AP_NavEKF2_core.cpp | 2 +- libraries/AP_NavEKF2/AP_NavEKF2_core.h | 4 ++++ 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/libraries/AP_NavEKF2/AP_NavEKF2.cpp b/libraries/AP_NavEKF2/AP_NavEKF2.cpp index ff0ed24cca..78b22fc9bc 100644 --- a/libraries/AP_NavEKF2/AP_NavEKF2.cpp +++ b/libraries/AP_NavEKF2/AP_NavEKF2.cpp @@ -943,6 +943,18 @@ void NavEKF2::getVelNED(int8_t instance, Vector3f &vel) const } } +// return estimate of true airspeed vector in body frame in m/s for the specified instance +// An out of range instance (eg -1) returns data for the primary instance +// returns false if estimate is unavailable +bool NavEKF2::getAirSpdVec(int8_t instance, Vector3f &vel) const +{ + if (instance < 0 || instance >= num_cores) instance = primary; + if (core) { + return core[instance].getAirSpdVec(vel); + } + return false; +} + // Return the rate of change of vertical position in the down direction (dPosD/dt) in m/s float NavEKF2::getPosDownDerivative(int8_t instance) const { diff --git a/libraries/AP_NavEKF2/AP_NavEKF2.h b/libraries/AP_NavEKF2/AP_NavEKF2.h index d487b58b2e..98b0cac81b 100644 --- a/libraries/AP_NavEKF2/AP_NavEKF2.h +++ b/libraries/AP_NavEKF2/AP_NavEKF2.h @@ -83,6 +83,11 @@ public: // An out of range instance (eg -1) returns data for the primary instance void getVelNED(int8_t instance, Vector3f &vel) const; + // return estimate of true airspeed vector in body frame in m/s for the specified instance + // An out of range instance (eg -1) returns data for the primary instance + // returns false if estimate is unavailable + bool getAirSpdVec(int8_t instance, Vector3f &vel) const; + // Return the rate of change of vertical position in the down direction (dPosD/dt) in m/s for the specified instance // An out of range instance (eg -1) returns data for the primary instance // This can be different to the z component of the EKF velocity state because it will fluctuate with height errors and corrections in the EKF diff --git a/libraries/AP_NavEKF2/AP_NavEKF2_Outputs.cpp b/libraries/AP_NavEKF2/AP_NavEKF2_Outputs.cpp index 198616d7fa..74cf6f246b 100644 --- a/libraries/AP_NavEKF2/AP_NavEKF2_Outputs.cpp +++ b/libraries/AP_NavEKF2/AP_NavEKF2_Outputs.cpp @@ -173,6 +173,22 @@ void NavEKF2_core::getVelNED(Vector3f &vel) const vel = outputDataNew.velocity + velOffsetNED; } +// return estimate of true airspeed vector in body frame in m/s +// returns false if estimate is unavailable +bool NavEKF2_core::getAirSpdVec(Vector3f &vel) const +{ + if (inhibitWindStates || PV_AidingMode == AID_NONE) { + return false; + } + vel = outputDataNew.velocity + velOffsetNED; + vel.x -= stateStruct.wind_vel.x; + vel.y -= stateStruct.wind_vel.y; + Matrix3f Tnb; // rotation from nav to body frame + outputDataNew.quat.inverse().rotation_matrix(Tnb); + vel = Tnb * vel; + return true; +} + // Return the rate of change of vertical position in the down direction (dPosD/dt) of the body frame origin in m/s float NavEKF2_core::getPosDownDerivative(void) const { diff --git a/libraries/AP_NavEKF2/AP_NavEKF2_core.cpp b/libraries/AP_NavEKF2/AP_NavEKF2_core.cpp index e3664eeace..bb99f56c3f 100644 --- a/libraries/AP_NavEKF2/AP_NavEKF2_core.cpp +++ b/libraries/AP_NavEKF2/AP_NavEKF2_core.cpp @@ -667,7 +667,7 @@ void NavEKF2_core::UpdateStrapdownEquationsNED() delVelNav = prevTnb.mul_transpose(delVelCorrected); delVelNav.z += GRAVITY_MSS*imuDataDelayed.delVelDT; - // calculate the body to nav cosine matrix + // calculate the nav to body cosine matrix stateStruct.quat.inverse().rotation_matrix(prevTnb); // calculate the rate of change of velocity (used for launch detect and other functions) diff --git a/libraries/AP_NavEKF2/AP_NavEKF2_core.h b/libraries/AP_NavEKF2/AP_NavEKF2_core.h index 8c3fef0072..5fe06b88c1 100644 --- a/libraries/AP_NavEKF2/AP_NavEKF2_core.h +++ b/libraries/AP_NavEKF2/AP_NavEKF2_core.h @@ -102,6 +102,10 @@ public: // return NED velocity in m/s void getVelNED(Vector3f &vel) const; + // return estimate of true airspeed vector in body frame in m/s + // returns false if estimate is unavailable + bool getAirSpdVec(Vector3f &vel) const; + // Return the rate of change of vertical position in the down direction (dPosD/dt) in m/s // This can be different to the z component of the EKF velocity state because it will fluctuate with height errors and corrections in the EKF // but will always be kinematically consistent with the z component of the EKF position state