Stable Altitude During Flight

I’m trying to fly a low-level grid while maintaining a stable AGL. I’m using an F450 with the old PixHawk. The copter slowly loses altitude until reaching the next waypoint. I’m considering integrating a sonar sensor, but want to see if anyone has had much experience testing this. I’m concerned that copter attitude will cause problems. Also, this might be a software issue and I don’t know if the flight software will make altitude adjustments in between waypoints. Any thoughts?

I solved with a laser altimeter :

Thanks Cala. I guess I should have mentioned my budget constraints. This is for a school project. I did look into Lidar options, but they were all well above my my price. This is why I am looking into sonar (such as the maxbotic).

You can find some info about sonar in diy drones too, but you can try to solve your issue too, can you share a photo from your copter and a log loosing altitude?

I don’t have a cam attached to the copter. The log is fairly long and I’m new so don’t fully understand the range of values. I believe it happened around 14:34:00 based on my noobie analysis, but I don’t really remember. I was trying to fly low altitude from one WP to another and had to switch from auto to loiter a couple times. Once, it hit the grass and flipped.2017-04-27 14-14-30.tlog (2.9 MB)

I refer to a log where you can find in the sd card installed in your pixhawk and a photo of your copter to see how it is, It´s a common issue that loose altitude when some air changes pressure around barometer, I suffered in the past and solve covering the controller with a desechable salad bowl, there is a large discussion in Diy Drones forum but I can´t find now, if I find I share for you.