Created
June 1, 2025 13:44
-
-
Save ymt117/e53343f81114383c9188786f8a6c7256 to your computer and use it in GitHub Desktop.
Get attitude from flight controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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