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

Allow to publish home position when setting the origin #1000

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions EKF/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,9 @@ void Ekf::controlHeightSensorTimeouts()
const bool continuous_bad_accel_hgt = isTimedOut(_time_good_vert_accel, (uint64_t)_params.bad_acc_reset_delay_us);

// check if height has been inertial deadreckoning for too long
const bool hgt_fusion_timeout = isTimedOut(_time_last_hgt_fuse, (uint64_t)5e6);
// in vision hgt mode check for vision data
const bool hgt_fusion_timeout = isTimedOut(_time_last_hgt_fuse, (uint64_t)5e6) ||
(_control_status.flags.ev_hgt && !isRecent(_time_last_ext_vision, 5 * EV_MAX_INTERVAL));

if (hgt_fusion_timeout || continuous_bad_accel_hgt) {

Expand Down Expand Up @@ -876,6 +878,13 @@ void Ekf::controlHeightSensorTimeouts()
failing_height_source = "ev";
new_height_source = "ev";

// Fallback to rangefinder data if available
} else if (_range_sensor.isHealthy()) {
setControlRangeHeight();
request_height_reset = true;
failing_height_source = "ev";
new_height_source = "rng";

} else if (!_baro_hgt_faulty) {
startBaroHgtFusion();

Expand Down Expand Up @@ -1061,11 +1070,13 @@ void Ekf::controlHeightFusion()

case VDIST_SENSOR_EV:

// don't start using EV data unless data is arriving frequently
// don't start using EV data unless data is arriving frequently, do not reset if pref mode was height
if (!_control_status.flags.ev_hgt && isRecent(_time_last_ext_vision, 2 * EV_MAX_INTERVAL)) {
fuse_height = true;
setControlEVHeight();
resetHeight();
if (!_control_status_prev.flags.rng_hgt) {
resetHeight();
}
}

if (_control_status.flags.baro_hgt && _baro_data_ready && !_baro_hgt_faulty) {
Expand Down
16 changes: 16 additions & 0 deletions EKF/ekf_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,20 @@ void Ekf::resetHeight()

// reset the vertical position
if (_control_status.flags.rng_hgt) {

// a fallback from any other height source to rangefinder happened
if(!_control_status_prev.flags.rng_hgt) {

if (_control_status.flags.in_air && isTerrainEstimateValid()) {
_hgt_sensor_offset = _terrain_vpos;
} else if (_control_status.flags.in_air) {
_hgt_sensor_offset = _range_sensor.getDistBottom() + _state.pos(2);
} else {
_hgt_sensor_offset = _params.rng_gnd_clearance;
}

}

// update the state and associated variance
resetVerticalPositionTo(_hgt_sensor_offset - _range_sensor.getDistBottom());

Expand Down Expand Up @@ -705,6 +719,8 @@ bool Ekf::setEkfGlobalOrigin(const double latitude, const double longitude, cons
map_projection_reproject(&_pos_ref, _state.pos(0), _state.pos(1), &current_lat, &current_lon);
current_alt = -_state.pos(2) + _gps_alt_ref;
current_pos_available = true;
} else {
_NED_origin_initialised = true;
}

// reinitialize map projection to latitude, longitude, altitude, and reset position
Expand Down
5 changes: 3 additions & 2 deletions test/test_EKF_fusionLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ TEST_F(EkfFusionLogicTest, doVisionHeightFusion)
_sensor_simulator.runSeconds(12);

// THEN: EKF should stop to intend to use vision height
// TODO: This is not happening
EXPECT_TRUE(_ekf_wrapper.isIntendingVisionHeightFusion()); // TODO: Needs to change

EXPECT_FALSE(_ekf_wrapper.isIntendingVisionHeightFusion());
EXPECT_TRUE(_ekf_wrapper.isIntendingBaroHeightFusion());
}