Rangefinder as only altitude source

Hello,

I am trying to connect a custom distance sensor to my copter facing downwards to measure altitude. So far I have succesfully connected a Raspberry Pi companion computer via MAVROS and I am able to read out the transfered distance_sensor_msg in the QGC’s MAVLINK inspector.

My goal is to have the copter solely rely on the data from the distance sensor to prove it’s capabilities. This means I would like the copter to ignore barometer as well as GPS altidude data.

To test this I fly the copter in position mode (altitude mode should also be fine) on a stable height (let’s say 1 m), then manuver it over a box (0.5 m). My expectation would be that since the distance to the ground decreases, the copter will fly up (to 1.5 m over floor which is 1 m over the box) to try to maintain it’s previous distance to the ground.

In my current tests the copter did not rise any further when directly over the box. I was able to see that the distance_sensor_msg changes as expected but the Vehicle_AltitudeRelative remained the same. Because of that I assume that PX4 eighter ignores the distance sensor completely, or it fuses altitude data from other sensors as well as IMU and thinks the distance sensor gives faulty readings, again ignoring it.

I wonder if there is a parameter that would allow me to achieve my goal, here is what I have tried so far:

  • EKF2_RNG_CTRL: 2 (Enabled) - Always read rangefinder data
    1 (Enabled, Conditional mode) - Read rangefinder at low speed
  • EKF2_HGT_REF: 2 (Range sensor) - Use rangefinder as primary source of height
  • MPC_ALT_MODE: 1 (Terrain following) - Adjust height to rangefinder reading, both when hovering and moving

After these basic settings I tried to manually deactivate other height sources, in that case GPS and Barometer:

  • EKF2_BARO_CTRL: 0 (Disabled) - Do not read barometer data
  • EKF2_GPS_CTRL: 5 - Bitmask (Position, 3D Velocity)
    7 - Bitmask (Position, 3D Velocity, Altitude)

In case of the barometer according to this post Distance sensor as only source of altitude - #4 by AlexandreBorowczyk I tried to increase it’s noise to have the EKF igrnore the baro:

  • EKF2_BARO_NOISE: 3 m → 15 m

I also played around with the time delay of the rangefinder (since it actually has a noticiable delay between the publishing of the ROS message and the readout of the distance_sensor_msg in QGC)

  • EKF2_RNG_DELAY: 5 ms → 300 ms

None of these options has achieved my goal, yet.

I was also thinking that it might be a vibration problem that could be solved by tuning the copter. I would be happy if anyone could give me a clue on what to try next or where to find out how the altitude is processed in PX4.