Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
mag_control: fuse fake heading during leveling fine alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
bresch authored and dagar committed Jul 26, 2021
1 parent 8a0510d commit df3481b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
36 changes: 18 additions & 18 deletions EKF/mag_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,6 @@

void Ekf::controlMagFusion()
{
// handle undefined behaviour
if (_params.mag_fusion_type > MAG_FUSE_TYPE_NONE) {
return;
}

// When operating without a magnetometer and no other source of yaw aiding is active,
// yaw fusion is run selectively to enable yaw gyro bias learning when stationary on
// ground and to prevent uncontrolled yaw variance growth
if (_params.mag_fusion_type == MAG_FUSE_TYPE_NONE) {
if (noOtherYawAidingThanMag())
{
_is_yaw_fusion_inhibited = true;
fuseHeading();
}
return;
}

checkMagFieldStrength();

// If we are on ground, reset the flight alignment flag so that the mag fields will be
Expand All @@ -67,8 +50,25 @@ void Ekf::controlMagFusion()
_num_bad_flight_yaw_events = 0;
}

if (_control_status.flags.mag_fault || !_control_status.flags.tilt_align) {
// When operating without a magnetometer and no other source of yaw aiding is active,
// yaw fusion is run selectively to enable yaw gyro bias learning when stationary on
// ground and to prevent uncontrolled yaw variance growth
// Also fuse zero heading innovation during the leveling fine alignment step to keep the yaw variance low
if (_params.mag_fusion_type >= MAG_FUSE_TYPE_NONE
|| _control_status.flags.mag_fault
|| !_control_status.flags.tilt_align) {

stopMagFusion();

if (noOtherYawAidingThanMag())
{
// TODO: setting _is_yaw_fusion_inhibited to true is required to tell
// fuseHeading to perform a "zero innovation heading fusion"
// We should refactor it to avoid using this flag here
_is_yaw_fusion_inhibited = true;
fuseHeading();
_is_yaw_fusion_inhibited = false;
}
return;
}

Expand Down
8 changes: 8 additions & 0 deletions EKF/mag_fusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,10 @@ void Ekf::fuseHeading()
// Vehicle is at rest so use the last moving prediction as an observation
// to prevent the heading from drifting and to enable yaw gyro bias learning
// before takeoff.
if (fabsf(_last_static_yaw) < 1e-6f) {
_last_static_yaw = predicted_hdg;
}

measured_hdg = _last_static_yaw;

}
Expand Down Expand Up @@ -818,6 +822,10 @@ void Ekf::fuseHeading()
// Vehicle is at rest so use the last moving prediction as an observation
// to prevent the heading from drifting and to enable yaw gyro bias learning
// before takeoff.
if (fabsf(_last_static_yaw) < 1e-6f) {
_last_static_yaw = predicted_hdg;
}

measured_hdg = _last_static_yaw;

}
Expand Down

0 comments on commit df3481b

Please sign in to comment.