Problem accessing GPS, atttitute and compass over mavlink

Hey guys,

i am new here. I am trying to set up a mavlink connection to my pixhawk.
I am trying to receive GPS data by starting the MAV_DATA_STREAM_POSITION stream (1Hz). That actually worked great. The console output looks like this:

MavLink configuration: successful
Status: Heartbeat: 50
Status: Heartbeat: 52
Status: Heartbeat: 54
Status: Heartbeat: 56
Status: Heartbeat: 58
Status: Heartbeat: 60
Status: Heartbeat: 64
Status: Heartbeat: 66
Status: Heartbeat: 69
Status: Heartbeat: 71
Status: Heartbeat: 73

Now, additionatly to the GPS data I want to get the Attitute and Compass data. So after I start the MAV_DATA_STREAM_POSITION stream, I also start the MAV_DATA_STREAM_EXTRA1 and MAV_DATA_STREAM_EXTRA2 stream.

This is the point where I get problems. All 3 streams are working individually but when i try to start them all one after another, I get mixed data e.g.:

MavLink configuration: successful
Status: Heartbeat: 77
Status: Heartbeat: 79
Status: Heartbeat: 85
Status: Heartbeat: 91
Status: Heartbeat: 97
Status: Heartbeat: 104
Status: Heartbeat: 110
Status: Heartbeat: 116
Status: Heartbeat: 122
Status: Heartbeat: 128
Status: Heartbeat: 135
Status: Heartbeat: 142
Status: Heartbeat: 148
Status: Heartbeat: 154
Status: Heartbeat: 162
Status: Heartbeat: 168
Status: Heartbeat: 174
Status: Heartbeat: 180
Status: Heartbeat: 186
Status: Heartbeat: 192
Status: Heartbeat: 199
Status: Heartbeat: 205
Status: Heartbeat: 212

Now I receive the different messages very inconsistently. Sometimes I dont get GPS or Compass data for like 20 seconds.

Is it not intended to use multiple streams at once? What am I doing wrong? Do I need to configure more?

Really appreciate any kind of help!

Instead of chaging the stream rates of groups of messages, request rates for individual messages using:


thanks for the hint. How do I use this command? I tried to read in the forum about it and I guess I am not the only one who has this question. Is there anywhere a short example code?


  • param 1 = 24 (The MAVLink message ID GPS_RAW_INT for example)
  • param 2 = 500000 (for 2Hz)
  • param 7 = 1

and repeat it for the other message IDs that you need.


okay, this is a rough code snippet of what I have done:

>     // I open a serial port connection to COM7 with baudrate 57600 (I am connected to the pixhawk over USB)
>      	_serial->open(port_, baudrate_);
>     // This is the part where I encode the command
>     	mavlink_command_long_t comando;
>     	char buf[300];
>     	uint16_t length = 0;
>     	comando.command = MAV_CMD_SET_MESSAGE_INTERVAL;
>     	comando.target_system = 1;	// target system id
>     	comando.target_component = 1;// target comp id
>     	comando.confirmation = false;
>     	comando.param1 = MAVLINK_MSG_ID_VFR_HUD;	// attitute
>     	comando.param2 = 0;
>     	comando.param3 = 0;
>     	comando.param4 = 0;
>     	comando.param5 = 0;
>     	comando.param6 = 0;
>     	comando.param7 = 2;
>     	length = mavlink_msg_command_long_encode(1, 1, &_mav_message, &comando);	// own system id, own comp id
>     // Now I send the message
>     	char write_buffer[MAVLINK_MAX_PACKET_LEN + 10];																					
>     // Translate message to buffer
>     	unsigned int bytesToSend = mavlink_msg_to_send_buffer((uint8_t*)write_buffer, message_);
>    // Write buffer to serial port, locks port while writing
>     	_serial->write(write_buffer, bytesToSend);

After that I check for receiving messages and print the message ID. The console output looks like this:

Message ID is the command Ack, so it seems that my request is received by the autopilot. However, I dont get a single attitute message.

I am using ArduCopter V4.0.3 Quad on a Pixhawk 1.

What am I still doing wrong ? :grinning: :grinning:

Param 2 needs to be != 0
Please set it to 500000 (for 500ms or 2Hz)

Thank you !

I thought param2 = 0 would be default rate. However, it is working but only if all (GPS, attitute and compass) get different rates assigned. That is something I can deal with at the moment. If you know why it is like this, or how to solve it that I can assign them all with e.g. 1Hz please tell me. Otherwise thank you, you helped a lot.

It must work with 1Hz.
But of course you need to send one MAV_CMD_SET_MESSAGE_INTERVAL per each mavlink message type that you want to receive periodicaly.