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
GPS GLOBAL
Status: Heartbeat: 52
GPS GLOBAL
Status: Heartbeat: 54
GPS GLOBAL
Status: Heartbeat: 56
GPS GLOBAL
Status: Heartbeat: 58
GPS GLOBAL
Status: Heartbeat: 60
GPS GLOBAL
Status: Heartbeat: 64
GPS GLOBAL
Status: Heartbeat: 66
GPS GLOBAL
Status: Heartbeat: 69
GPS GLOBAL
Status: Heartbeat: 71
GPS GLOBAL
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.:
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?
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:
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.