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

Commit 5d34d7a

Browse files
authored
Height source vision: Fallback to rangefinder if available (#994)
1 parent da06f25 commit 5d34d7a

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

EKF/control.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,9 @@ void Ekf::controlHeightSensorTimeouts()
787787
const bool continuous_bad_accel_hgt = isTimedOut(_time_good_vert_accel, (uint64_t)_params.bad_acc_reset_delay_us);
788788

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

792794
if (hgt_fusion_timeout || continuous_bad_accel_hgt) {
793795

@@ -876,6 +878,13 @@ void Ekf::controlHeightSensorTimeouts()
876878
failing_height_source = "ev";
877879
new_height_source = "ev";
878880

881+
// Fallback to rangefinder data if available
882+
} else if (_range_sensor.isHealthy()) {
883+
setControlRangeHeight();
884+
request_height_reset = true;
885+
failing_height_source = "ev";
886+
new_height_source = "rng";
887+
879888
} else if (!_baro_hgt_faulty) {
880889
startBaroHgtFusion();
881890

@@ -1061,11 +1070,13 @@ void Ekf::controlHeightFusion()
10611070

10621071
case VDIST_SENSOR_EV:
10631072

1064-
// don't start using EV data unless data is arriving frequently
1073+
// don't start using EV data unless data is arriving frequently, do not reset if pref mode was height
10651074
if (!_control_status.flags.ev_hgt && isRecent(_time_last_ext_vision, 2 * EV_MAX_INTERVAL)) {
10661075
fuse_height = true;
10671076
setControlEVHeight();
1068-
resetHeight();
1077+
if (!_control_status_prev.flags.rng_hgt) {
1078+
resetHeight();
1079+
}
10691080
}
10701081

10711082
if (_control_status.flags.baro_hgt && _baro_data_ready && !_baro_hgt_faulty) {

EKF/ekf_helper.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,20 @@ void Ekf::resetHeight()
262262

263263
// reset the vertical position
264264
if (_control_status.flags.rng_hgt) {
265+
266+
// a fallback from any other height source to rangefinder happened
267+
if(!_control_status_prev.flags.rng_hgt) {
268+
269+
if (_control_status.flags.in_air && isTerrainEstimateValid()) {
270+
_hgt_sensor_offset = _terrain_vpos;
271+
} else if (_control_status.flags.in_air) {
272+
_hgt_sensor_offset = _range_sensor.getDistBottom() + _state.pos(2);
273+
} else {
274+
_hgt_sensor_offset = _params.rng_gnd_clearance;
275+
}
276+
277+
}
278+
265279
// update the state and associated variance
266280
resetVerticalPositionTo(_hgt_sensor_offset - _range_sensor.getDistBottom());
267281

test/test_EKF_fusionLogic.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ TEST_F(EkfFusionLogicTest, doVisionHeightFusion)
379379
_sensor_simulator.runSeconds(12);
380380

381381
// THEN: EKF should stop to intend to use vision height
382-
// TODO: This is not happening
383-
EXPECT_TRUE(_ekf_wrapper.isIntendingVisionHeightFusion()); // TODO: Needs to change
382+
383+
EXPECT_FALSE(_ekf_wrapper.isIntendingVisionHeightFusion());
384+
EXPECT_TRUE(_ekf_wrapper.isIntendingBaroHeightFusion());
384385
}

0 commit comments

Comments
 (0)