Requesting Data From The Autopilot

The ground station or companion computer can request the data it wants (and the rate) using one of the following methods:

  • Set the SRx_ parameters to cause the autopilot to pro-actively send groups of messages on start-up. This method is easy to set-up for a small number of drones but is not recommended for most applications

  • Send REQUEST_DATA_STREAM messages to set the rate for groups of messages

  • Send a SET_MESSAGE_INTERVAL command (within a COMMAND_LONG message) to precisely control the rate of an individual message. Note this is only supported on ArduPilot 4.0 and higher

  • Send a REQUEST_MESSAGE command (within a COMMAND_LONG message) to request a single instance of a message. Note this is only supported on ArduPilot 4.0 and higher

  • Create configuration files stored on the SD card or in ROMFS specifying message stream rates on a per-channel basis

  • Install a Lua script to set individual messages rates (e.g. Set Message Interval via a Lua script). See “Using a LUA Script” section below.

Note that the stream rates will temporarily be 4 or more times slower than requested while parameters and waypoints are being sent.

More details on the above methods can be found below.

Note

If you find your message rates are reverting to some fixed value after you set them, see the “Rates Reverting to some Fixed value” section at the bottom of this page

Using SRx Parameters

Setting the SRx_ parameters (and then rebooting the autopilot) will cause the autopilot to pro-actively send groups of messages to the ground station. This is not the recommended method because the ground station has no way to determine what “x” should be.

Using REQUEST_DATA_STREAM

Most ground stations including the Mission Planner use this method. See Setting the Datarate in the Mission Planner wiki.

Send a REQUEST_DATA_STREAM message with the following fields

  • target_system : the MAVLink system id of the vehicle (normally “1”)

  • target_components : normally “0”

  • req_stream_id : 0 to 12 corresponding to the group of messages (see MAV_DATA_STREAM). See the “Using SRx Parameters” section above to determine exactly which messages are in each group

  • req_message_rate : the rate (in hz) of the message

  • start_stop : “1” to start sending, “0” to stop

Examples

Here are some example commands that can be copy-pasted into MAVProxy (aka SITL) to test this command. Before running these commands enter the following

  • module load message

Example MAVProxy/SITL Command

Description

message REQUEST_DATA_STREAM 1 0 1 5 1

Request sysid:1, compid:0 send sensor data at 5hz

message REQUEST_DATA_STREAM 1 0 1 0 0

Request sysid:1, compid:0 stop sending sensor data

message REQUEST_DATA_STREAM 1 0 6 5 1

Request sysid:1, compid:0 send position data at 5hz

message REQUEST_DATA_STREAM 1 0 6 0 0

Request sysid:1, compid:0 stop sending position data

Using SET_MESSAGE_INTERVAL

This method provides the most precise control and reduces bandwidth requirements (because unnecessary messages are not sent) but requires knowing exactly which messages you require

Send a COMMAND_LONG with the following fields

  • target_system : the MAVLink system id of the vehicle (normally “1”)

  • target_components : normally “0”

  • command: 511 (for MAV_CMD_SET_MESSAGE_INTERVAL)

  • confirmation: 0

  • param1: desired MAVLink message’s id (i.e. 33 for GLOBAL_POSITION_INT)

  • param2: time interval between messages in microseconds (i.e. 100000 for 10hz, 1000000 for 1hz)

  • param3 to param7: 0 (not used)

Examples

Here are some example commands that can be copy-pasted into MAVProxy (aka SITL) to test this command. Before running these commands enter the following

  • module load message

Example MAVProxy/SITL Command

Description

message COMMAND_LONG 1 0 511 0 33 100000 0 0 0 0 0

Request GLOBAL_POSITION_INT at 10hz

message COMMAND_LONG 1 0 511 0 33 1000000 0 0 0 0 0

Request GLOBAL_POSITION_INT at 1hz

message COMMAND_LONG 1 0 511 0 33 0 0 0 0 0 0

Request GLOBAL_POSITION_INT at default rate

message COMMAND_LONG 1 0 511 0 33 -1 0 0 0 0 0

Request GLOBAL_POSITION_INT not be sent

Warning

