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;
}
}
}
}