Skip to content
Snippets Groups Projects
Commit e29b6fef authored by Emilio Corigliano's avatar Emilio Corigliano
Browse files

[NAS] Updated correctBaro

parent afe000f4
Branches
No related tags found
1 merge request!306[NAS] Updated GPS, barometer, accelerometer and pitot corrects
...@@ -153,28 +153,35 @@ void NAS::predictGyro(const GyroscopeData& angularSpeed) ...@@ -153,28 +153,35 @@ void NAS::predictGyro(const GyroscopeData& angularSpeed)
void NAS::correctBaro(const float pressure) void NAS::correctBaro(const float pressure)
{ {
Matrix<float, 1, 6> H = Matrix<float, 1, 6>::Zero(); float altitude = -x(2);
float temp = Aeroutils::relTemperature(altitude, reference.refTemperature);
// Temperature at current altitude. Since in NED the altitude is negative, Matrix<float, 1, 6> H = Matrix<float, 1, 6>::Zero();
// mslTemperature returns temperature at current altitude and not at msl Matrix<float, 1, 1> R = Matrix<float, 1, 1>(powf(config.SIGMA_BAR, 2));
float temp = Aeroutils::relTemperature(-x(2), reference.refTemperature);
// Compute gradient of the altitude-pressure function // Compute gradient of the altitude-pressure function
H[2] = Constants::a * Constants::n * reference.refPressure * H[2] = Constants::a * Constants::n * reference.refPressure *
powf(1 - Constants::a * x(2) / temp, -Constants::n - 1) / temp; powf(1 + Constants::a * altitude / temp, Constants::n - 1) / temp;
Matrix<float, 6, 6> Pl = P.block<6, 6>(0, 0); Matrix<float, 6, 6> Pl = P.block<6, 6>(0, 0);
Matrix<float, 1, 1> S = Matrix<float, 1, 1> S = H * Pl * H.transpose() + R;
H * Pl * H.transpose() + Matrix<float, 1, 1>(config.SIGMA_BAR);
Matrix<float, 6, 1> K = Pl * H.transpose() * S.inverse(); // If not invertible, don't do the correction and return
P.block<6, 6>(0, 0) = (Matrix<float, 6, 6>::Identity() - K * H) * Pl; if (S.determinant() < 1e-3)
{
return;
}
float y_hat = float y_hat =
Aeroutils::relPressure(reference.refAltitude - x(2), Aeroutils::relPressure(reference.refAltitude - x(2),
reference.mslPressure, reference.mslTemperature); reference.mslPressure, reference.mslTemperature);
Matrix<float, 1, 1> e = Matrix<float, 1, 1>(pressure - y_hat);
Matrix<float, 6, 1> K = Pl * H.transpose() * S.inverse();
P.block<6, 6>(0, 0) = (Matrix<float, 6, 6>::Identity() - K * H) * Pl;
// Update the state // Update the state
x.head<6>() = x.head<6>() + K * (pressure - y_hat); x.head<6>() = x.head<6>() + K * e;
} }
void NAS::correctGPS(const Vector4f& gps) void NAS::correctGPS(const Vector4f& gps)
......
...@@ -37,7 +37,7 @@ struct NASConfig ...@@ -37,7 +37,7 @@ struct NASConfig
Eigen::Vector4f SIGMA_GPS; ///< [millideg^2, millideg^2, m^2/s^2, m^2/s^2] Eigen::Vector4f SIGMA_GPS; ///< [millideg^2, millideg^2, m^2/s^2, m^2/s^2]
///< estimated GPS variance. position from test, ///< estimated GPS variance. position from test,
///< velocity from datasheet ///< velocity from datasheet
float SIGMA_BAR; ///< [m^2] Estimated altitude variance float SIGMA_BAR; ///< [Pa] Estimated altitude variance
float SIGMA_POS; ///< [m^2] Estimated variance of the position noise float SIGMA_POS; ///< [m^2] Estimated variance of the position noise
float SIGMA_VEL; ///< [(m/s)^2] Estimated variance of the velocity noise float SIGMA_VEL; ///< [(m/s)^2] Estimated variance of the velocity noise
float SIGMA_PITOT; ///< [Pa^2] Estimated variance of the pitot velocity float SIGMA_PITOT; ///< [Pa^2] Estimated variance of the pitot velocity
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment