Skip to content

Commit 0f49eb3

Browse files
RomanBapstpriseborough
authored andcommitted
fixed method which calculates validity of terrain estimate
Signed-off-by: RomanBapst <[email protected]>
1 parent cd34ab8 commit 0f49eb3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

EKF/terrain_estimator.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ void Ekf::fuseFlowForTerrain()
242242
_terrain_vpos += Kx * _flow_innov[0];
243243
// guard against negative variance
244244
_terrain_var = fmaxf(_terrain_var - KxHxP, 0.0f);
245+
_time_last_of_fuse = _time_last_imu;
245246
}
246247

247248
// Calculate observation matrix for flow around the vehicle y axis
@@ -269,6 +270,7 @@ void Ekf::fuseFlowForTerrain()
269270
_terrain_vpos += Ky * _flow_innov[1];
270271
// guard against negative variance
271272
_terrain_var = fmaxf(_terrain_var - KyHyP, 0.0f);
273+
_time_last_of_fuse = _time_last_imu;
272274
}
273275
}
274276

@@ -281,7 +283,15 @@ bool Ekf::get_terrain_valid()
281283
// determine terrain validity
282284
void Ekf::update_terrain_valid()
283285
{
284-
if (_terrain_initialised && ((_time_last_imu - _time_last_hagl_fuse) < (uint64_t)5e6)) {
286+
// we have been fusing range finder measurements in the last 5 seconds
287+
bool recent_range_fusion = (_time_last_imu - _time_last_hagl_fuse) < 5*1000*1000;
288+
289+
// we have been fusing optical flow measurements for terrain estimation within the last 5 seconds
290+
// this can only be the case if the main filter does not fuse optical flow
291+
bool recent_flow_for_terrain_fusion = ((_time_last_imu - _time_last_of_fuse) < 5*1000*1000) && !_control_status.flags.opt_flow;
292+
293+
294+
if (_terrain_initialised && (recent_range_fusion || recent_flow_for_terrain_fusion)) {
285295

286296
_hagl_valid = true;
287297

0 commit comments

Comments
 (0)