Skip to content

Commit

Permalink
Merge pull request PX4#142 from PX4/pr-ekf2ImproveHeadingReset
Browse files Browse the repository at this point in the history
EKF: Improved heading reset
  • Loading branch information
priseborough committed May 21, 2016
2 parents 4b279a8 + ae5071f commit 4c52522
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions EKF/ekf_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ void Ekf::alignOutputFilter()
bool Ekf::resetMagHeading(Vector3f &mag_init)
{

// calculate the variance for the rotation estimate expressed as a rotation vector
// this will be used later to reset the quaternion state covariances
Vector3f angle_err_var_vec = calcRotVecVariances();

// update transformation matrix from body to world frame using the current estimate
_R_to_earth = quat_to_invrotmat(_state.quat_nominal);

Expand Down Expand Up @@ -404,17 +408,21 @@ bool Ekf::resetMagHeading(Vector3f &mag_init)
_state.quat_nominal = Quaternion(R_to_earth);
}

// reset the quaternion variances because the yaw angle could have changed by a significant amount
// by setting them to zero we avoid 'kicks' in angle when 3-D fusion starts and the imu process noise
// will grow them again.
if (_control_status.flags.tilt_align) {
zeroRows(P, 0, 3);
zeroCols(P, 0, 3);
}

// update transformation matrix from body to world frame using the current estimate
_R_to_earth = quat_to_invrotmat(_state.quat_nominal);

// update the yaw angle variance using the variance of the measurement
if (_params.fusion_mode & MASK_USE_EVYAW) {
// using error estimate from external vision data
angle_err_var_vec(2) = sq(fmaxf(_ev_sample_delayed.angErr, 1.0e-2f));
} else if (_params.mag_fusion_type <= MAG_FUSE_TYPE_3D) {
// using magnetic heading tuning parameter
angle_err_var_vec(2) = sq(fmaxf(_params.mag_heading_noise, 1.0e-2f));
}

// reset the quaternion covariances using the rotation vector variances
initialiseQuatCovariances(angle_err_var_vec);

// calculate initial earth magnetic field states
_state.mag_I = _R_to_earth * mag_init;

Expand Down

0 comments on commit 4c52522

Please sign in to comment.