If the telemetry link is shared (i.e. multiple GCSs or a GCS and a companion computer) there can be conflicting requests. The most common example is the Mission Planner using the REQUEST_DATA_STREAM method while a companion computer uses SET_MESSAGE_INTERVAL method. Mission Planner at least allows turning off the REQUEST_DATA_STREAM requests by setting the rates to “-1” (see Setting the Datarate). MAVProxy users can set streamrate -1.

Using REQUEST_MESSAGE

A GCS can poll for a single instance of a message from the autopilot.

Send a COMMAND_LONG with the following fields

  • target_system : the MAVLink system id of the vehicle (normally “1”)

  • target_components : normally “0”

  • command: 512 (for MAV_CMD_REQUEST_MESSAGE)

  • confirmation: 0

  • param1: desired MAVLink message’s id (i.e. 33 for GLOBAL_POSITION_INT)

  • param2: depends on message requested; see that message’s definition for details.

  • param3 to param7: 0 (not used)

Examples

Here are some example commands that can be copy-pasted into MAVProxy (aka SITL) to test this command. Before running these commands enter the following

  • module load message

Example MAVProxy/SITL Command

Description

message COMMAND_LONG 1 0 512 0 33 0 0 0 0 0 0

Request GLOBAL_POSITION_INT be sent once

Specifying Message Rates in a File

At boot ArduPilot will populate the initial message intervals from files found in either ROMFS or in the filesystem.

On ChibiOS-based boards (with more than 1MB of flash) the SD card will be searched for specially-named files in the root directory.

Each mavlink channel is configured in a separate configuration file. The first serial port configured as mavlink is channel 0, the second serial port channel 1 etc.

An example filename is message-intervals-chan0.txt

The format is simple but strict. There are two columns, separated by a single space and both containing numbers. The first number is a mavlink message ID. The second is the message interval, in milliseconds. Each line must be terminated by either carriage-return or a line-feed.

30 50
28 100
29 200

This sample file content will stream ATTITUDE (ID=30) at 20Hz and SCALED_PRESSURE (ID=29) at 5Hz. Message ID 28 is RAW_PRESSURE which ArduPilot does not send - this line will be ignored.

Configuration files can be included in ROMFS (i.e. compiled into the image) by specifying their path in the relevant board’s hwdef file:

ROMFS message-intervals-chan0.txt libraries/AP_HAL_ChibiOS/hwdef/CubeOrange/message-intervals-chan0.txt

The second parameter is a path relative to the ArduPilot checkout’s root directory.

Example use cases of this include locking telemetry rates on boards that can’t run scripting, or before scripting can be run.

Using a Lua Script

  • Download the message_interval.lua Lua script

  • Open the script in an editor (like Notepad)

  • Ensure each mavlink message you wish to enable or disable is listed in the “mavlink message ids” (around line 13) and “intervals” array (around line 36)

  • Upload the script to the autopilot by following these instructions

  • Restart the autopilot and confirm no errors appear on the ground stations’s Messages tab

  • Follow the instructions below to ensure the messages are appearing at the desired rate. If the rates are variable, this may be because of a conflict between the Lua script and a GCS, please see the “Rates Reverting to some Fixed value” section below

Checking The Message Rates

Some ground stations including Mission Planner and QGC include a “MAVLink Inspector” which is useful when checking the update rate of specific messages.

If using Mission Planner:

  • Press Ctrl-F

  • Push the “MAVLink Inspector” button

  • Expand the vehicle and component IDs to see individual messages and their update rate

../_images/mavlink-mp-mavlink-inspector.png

If using MAVProxy:

  • module load messagerate

  • messagerate status

Rates Reverting to some Fixed value

If you find the message rates are reverting to some fixed rate (often 4hz) after you set them, it is probably a Ground Control station adjusting the rates.

Most Ground Control Stations have a control to disable this behaviour. For example:

  • If using MAVProxy type set streamrate -1 into the console

  • If using Misison Planner, open the Config, Planner screen and set the “Telemetry Rates” dropdowns to -1

  • If using QGroundControl, open Application Settings, Telemetry and move the “Controlled By vehicle” slider to the right

If adjusting the GCS behaviour is impossible, set the appropriate SERIALn_OPTIONS parameter’s bit 12 (“Ignore Streamrate”) to ignore attempts by the GCS to set message rates via streamrate commands. For example if Serial1/Telem1’s rates are being inconveniently adjusted by the GCS, set the SERIAL1_OPTIONS parameter value