I will use maxbotic I2C sonar to estimate the altitude precisely. I use the driver in /driver/mb12xx.cpp file and publish the distance_sensor topic. I see position_estimator_inav module uses it and publish the distance from ground field in the vehicle_local_position topic. In PX4, what should I do in order to use sonar sensor value together with barometer? I think it uses baro and gps value to estimate altitude, am I right?
I am not familiar with INAV. LPE is currently the default estimator and EKF2 is the most recent development. Both of the latter use range measurements to aid with height as well as terrain estimation. I.e. these estimators fuse range measurements with GPS and baro. For LPE, this happens here:
A quick glance at INAV leads me to believe that it uses range sensors (referred to as lidar measurements in INAV) if available, otherwise baro. I.e. it does not use the two as LPE or EKF2 do:
I would suggest you upgrade to a more modern estimator.