Softivation

Altitude drifts while the barometer looks normal

If the drone descends while Mission Planner shows a steady altitude, the barometer has drifted. This guide shows step by step how to separate the three root causes of altitude drift in the log.

Furkan IŞIKAY 9 min read

The drone is hovering and you aren't touching the transmitter. On the Mission Planner screen, altitude is steady at 20 meters. But to the eye, the drone is slowly descending. After a while it sinks to treetop level, and the screen still says 20 meters.

The first thing that comes to mind is that the barometer is broken. Most of the time it isn't. The barometer reports what it measures correctly. The problem is that the measurement no longer corresponds to the real height.

Where the altitude on the screen comes from

The autopilot doesn't measure altitude directly. It measures air pressure and converts pressure to height. Pressure falls as you climb and rises as you descend. The pressure read before takeoff is taken as zero, and every change after that is interpreted as a height difference.

So if the measured pressure changes for some reason other than an actual change in height, the autopilot takes it for a climb or a descent. The altitude loop then moves the drone in the opposite direction to cancel this fake movement. On the screen the target height looks maintained; in reality it isn't.

In the chart below, look at how the two curves separate once the barometer altitude starts drifting at 5 centimeters per second.

The screen says 20 m, the drone is descending

When the barometer drifts 5 cm per second, the Mission Planner altitude stays steady at 20 m while the drone's real height drops from 20 m to 1.5 m
What to look at: where the two curves separate after the dashed line. The blue curve doesn't move at all. When the drift stops, the red curve stops too, but it doesn't climb back.

After the drift starts, the value on the screen stays at 20 meters while the real height falls from 20 meters to 1.5 meters. The gap reaches 18.6 meters, and the descent rate is almost the same as the drift rate.

When the drift stops, the descent stops too, but the lost height doesn't come back.

The number on the screen is not a measurement, it is an interpretation. It is the pressure the barometer read, converted to height. If the pressure lies, the screen consistently shows the same lie.

Three things that distort pressure

Three separate causes produce the same symptom, and you tell them apart by when they appear. In the figure below, compare the trace each one leaves in the log.

  • Temperature: the autopilot board heats up while running, and as the barometer warms it reads pressure with an offset. This builds up even when the drone sits on the bench without ever taking off.
  • Airflow inside the airframe: the barometer measures the pressure inside the enclosure. If the top and bottom vent holes are unbalanced, a pressure difference builds up inside the enclosure in forward flight and disappears suddenly when the maneuver ends.
  • The air itself: on long flights, atmospheric pressure changes anyway. If the altitudes don't match when you fly the same route twice, this is usually the reason.

The same symptom, three different traces in the log

The traces of the three sources in the log: with warm-up, barometer altitude rises together with temperature; with airflow inside the airframe, the drift occurs only during maneuvers; with air pressure, the difference between barometer and GPS grows over the whole flight
What to look at: when the drift starts. If it builds up on the ground, it's warm-up; if it comes and goes with maneuvers, it's the airframe; if it grows throughout the flight, it's the air. The curves are schematic.

Direct sunlight falling on the barometer also causes sudden deviations. The foam over the barometer is there to block light and airflow while letting air pass through. If the foam shrinks over time and slips out of place, the protection is gone.

Example: When your turn comes, you take off as soon as you power the drone on, and the board spends its first minutes warming up in the air. If the drone visibly descends while the screen says 20 meters, the first thing to check is whether the BARO[0].Temp and BARO[0].Alt curves in the log rise together. If the same drone's altitude suddenly jumps when it moves from shade into open sun at noon, check whether the foam is in place this time.

What to look for in your own log

Before changing a parameter, you need to find out which layer is wrong. Download the flight log and follow this order.

  1. Plot CTUN.BAlt and CTUN.Alt on top of each other. If both drift in the same direction, the problem is not in the estimate but in the pressure the barometer reads.
  2. Put BARO[0].Temp and BARO[0].Alt on the same graph. If altitude rises while temperature rises, it is thermal drift. It happens even while the board sits on the ground warming up.
  3. Plot the difference between BARO.Alt and GPS.Alt against time. If the difference grows throughout the flight, air pressure is changing, not a short-lived wind effect.
  4. Check whether the drift happens only during maneuvers. If it drops in forward flight or sideways movement, look at the pressure inside the airframe and at propeller wash.
  5. If there are two barometers, compare BARO[0].Alt with BARO[1].Alt. If only one drifts, it's hardware; if both drift together, it's the airframe or the air.

All of these curves are in ArduPilot's own log messages. You can find the official descriptions of the field names in the log messages list.

Live monitoring on your own board

If you want a quick idea before downloading a log, you can connect to your board and check whether the difference between the reported altitude and the GPS height grows over time. The code below takes the difference at the moment of connection as zero and writes the change after that.

