Skip to content

Instantly share code, notes, and snippets.

@ymt117
Created June 1, 2025 13:44
Show Gist options
  • Save ymt117/e53343f81114383c9188786f8a6c7256 to your computer and use it in GitHub Desktop.
Save ymt117/e53343f81114383c9188786f8a6c7256 to your computer and use it in GitHub Desktop.
Get attitude from flight controller
#include <HardwareSerial.h>
#include <MAVLink.h>
HardwareSerial SerialMAV(0);
void setup() {
Serial.begin(115200);
SerialMAV.begin(115200);
}
void loop() {
mavlink_message_t msg;
mavlink_status_t status;
while (SerialMAV.available() > 0) {
uint8_t c = SerialMAV.read();
if (mavlink_parse_char(MAVLINK_COMM_0, c, &msg, &status)) {
if (msg.msgid == MAVLINK_MSG_ID_ATTITUDE) {
mavlink_attitude_t attitude;
mavlink_msg_attitude_decode(&msg, &attitude);
float roll = attitude.roll * 180.0 / PI;
float pitch = attitude.pitch * 180.0 / PI;
float yaw = attitude.yaw * 180.0 / PI;
Serial.print("Roll: ");
Serial.print(roll, 2);
Serial.print(" deg, Pitch: ");
Serial.print(pitch, 2);
Serial.print(" deg, Yaw: ");
Serial.print(yaw, 2);
Serial.println(" deg");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment