When I tested terrain following, I noticed that EKF keeps using the RangeFinder and eventually targets incorrect altitude even though EK3_RNG_USE_HGT < 0. I am sure whether this is known issue or I misunderstand terrain following of EKF3. Just in case, I would like to explain the issue in here.
If the aim is to do surface tracking or terrain following then the EKF is not involved at all and so no EKF related parameter changes should be made (and you haven’t which is great). The EKF is not responsible for estimating the height above terrain for these use-cases… instead the EKF just does what it always does which is estimate the altitude (above the EKF origin which can be converted to alt-above-home or alt-above-sea-level) using barometer or GPS altitude.
If you look closely into the EKF you may find that it does actually calculate an altitude above terrain but this is only for use with an optical flow sensor.
I’m not sure if this answers your question but hopefully it’s a step towards that and happy to discuss further of course.
This discusion may be related to something I have not been able to do in months in the real thing and in SITL: mix in a mission waypoints referenced to Terrain (third parameter 10 (rangefinder)) and Relative (third parameter 3 (barometer)).
This mission in SITL shows it: three W’s in a vertical plane referenced Terrain/Relative/mixed. The mix is:
-High W points Relative (third parameter 3 (barometer)).
-Low W points Terrain (third parameter 10 (rangefinder)).
The first two W’s are followed normally. For the third, after starting on the high waypoint (third parameter 3), it happens as if it wouldn’t “know” how to go to the following low waypoint (third parameter 10, blue above), “Failsafe terrain data missing” is heard, and the vehicle does an RTL.
RTL occurs at t=155s, as appears in the video index.
I don’t know if I am missing something, or this a system limitation I can’t find documented. I have asked about this in the past, resulting the answers the Empty Set ∅.
This happens also in the real thing on all versions I have tried.
This is the SITL parameters file with relevant aparameters: RNGFND1_MAX_CM 700 TERRAIN_ENABLE 0
Something missing? Is the mixture allowed? Explanation if not?
Thanks for testing 4.1. So I think you’re trying to do terrain following but some of the waypoint altitudes are beyond the range of the rangefinder? If “yes” then I’m afraid this won’t work. For it to do a mission command with a terrain altitude the vehicle must always be flying below the maximum range of the rangefinder.
I think you’ll find that if you switch over to use the terrain database (by setting TERR_ENABLE = 1) and disable the rangefinder that it does work… but of course it won’t be as accurate.
Waypoint 19 is at 20m (> RNGFND1_MAX_CM), defined Relative (third parameter 3), and is reached.
Waypoint 20 is at 1m (< RNGFND1_MAX_CM), defined Terrain (third parameter 10), and is not reached ( “ Failsafe terrain data missing ” is heard, and the vehicle does an RTL).
Do you mean that it cannot reach a waypoint within rangefinder range (referenced Terrain third parameter 10) from a waypoint out of rangefinder range (referenced Relative third parameter 3) by design? It is hard to accept that.
I simply want to use the rangefinder (which works accurately in the first W (all waypoints Terrain, third parameter 10)) to go from a high point to a low point close to ground accurately.
After a vehicle arrives at waypoint 2, it shows “Failsafe terrain data missing” and conduct RTL flight mode because the AGL altitude is higher than 12 meters at waypoint 2.
In my understanding, @rmackay9 says that we need to use the terrain database if any waypoint in the mission exceeds the maximum range of the rangefinder. Please correct me if I am wrong.
I wanted to point out that if I turn on the rangefinder and set TERRAIN_ENABLE = 1, the vehicle keeps targeting incorrect altitude (target altitude is 30 meters in the mission), but the vehicle stays at 52 meters (relative), 85 meters (AGL), and 34 meters (rangefinder).
After the vehicle passes the waypoint at 20m (rel) and starts towards the waypoints with 1m (terrain) alt it immediately needs to know its altitude above terrain. The reason is that it does not fly a straight line from the rel waypoint to the terr waypoint, instead it flies from it’s current alt above terrain to the waypoint’s alt-above-terrain. The terrain following wiki page’s Warning section has this picture which may explain this.
You hit the nail! Thinking in terms of a “straight line” suggests the solution: before any Terrain waypoint from a Relative one insert a Relative one with same lat/lon coordinates, and height within rangefinder reach: