I’m using the MAVLink protocol to read altitude data from my flight controller. Specifically, I’ve been using the GLOBAL_POSITION_INT message and the “relative home alt” value. Since my drone flights usually take place over flat terrain, I assumed this would give me the most accurate altitude readings.
However, during my recent flights using this value, I noticed some strange fluctuations-it often reports the wrong altitude, sometimes with errors as large as 1.5 meters! Since I was using this reported altitude to generate movement commands (which I sent via SET_POSITION_TARGET_LOCAL_NED), the copter almost hit obstacles several times, and on one occasion, it actually crashed and was seriously damaged because of the inaccurate altitude from GLOBAL_POSITION_INT.
Just for reference, my EKF settings are: EK3_SRC1_POSZ = 2 (RangeFinder) and EK3_SRC2_POSZ = 1 (Baro).
I’ve noticed that there are other, seemingly more accurate altitude sources available-like the altitude in CTUN or the mg(measured range) in XKF5. Unfortunately, these values are only available in logs and aren’t sent to the ground station via MAVLink.
Is there any way to get these more accurate altitude values sent to the ground station using MAVLink? Or is there another altitude source that reliably provides the true altitude above ground level in real time?
In general EK3_SRC1_POSZ should be set to 1 (baro) or 3 (GPS). 2(RangeFinder) is never a good idea if the vehicle is flying outdoors. “2” should only be used in a location where the ground is completely flat. This normally means only indoors and only indoors where there are no stairs, tables or anything else which could lead to sudden, non-altitude related changes in rangefinder distance
Variations in the EKF’s altitude (when using barometer) are probably caused by changes in the air pressure related to the attitude of the vehicle. We do have compensation in ardupilot but the configuration is tricky so normally a hardware solution is best.
By the way, AP also has an alt-above-terrain which uses the internal terrain database but this doesn’t include “ground clutter” (trees, buildings, etc).
Sorry if I haven’t completely answered the question
Thanks so much for your time and reply!
First, I tried the normal setup you mentioned (EK3_SRC1_POSZ = 1). However, when I checked the altitude report during flight, it showed about 0.5 meters, even though I was keeping the quad about 2 meters above the ground!
I think this might be because, in my setup and frame, the flight controller is sandwiched between two carbon fiber plates, and there are many cables and connectors around it. This probably affects the air pressure sensor, making its readings less accurate and reliable near the FC. So, the altitude data isn’t as true or precise as I’d like.
My goal is to find the best setup and parameter configuration to get highly accurate altitude measurements.
Given this kind of setup, what would you suggest to improve the accuracy? Any tips or tricks would be really appreciated!
Re the alt reported by the GCS, it’s normally the alt-above-home although there should be alt-above-sea-level and rangefinder distances that are also reported by the autopilot that can be viewed in the GCS.
Barometers drift sadly especially soon after takeoff on vehicles with short legs so I wouldn’t expect the alt-above-home to be perfectly accurate. If you’re looking to fly at a specific altitude above the ground especially during missions then the altitude frame can be specified as a “terrain altitude”. We’ve got more details on surface tracking and terrain following on the wiki.
Sorry to be repetitive but please don’t set EK3_SRC1_POSZ = 2 (rangefinder) outdoors or even indoors if there is “ground clutter”. I’ve been repeating this over and over again, it’s also on the wiki and mentioned in the parameters so if possible I’d prefer not to go into all the details of why one more time, trust me, it’s just a bad idea.