Skip to content

Commit

Permalink
AttPosEKF: Inhibit mag state if not fixed wing and not accelerating f…
Browse files Browse the repository at this point in the history
…orwards
  • Loading branch information
Zefz committed Mar 8, 2015
1 parent 11568c7 commit 34f6cf9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/modules/ekf_att_pos_estimator/estimator_22states.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ AttPosEKF::AttPosEKF() :
moCompR_LOS(0.0f),

_isFixedWing(false),
_onGround(true)
_onGround(true),
_accNavMagHorizontal(0.0f)
{

memset(&last_ekf_error, 0, sizeof(last_ekf_error));
Expand Down Expand Up @@ -350,6 +351,11 @@ void AttPosEKF::UpdateStrapdownEquationsNED()
// variance estimation)
accNavMag = delVelNav.length()/dtIMU;

//First order low-pass filtered magnitude of horizontal nav acceleration
Vector3f derivativeNav = (delVelNav / dtIMU);
float derivativeVelNavMagnitude = sqrtf(sq(derivativeNav.x) + sq(derivativeNav.y));
_accNavMagHorizontal = _accNavMagHorizontal * 0.95f + derivativeVelNavMagnitude * 0.05f;

// If calculating position save previous velocity
float lastVelocity[3];
lastVelocity[0] = states[4];
Expand Down Expand Up @@ -2539,15 +2545,14 @@ void AttPosEKF::setOnGround(const bool isLanded)
if (_onGround || !useAirspeed) {
inhibitWindStates = true;
} else {
inhibitWindStates =false;
inhibitWindStates = false;
}

//Check if we are accelerating forward, only then is the mag offset is observable
bool isMovingForward = _accNavMagHorizontal > 0.5f;

// don't update magnetic field states if on ground or not using compass
if (_onGround || !useCompass) {
inhibitMagStates = true;
} else {
inhibitMagStates = false;
}
inhibitMagStates = useCompass && !_onGround && (_isFixedWing || isMovingForward);

// don't update terrain offset state if there is no range finder and flying at low velocity or without GPS
if ((_onGround || !useGPS) && !useRangeFinder) {
Expand Down
1 change: 1 addition & 0 deletions src/modules/ekf_att_pos_estimator/estimator_22states.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ class AttPosEKF {
private:
bool _isFixedWing; ///< True if the vehicle is a fixed-wing frame type
bool _onGround; ///< boolean true when the flight vehicle is on the ground (not flying)
float _accNavMagHorizontal; ///< First-order low-pass filtered rate of change maneuver velocity
};

uint32_t millis();
Expand Down

0 comments on commit 34f6cf9

Please sign in to comment.