Python
# Watches barometer altitude and GPS altitude side by side.
# If you connect to your own board, change the connection address:
# USB -> 'com3' or '/dev/ttyACM0'
#   telem  -> '/dev/ttyUSB0', baud=57600
import time
from pymavlink import mavutil

BAGLANTI = 'tcp:127.0.0.1:5760'      # change for your own board
SURE_SN  = 60                        # how many seconds to watch

arac = mavutil.mavlink_connection(BAGLANTI)
arac.wait_heartbeat()
print('connected, sysid', arac.target_system)

for msg_id in (mavutil.mavlink.MAVLINK_MSG_ID_GLOBAL_POSITION_INT,
               mavutil.mavlink.MAVLINK_MSG_ID_SCALED_PRESSURE,
               mavutil.mavlink.MAVLINK_MSG_ID_GPS_RAW_INT):
    arac.mav.command_long_send(
        arac.target_system, arac.target_component,
        mavutil.mavlink.MAV_CMD_SET_MESSAGE_INTERVAL, 0,
        msg_id, 500000, 0, 0, 0, 0, 0)

ekran = gps = basinc = sicaklik = None
fix_var = False
t0 = time.time()
ilk_fark = None
print(' sure   ekran_m   gps_m    fark_m   basinc_hPa  baro_C')
while time.time() - t0 < SURE_SN:
    m = arac.recv_match(blocking=True, timeout=2)
    if m is None:
        continue
    tip = m.get_type()
    if tip == 'GLOBAL_POSITION_INT':
        ekran = m.relative_alt / 1000.0
    elif tip == 'GPS_RAW_INT':
        fix_var = m.fix_type >= 3          # without a fix GPS altitude is meaningless
        gps = m.alt / 1000.0
    elif tip == 'SCALED_PRESSURE':
        basinc = m.press_abs
        sicaklik = m.temperature / 100.0
        if fix_var and None not in (ekran, gps):
            fark = ekran - gps
            if ilk_fark is None:
                ilk_fark = fark
            print('%5.0f  %8.2f %8.2f %8.2f %11.2f %7.2f'
                  % (time.time() - t0, ekran, gps, fark - ilk_fark, basinc, sicaklik))

If the board has just been powered on, in the first minutes you'll see the barometer temperature rise and the difference column drift along with it. While the code runs, a table like this appears on the screen:

Output
connected, sysid 1
 sure   ekran_m   gps_m    fark_m   basinc_hPa  baro_C
   10      0.00   500.10     0.00      954.60   26.98
   10      0.00   500.10     0.00      954.60   27.06
   11      0.00   500.10     0.00      954.60   27.13
   11      0.00   500.10     0.00      954.60   27.21
   12      0.00   500.10     0.00      954.60   27.28
   12      0.00   500.10     0.00      954.60   27.36
   13      0.00   500.10     0.00      954.60   27.43

If the difference column grows steadily in one direction, there is drift. If it grows together with the temperature column, it is caused by warm-up.

Error Messages and Their Meanings

All the pre-takeoff messages related to the barometer and altitude appear in the ArduPilot source code exactly as follows.

PreArm: Baro: not healthy

The autopilot can't get valid data from the barometer. The sensor isn't responding or the values read fail the health check. Check the cable, the solder joints and, if there is one, the state of the second barometer.

PreArm: Baro: GPS alt error 5811m (see BARO_ALTERR_MAX)

The difference between GPS height and the height calculated from pressure has exceeded the accepted limit. The limit is set by BARO_ALTERR_MAX and its default is 2000 meters. A difference this large usually comes from the sensor being read with the wrong model, not from a drift of a few meters.

PreArm: Altitude disparity

The height from the barometer and the height from the inertial solution have diverged. The threshold for this check is defined in the source code as 1.0 meter. This is the tightest altitude check seen before takeoff.

PreArm: Need Alt Estimate

The autopilot doesn't yet have a reliable height estimate. The filter hasn't settled or the barometer data is intermittent. The same reason can come up when you try to change modes in flight.

PreArm: EKF height variance

The uncertainty of the height estimate is outside the accepted band. Vibration and barometer noise together produce this message. Before blaming the barometer alone, check the vibration levels too.

Measure the source on your own board

Most of this behavior depends on real hardware: board heating, the airframe's hole layout, sun and propeller wash. That is why you find the source by measuring on the bench and in a short flight.

Three things are enough for this: power the board on and wait twenty minutes without taking off, noting how many meters the reported altitude drifts, and record the barometer temperature at the same time; then fly forward and stop on a short flight to see whether the altitude moves with the maneuver. These three measurements tell you which of the three root causes you are dealing with.

More in the course

The lesson on this topic is in the Drone Basics: From Sensors to Flight course. In the lesson you'll find the decision order for the drift in the source code, the real default values of the parameters, log signature tables and cases from the field.

Was this article helpful?

Free resourcePixhawk and ArduPilot error message glossaryThe 5 messages in this article and similar ones are in the glossary: what they mean, why they appear, what to check first.