Altitude drift when range sensor is enabled

I am trying to simulate px4flow with lidar as the primary height sensor in gazebo, i am using flat surface. Problem is it does not stay stabilized in Z axis in position/altitude hold modes.

When i set EKF2_HGT_MODE to barometric pressure and enable EKF2_RNG_AID, maximum drift in distance sensor is 18cm and there is a gap between vehicle_local_position/z and vehicle_local_position/bottom_dist. I do not know if it is normal.

Barometer setup (i reversed vehicle_local_position/z to positive in plots):

But when i change EKF2_HGT_MODE to range sensor, vehicle_local_position/z is stabilized and vehicle_local_position/dist_bottom goes crazy.

Range sensor setup:


Log: https://review.px4.io/plot_app?log=cfdd4239-3c96-4422-840f-17f4e52e6f52

I tried altitude hold with only lidar, same results occured. Can you help?
Thanks

Solution: When i checked estimator_status/control_flags i found out that primary height sensor was switching continuously between range sensor and barometer .

From Terrain height and z-position estimates for rangefinder + optical flow fusion. Solved by Barometer disable. · Issue #955 · PX4/PX4-ECL · GitHub step 2, i commented code lines which enable barometer when range sensor health flag was false and it worked perfectly.

I do not know why range sensor gave false fails, lidar data was fine.