Problems with mavlink_msg_interval_pack

#1

Hello,

I’m trying to use the Arduino to request a specific message from the Pixhawk (Attitude #30), but it’s not working. I’ve tried mavlink_msg_interval_pack, mav_cmd_set_message_interval, and even mavlink_msg_data_stream_pack which is supposed to be deprecated. I’ve read the thread “Unable to read data on arduino serial monitor” on here but I’m still stuck.

I’m not sure what I’m doing wrong, but I can only see the messages that are sent automatically by Pixhawk (Heartbeat, Timesync, Param_value, and statustext). Any help would be appreciated. Thanks! Sorry about the format for the code - I tried editing it, but I’m not sure why it’s publishing like this.

This is what I have to request data from the Pixhawk.

void request_data()
{
mavlink_message_t msg;
uint8_t buf[MAVLINK_MAX_PACKET_LEN];

// Default UART header for Arduino
int sysid = QUADROTOR;
int compid = MAV_COMP_ID_ALL;

// To be setup according to the needed information to be requested from the Pixhawk
int32_t interval_us = 1000000; //interval between two messages, in microseconds
uint16_t message_id = 30; // ID of the requested MAVLink message;

mavlink_msg_message_interval_pack(sysid, compid, &msg, message_id, interval_us);
uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);
Serial1.write(buf, len);

}

This is what I have to read data from the Pixhawk.

void comm_receive()
{

mavlink_message_t msg;
mavlink_status_t status;

while (Serial1.available() > 0) {
  uint8_t c = Serial1.read();

// Try to get a new message
if (mavlink_parse_char(MAVLINK_COMM_0, c, &msg, &status)) {
  
  // Handle message
  switch (msg.msgid) {

    case MAVLINK_MSG_ID_HEARTBEAT:  // #0: HEARTBEAT
      {
        mavlink_heartbeat_t hb;
        mavlink_msg_heartbeat_decode(&msg, &hb);
        Serial.print("Heartbeat");
      }
      break;   
      
    case MAVLINK_MSG_ID_ATTITUDE:  // #30: ATTITUDE
      {
        mavlink_attitude_t att;
        mavlink_msg_attitude_decode(&msg, &att);

        Serial.print("time: ");  Serial.println(att.time_boot_ms);
        Serial.print("roll: "); Serial.println(att.roll);
      }
      break;      

    default:
      break;
  }
}

}
}

#2

Have you seen this?

#3

Hello! Yes, I have. It doesn’t seem like they were able to resolve the issue. At least, I tried running the programs they wrote and they didn’t work on my end.

#4

What’s this? You should use 1 if your drone’s system ID is 1.

#5

Whoops sorry. That was supposed to be a comment, but it is set to ‘1’ on my end. I was able to get request_data_stream to work, but I thought it was no longer supported? I’m still not sure how to get message_interval_pack to work. Do you have any ideas?

#6

I updated this thread with the code I currently use that works for me. Hope it helps.

#7

Thank you! I took a look, but it doesn’t seem to be working for me. All I see on the Serial monitor are the “Command Sent” lines you printed in the loop. I made it so the default in the switch statements printed the message ID’s and it looks like there are heartbeat, timesync, statustext, param_value, and command_ack messages being sent. I’ll keep playing around with it though.

Does it matter what I set for the first argument of mavlink_parse_char? How did you decide it should be MAVLINK_COMM_0?