Browse Source

EKF: Add method to reset wind state covariances

Set variances in polar coordinates and rotate into cartesian frame
master
Paul Riseborough 9 years ago committed by CarlOlsson
parent
commit
6dff2df28e
  1. 32
      EKF/covariance.cpp
  2. 3
      EKF/ekf.h

32
EKF/covariance.cpp

@ -794,3 +794,35 @@ void Ekf::resetMagCovariance() @@ -794,3 +794,35 @@ void Ekf::resetMagCovariance()
P[rc_index][rc_index] = sq(_params.mag_noise);
}
}
void Ekf::resetWindCovariance()
{
// set the wind covariance terms to zero
zeroRows(P,22,23);
zeroCols(P,22,23);
// calculate the wind speed and bearing
float spd = sqrtf(sq(_state.wind_vel(0))+sq(_state.wind_vel(1)));
float yaw = atan2f(_state.wind_vel(1),_state.wind_vel(0));
// calculate the uncertainty in wind speed and direction using the uncertainty in airspeed and sideslip angle
// used to calculate the initial wind speed
float R_spd = sq(math::constrain(_params.eas_noise, 0.5f, 5.0f) * math::constrain(_airspeed_sample_delayed.eas2tas, 0.9f, 10.0f));
float R_yaw = sq(0.1745f);
// calculate the variance and covariance terms for the wind states
float cos_yaw = cosf(yaw);
float sin_yaw = sinf(yaw);
float cos_yaw_2 = sq(cos_yaw);
float sin_yaw_2 = sq(sin_yaw);
float sin_cos_yaw = sin_yaw*cos_yaw;
float spd_2 = sq(spd);
P[22][22] = R_yaw*spd_2*sin_yaw_2 + R_spd*cos_yaw_2;
P[22][23] = - R_yaw*sin_cos_yaw*spd_2 + R_spd*sin_cos_yaw;
P[23][22] = P[22][23];
P[23][23] = R_yaw*spd_2*cos_yaw_2 + R_spd*sin_yaw_2;
// Now add the variance due to uncertainty in vehicle velocity that was used to calculate the initial wind speed
P[22][22] += P[4][4];
P[23][23] += P[5][5];
}

3
EKF/ekf.h

@ -430,4 +430,7 @@ private: @@ -430,4 +430,7 @@ private:
// perform a limited reset of the magnetic field state covariances
void resetMagCovariance();
// perform a limited reset of the wind state covariances
void resetWindCovariance();
};

Loading…
Cancel
Save