Softivation

No telemetry, check the message interval first

You connected with pymavlink but no position data arrives. ArduPilot doesn't broadcast most messages unless you ask. We explain how to request the message interval and measure the rate correctly.

Furkan IŞIKAY 6 min read

You connect to the drone with Python, the heartbeat signal arrives, but the line waiting for the position message waits forever. You swap the cable, fiddle with the baud, reflash the firmware.

None of that fixes it, because the problem isn't there: ArduPilot doesn't broadcast most MAVLink messages unless you explicitly ask for them.

In Fighting UAV the cost of this is heavy. You can't track an opponent flying at 20 m/s with 1 Hz position data: it travels 20 meters between two samples, and your lock-on algorithm ends up chasing thin air.

The position data isn't slow, it isn't flowing at all

A message you didn't request flows at zero rate, meaning it never arrives. You tell the autopilot with a command which message you want at what rate, and the autopilot reports with a reply that it accepted.

The accept reply doesn't mean the message is flowing at the rate you asked for; it only says the command was accepted. You need to measure the rate yourself.

The rate you want is written in microseconds

The param2 field of the MAV_CMD_SET_MESSAGE_INTERVAL command is an interval, that is, in microseconds. If you want 10 Hz, you should write 1000000/10 = 100000. If you write 10 here, you're asking for a 10-microsecond interval, which is 100,000 Hz. Special values: 0 returns to the default, -1 turns the message off completely.

Your measurement can give you the wrong number

If you put time.sleep(1) between the request and the measurement and count without draining the queue, you read 12.2 Hz even though you asked for 10 Hz. About 10 messages pile up in the socket queue during the wait.

As soon as the measurement window opens, this accumulated pile is counted instantly, and you get 60 messages instead of 50 in 5 seconds. Look at the red pile at the start of the middle strip in the figure.

What gets counted in the measurement window after the request

No messages flow before the request goes out; after the request the vehicle sends at 10 Hz. If the queue isn't drained, the roughly 10 messages that piled up during sleep(1) are counted all at once at the start of the measurement window, showing 60 messages in 5 seconds, 12.2 Hz. With the queue drained, you read 50 messages, 10.0 Hz.
Where to look: the red pile at the start of the middle strip. What piled up during sleep(1) is counted as soon as the window opens. In the bottom strip, draining discards them before the window.

If you don't drain the queue before measuring, the number you get isn't the real frequency. The kuyrugu_bosalt() function in the code below does this job.

Code that turns on the message and measures its rate

Python
import time
from pymavlink import mavutil

arac = mavutil.mavlink_connection('tcp:127.0.0.1:5760')
arac.wait_heartbeat()

MSG_ID = mavutil.mavlink.MAVLINK_MSG_ID_GLOBAL_POSITION_INT

def kuyrugu_bosalt(arac, sure=0.5):
    """Call BEFORE measuring. Accumulated messages inflate the frequency."""
    bitis = time.time() + sure
    while time.time() < bitis:
        arac.recv_match(blocking=False)

def olc(arac, ad, sure=5.0):
    bitis = time.time() + sure
    n = 0
    while time.time() < bitis:
        if arac.recv_match(type=ad, blocking=True, timeout=0.5):
            n += 1
    return n / sure

# 1) Before requesting: this message does NOT stream by default
kuyrugu_bosalt(arac)
print(f"Once : {olc(arac, 'GLOBAL_POSITION_INT'):.1f} Hz")

# 2) Ask for 10 Hz - interval in MICROSECONDS
arac.mav.command_long_send(
    arac.target_system, arac.target_component,
    mavutil.mavlink.MAV_CMD_SET_MESSAGE_INTERVAL,
    0, MSG_ID, int(1_000_000 / 10), 0, 0, 0, 0, 0)

ack = arac.recv_match(type='COMMAND_ACK', blocking=True, timeout=3)
print(f"ACK  : result={ack.result}  (0 = ACCEPTED)")

# 3) Trust the measurement, not the ACK - and drain the queue before measuring
time.sleep(1)
kuyrugu_bosalt(arac)
print(f"After: {olc(arac, 'GLOBAL_POSITION_INT'):.1f} Hz")

If you run the code against ArduCopter V4.7.0, you get this output:

Terminal
$ python3 telemetri_hizi.py
Once : 0.0 Hz
ACK  : result=0  (0 = ACCEPTED)
After: 10.0 Hz

Note the first line: 0.0 Hz. The message hasn't slowed down; it isn't flowing at all. After the request, the rate settles on the target.

Example: in Fighting UAV, if your code tracking the opponent can't lock on to the target, before fiddling with the cable and baud, close the tracking code and run this code on the same link without restarting the autopilot. If you see 0.0 Hz on the Once line, your tracking code never requested the position message. If you see 10.0 Hz on the Sonra line, the link and the autopilot setting are fine, and you look for the problem inside the tracking code itself.

If you don't have a board, try it in SITL

If you want to try the code without a board, you can set up SITL with a few commands.

Shell
mkdir -p ~/sitl && cd ~/sitl
curl -sL -o arducopter \
  https://firmware.ardupilot.org/Copter/stable/SITL_x86_64_linux_gnu/arducopter
chmod +x arducopter
curl -sL -o copter.parm \
  https://raw.githubusercontent.com/ArduPilot/ardupilot/master/Tools/autotest/default_params/copter.parm
pip install pymavlink

# --speedup 1 is required: in an accelerated simulation the Hz you measure is sim-time
./arducopter -S -I0 --model + --speedup 1 --defaults copter.parm \
  --sysid 1 --home 37.1591,38.7969,500,0

If you run SITL with --speedup 5, the interval runs on simulation time. You ask for 10 Hz and measure 60 Hz on the wall clock. Use --speedup 1 when measuring frequency.

Error Messages and Their Meanings

This problem doesn't print an error line; the recv_match waiting for the position message just waits silently. But two lines in the code's output are easy to misread at first glance.

The Once : 0.0 Hz line is the measurement before the request is sent. Since GLOBAL_POSITION_INT doesn't flow by default, the counter stays at zero.

The ACK : result=0 line says the autopilot accepted the command, not that the message is flowing at the rate you asked for. Measure the rate yourself after draining the queue.

AttributeError: 'NoneType' object has no attribute 'result'

No COMMAND_ACK arrived within 3 seconds after the command. recv_match returned None, and the code tried to read its result field. It means the command didn't reach the autopilot or its reply didn't come back. Check the connection and try again.

What's missing for competition code

The code in this article turns on a single message and measures it. Here's what's missing for competition day:

  • Deciding which message to request at what frequency. SiK telemetry at 57600 baud can't carry 50 Hz; the link saturates and your commands don't get through.
  • UART and DMA differences on Pixhawk, Cube Orange, and Matek boards.
  • Diagnosing cases where the ACK returns DENIED or FAILED.
  • Since ArduPilot keeps the setting per channel, the old rate carries on when the code restarts.

The full solutions to these, a board-specific pinout table, and competition-level code are covered in the Drone Communication Technologies course.

AI and Drone Simulation Virtual Machine: comes with ArduPilot SITL, ROS Noetic, and Gazebo 11 installed. You start simulating without any setup hassle.

Was this article helpful?

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