diff --git a/src/shared/algorithms/NAS/NAS.cpp b/src/shared/algorithms/NAS/NAS.cpp index 98411f9252c87e76688c828025474559c47bc9c7..892bce0720ae7a6a9c24140a8c1a0082982a42b9 100644 --- a/src/shared/algorithms/NAS/NAS.cpp +++ b/src/shared/algorithms/NAS/NAS.cpp @@ -122,6 +122,12 @@ void NAS::predictAcc(const Vector3f& acceleration) P.block<6, 6>(0, 0) = F_lin * Pl * F_lin_tr + Q_lin; } +void NAS::predictAcc(const AccelerometerData& acceleration) +{ + predictAcc(Vector3f{acceleration.accelerationX, acceleration.accelerationY, + acceleration.accelerationZ}); +} + void NAS::predictGyro(const Vector3f& angularVelocity) { Vector3f bias = x.block<3, 1>(IDX_BIAS, 0); @@ -151,6 +157,13 @@ void NAS::predictGyro(const Vector3f& angularVelocity) P.block<6, 6>(IDX_QUAT, IDX_QUAT) = Pq; } +void NAS::predictGyro(const GyroscopeData& angularVelocity) +{ + predictGyro(Vector3f{angularVelocity.angularVelocityX, + angularVelocity.angularVelocityY, + angularVelocity.angularVelocityZ}); +} + void NAS::correctBaro(const float pressure) { Matrix<float, 1, 6> H = Matrix<float, 1, 6>::Zero(); @@ -193,6 +206,19 @@ void NAS::correctGPS(const Vector4f& gps) x.head<6>() = x.head<6>() + K * (gps - H); } +void NAS::correctGPS(const GPSData& gps) +{ + if (!gps.fix) + return; + + auto gpsPos = Aeroutils::geodetic2NED( + {gps.latitude, gps.longitude}, + {reference.startLatitude, reference.startLongitude}); + + correctGPS( + Vector4f{gpsPos(0), gpsPos(1), gps.velocityNorth, gps.velocityEast}); +} + void NAS::correctMag(const Vector3f& mag) { Vector4f q = x.block<4, 1>(IDX_QUAT, 0); @@ -226,6 +252,13 @@ void NAS::correctMag(const Vector3f& mag) P.block<6, 6>(IDX_QUAT, IDX_QUAT) = Pq; } +void NAS::correctMag(const MagnetometerData& mag) +{ + Vector3f magV = {mag.magneticFieldX, mag.magneticFieldY, + mag.magneticFieldZ}; + correctMag(magV.normalized()); +} + void NAS::correctAcc(const Eigen::Vector3f& acc) { Vector4f q = x.block<4, 1>(IDX_QUAT, 0); @@ -264,6 +297,12 @@ void NAS::correctAcc(const Eigen::Vector3f& acc) P.block<6, 6>(IDX_QUAT, IDX_QUAT) = Pq; } +void NAS::correctAcc(const AccelerometerData& acc) +{ + Vector3f accV = {acc.accelerationX, acc.accelerationY, acc.accelerationZ}; + correctAcc(accV.normalized()); +} + void NAS::correctPitot(const float deltaP, const float staticP) { if (deltaP >= 0) diff --git a/src/shared/algorithms/NAS/NAS.h b/src/shared/algorithms/NAS/NAS.h index d48b9081a58bad06f7f9a7c60397e65d68906903..c515ea41c741736c9b975d3cf686596db567cadd 100644 --- a/src/shared/algorithms/NAS/NAS.h +++ b/src/shared/algorithms/NAS/NAS.h @@ -23,6 +23,7 @@ #pragma once #include <algorithms/ReferenceValues.h> +#include <sensors/SensorData.h> #include <utils/AeroUtils/AeroUtils.h> #include <utils/Constants.h> @@ -54,17 +55,31 @@ public: /** * @brief Prediction with accelerometer data. * - * @param u Vector with acceleration data [x y z][m/s^2]. + * @param acceleration Vector with acceleration data [x y z][m/s^2]. */ void predictAcc(const Eigen::Vector3f& acceleration); + /** + * @brief Prediction with accelerometer data. + * + * @param acceleration Accelerometer data [m/s^2]. + */ + void predictAcc(const AccelerometerData& acceleration); + /** * @brief Prediction with gyroscope data. * - * @param u Vector with angular velocity data [x y z]. + * @param angularVelocity Vector with angular velocity data [x y z][rad/s]. */ void predictGyro(const Eigen::Vector3f& angularVelocity); + /** + * @brief Prediction with gyroscope data. + * + * @param angularVelocity Gyroscope data [rad/s]. + */ + void predictGyro(const GyroscopeData& angularVelocity); + /** * @brief Correction with barometer data. * @@ -76,23 +91,43 @@ public: * @brief Correction with gps data. * * @param gps Vector of the gps readings [n e vn ve][m m m/s m/s]. - * @param sats_num Number of satellites available. */ void correctGPS(const Eigen::Vector4f& gps); + /** + * @brief Correction with gps data only if fix is acquired. + * + * @param gps GPS data. + */ + void correctGPS(const GPSData& gps); + /** * @brief Correction with magnetometer data. * - * @param mag Normalized vector of the magnetometer readings [x y z]. + * @param mag Normalized vector of the magnetometer readings [x y z][uT]. */ void correctMag(const Eigen::Vector3f& mag); + /** + * @brief Correction with magnetometer data. + * + * @param mag Magnetometer data [uT]. + */ + void correctMag(const MagnetometerData& mag); + /** * @brief Correction with accelerometer data. * - * @param u Normalized vector with acceleration data [x y z]. + * @param u Normalized vector with acceleration data [x y z][m/s^2]. */ - void correctAcc(const Eigen::Vector3f& acceleration); + void correctAcc(const Eigen::Vector3f& acc); + + /** + * @brief Correction with accelerometer data. + * + * @param u Acceleration data [m/s^2]. + */ + void correctAcc(const AccelerometerData& acc); /** * @brief Correction with pitot pressure. @@ -129,6 +164,11 @@ public: */ void setReferenceValues(const ReferenceValues reference); + /** + * @brief Returns the current reference values. + */ + ReferenceValues getReferenceValues(); + private: ///< Extended Kalman filter configuration parameters. NASConfig config;