Drone Hits Ceiling: MIS_TAKEOFF_ALT Not Respected with EKF2_HGT_REF = Range Sensor

During an indoor flight test, I observed a potentially critical issue with altitude control using an MTF01 Micro Air Optical Flow sensor. I configured the system to perform a controlled takeoff via QGroundControl with a MIS_TAKEOFF_ALT set to 0.7m, but the drone continued to ascend beyond that and hit the ceiling.

Flight Logs

Setup:
Hardware:
Flight Controller: CubePilot Cube Orange+
Airframe: Holybro X500 V2
Optical Flow + Range Sensor: MTF01 MicroAir (UART)(Link to the sensor)
Software:
PX4 Version: v1.15.4 (99c40407)
QGroundControl
Environment: Indoor (GPS connected but no signal)

Sensor Configuration Parameters Used:
MAV_1_CONFIG = GPS2
MAV_1_MODE = Normal
SER_GPS2_BAUD = 115200 8N1
EKF2_OF_CTRL = Enabled
EKF2_RNG_CTRL = Enabled (Conditional Mode)
EKF2_HGT_REF = Range sensor
SENS_FLOW_ROT = No rotation
MIS_TAKEOFF_ALT = 0.7

Observed Behavior:
The drone armed and took off (Command Given from Q Ground Control )
Expected behavior: Climb to 0.7m then hover.
Actual behavior: The drone kept ascending and collided with the ceiling.

Before the flight, I checked the distance sensor and optical flow sensor output in Mavlink Inspector

Flight Logs

Hey @anuj_yadav , do you still have the mission file you loaded?

Your log shows you armed in position control mode and then you switched to takeoff mode, not mission mode. As QGC let’s you select the takeoff altitude, this will override the MIS_TAKEOFF_ALT, what did you select?

Upon further inspection of the vehicle_command messages, the takeoff request that arrived from qgc had altitude set to 702m.

Thanks @Benja
I didn’t use Mission mode. I used the Takeoff button from the QGroundControl home screen (top-left corner). I didn’t explicitly set any altitude there .
Also, can you please confirm if PX4 actually used the MTF01 MicroAir’s optical flow and rangefinder (LiDAR) data for altitude and position estimation in this flight?

Could you (without taking off) check what’s the default altitude it sets there? It’ s to confirm that a reasonable value was set there (10m for example) and somehow it became 702m.

PX4 used and fused distance from a distance sensor and optical flow from an optical flow sensor. Arcording to the data sensor ID, the data is coming from MAVLINK.

I am thinking of trying to fly the drone in position mode , so i can check if the optical flow is working ,or I will just plan a mission to takeoff (small altitude ) and then land .

@Benja thank you for your valuable advice,
what do you think about this plan ?

Disable GPS in EKF (EKF2_GPS_CTRL = 0) and fly position mode, you won’t even be able to arm if the OF does not work properly.

As an intermediate step, fly altitude mode (so the position is not used for control) and the check the log to see if the estimated local position matched the movement you did

Thanks a lot @Benja
I will try this .