Last active
October 13, 2019 13:50
-
-
Save bart02/c26288bdc7162d802c55715bc6ad7df8 to your computer and use it in GitHub Desktop.
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 "mavlink.h" | |
| // Launch the serial port in setup | |
| void setup() { | |
| // MAVLink interface start | |
| Serial.begin(57600); | |
| Serial3.begin(57600); | |
| Mav_Request_Data(); | |
| } | |
| void loop() { | |
| comm_receive(); | |
| } | |
| void Mav_Request_Data() | |
| { | |
| mavlink_message_t msg; | |
| uint8_t buf[MAVLINK_MAX_PACKET_LEN]; | |
| mavlink_msg_request_data_stream_pack(2, 200, &msg, 1, 0, MAV_DATA_STREAM_EXTRA1, 0xFF, 1); | |
| uint16_t len = mavlink_msg_to_send_buffer(buf, &msg); | |
| Serial3.write(buf, len); | |
| } | |
| void comm_receive() { | |
| mavlink_message_t msg; | |
| mavlink_status_t status; | |
| while(Serial3.available()>0) { | |
| uint8_t c = Serial3.read(); | |
| // Try to get a new message | |
| 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); | |
| Serial.println(attitude.yaw); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment