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

Commit

Permalink
Ekf: centralize GPS height fusion startup
Browse files Browse the repository at this point in the history
  • Loading branch information
bresch committed Apr 16, 2020
1 parent 65e7c85 commit b77988e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
10 changes: 2 additions & 8 deletions EKF/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ void Ekf::controlHeightSensorTimeouts()
// set height sensor health
_baro_hgt_faulty = true;

setControlGPSHeight();
startGpsHgtFusion();

request_height_reset = true;
ECL_WARN_TIMESTAMPED("baro hgt timeout - reset to GPS");
Expand Down Expand Up @@ -1018,14 +1018,8 @@ void Ekf::controlHeightFusion()
}

} else if (!do_range_aid && _gps_data_ready && !_gps_hgt_intermittent && _gps_checks_passed) {
setControlGPSHeight();
fuse_height = true;

// we have just switched to using gps height, calculate height sensor offset such that current
// measurement matches our current height estimate
if (_control_status_prev.flags.gps_hgt != _control_status.flags.gps_hgt) {
_hgt_sensor_offset = _gps_sample_delayed.hgt - _gps_alt_ref + _state.pos(2);
}
startGpsHgtFusion();

} else if (_control_status.flags.baro_hgt && _baro_data_ready && !_baro_hgt_faulty) {
// switch to baro if there was a reset to baro
Expand Down
1 change: 1 addition & 0 deletions EKF/ekf.h
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ class Ekf : public EstimatorInterface
void startMag3DFusion();

void startBaroHgtFusion();
void startGpsHgtFusion();

// calculate the measurement variance for the optical flow sensor
float calcOptFlowMeasVar();
Expand Down
11 changes: 11 additions & 0 deletions EKF/ekf_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1487,6 +1487,17 @@ void Ekf::startBaroHgtFusion()
}
}

void Ekf::startGpsHgtFusion()
{
setControlGPSHeight();

// we have just switched to using gps height, calculate height sensor offset such that current
// measurement matches our current height estimate
if (_control_status_prev.flags.gps_hgt != _control_status.flags.gps_hgt) {
_hgt_sensor_offset = _gps_sample_delayed.hgt - _gps_alt_ref + _state.pos(2);
}
}

// update the rotation matrix which rotates EV measurements into the EKF's navigation frame
void Ekf::calcExtVisRotMat()
{
Expand Down
4 changes: 1 addition & 3 deletions EKF/gps_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ bool Ekf::collect_gps(const gps_message &gps)

if (_params.vdist_sensor_type == VDIST_SENSOR_GPS) {
ECL_INFO_TIMESTAMPED("GPS checks passed (WGS-84 origin set, using GPS height)");
setControlGPSHeight();
// zero the sensor offset
_hgt_sensor_offset = 0.0f;
startGpsHgtFusion();
} else {
ECL_INFO_TIMESTAMPED("GPS checks passed (WGS-84 origin set)");
}
Expand Down

0 comments on commit b77988e

Please sign in to comment.