EKF2 not working


We are working with Pixhawk Cube Black and PX4-Autopilot v1.11.3. We are doing indoor flight tests with distance(Lidar-Lite v3) and optical flow(HereFlow) sensors. Our drone had crashed multiple times.

In tests, lidar and barometer measurements are accurate but EKF2 outputs such as vehicle_local_position/z value are miscalculated. In this specific log file EKF2_HGT_MODE is set to barometric pressure and EKF2_RNG_AID is set to enabled. We tried other combinations of various parameters of EKF2 and failed. We can not find the source of error. Any help is appreciated, thank you.

Flight Review : https://logs.px4.io/plot_app?log=9b99c2bb-44f4-46c9-970c-b4cceb8d9a5e

Hello Ozan-Alp,

Could you describe which sensors you are using to estimate the altitude?
Are you using the 1D lidar?


Okay I guess you are using Lidar-Lite v3 as the sensor to measure altitude

Try setting parameter:
as 2 (I2C) or 1 (PWM)

I’m guessing you are using I2C

Also, your EKF2_AID_MASK parameter seems to be set to 6
I think this has to be 1 if you are using optical flow sensor


I have tens of tests with different parameters,normally EKF2_AID_MASK was set to number 1 bit starting fom 0 (optical flow was ticked) which equals to 2. In this log i tried to inhibit imu bias too, which is number 2 starting from 0, so …0110 bitmask converts to 2^1+2^2=6.

I2C was selected. Lidar-Lite v3 is used as a range sensor, but in tests regardless of choosing primary height source as range sensor or enabling range aid, ekf switches between range sensor and barometer.

I will send other logs in Monday. In all tests there is one common problem. Drone stops using RC input and acts on its own. Estimated local z and lidar/baro measurements become irrevelant.

You’re right, Optical flow is 2, not 1. My bad

I’m guessing the Distance data is being published in the MAVLink inspector, correct?

First, set EKF2_HGT_MODE as 2 (Range sensor)

and here is the important part:
Set EKF2_RNG_AID to 0 (Range aid disabled)

Then compare the altitude from distance sensor and from local position

Changing the noise covariance parameters may also help,
by minimizing EKF2_RNG_NOISE and maximizing EKF2_BARO_NOISE


Uorb topic is published, I can monitor distance_sensor from QGroundcontrol. I tried all of EKF2_HGT_MODE and EKF2_RNG_AID combinations (baro&aid_enabled, baro&aid_disabled, range&aid_enabled, range&aid_disabled). Even in gazebo simulation, for all combinations(except baro&aid_disabled) EKF2 primary height sensor flag switches between baro and range sensor, but innovation test of range sensor does not exceed 1. EKF2 seems to reject range data while it is healthy. I did not change NOISE parameters, I will try that and provide the log file in Monday. Thank you.

Setting EKF2_HGT_MODE as 2 and EKF2_RNG_AID to 0 did not work, i lost the log but switch problem and wrong altitude estimation continued. I want to use barometer when drone altitude exceeds maximum lidar range so changing noise is not good for me. Here are some other logs.

Log1: Range&aid enabled. Local position started from -4 meters.

Log2: Baro&aid enabled. Drone jumped while in air while there was no rc command to do that(t=110s), and when drone was on ground local z skyrocketed to 4 meters(t=140s)