@Benjamin and @ton999 thanks for reporting this! It is great that you are using SITL to check this type of behaviour.
I had a look at it, and reproduced the issue. It turns out not to be a terrain problem, but a very small difference between how baro is fused in the EKF.
The top of the mountain is 2532m AMSL.
In the 4.0.3 log the GPS altitude peaks at 2540m. At that time the BARO altitude, adjusted for home alt, is 2687. So the plane thinks it is 150m over the ground, when in fact it is skimming the tops of the trees.
In the 4.1.0 log the GPS altitude peaks at 2536m and the baro at 2686. It does manage to just touch the top of the mountain in SITL. The difference between 4.1 and 4.0 is very small, but just enough to make the difference.
If you change the EKF to use GPS alt then it clears the mountain with no problem. For EKF2 use EK2_ALT_SOURCE=2. For EKF3 use EK3_SRC1_POSZ=3.
This is a general problem with our atmospheric simulation in SITL. I have fixed it in this PR:
but that PR was a bit too late for 4.1.0. I may include it in a later 4.1.x release. I tested your mission with that PR and baro altitude and it clears the top of the mountain by 150m, which is what the mission asks for.
It is also worth mentioning that when doing SITL tests of terrain code that a high speedup can cause issues due to the way the timing works with the terrain thread. It may not be able to fetch blocks far enough ahead to be able to climb. At speedup 10x it is flying at 250m/s, which is pretty quick!
The second lesson is that if you ever do want to fly a mission like this then use GPS altitude with a good quality GPS (such as ublox F9P). Don’t rely on the barometer when you go through that much height change.
Thank you very much for your analysis. So based on this fact, I conclude that it is better and safer to use GPS as the main Altitude source than barometer, right? I am curious to understand why in default setting we use barometer? What is the reason or benefits of using baro compared with Gps? Thank you.
it isn’t as clear as that. It depends on the mission and which GPS.
A M8 or lower u-blox may sometimes have 10s of meter of altitude error. That is terrible for vehicle landing without rangefinder, but the error doesn’t tend to grow larger as the mission covers a wider height range. The baro error is usually small for a local flight, but gets worse as you fly for a long time or over a large height range.
The best option if you can afford it is a better quality GPS. Hopefully as the new L5 band starts getting more widely available (and in full service) lower cost GNSS modules that have good height accuracy will become common.