This file contains 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
//Request a data from a device | |
mavlink_msg_request_data_stream_pack(2, 200, &msg, 1, 0, MAVStreams[i], MAVRates[i], 1); | |
//Send a heartbeat packet | |
mavlink_msg_heartbeat_pack(255,0, &msg, type, autopilot_type, system_mode, custom_mode, system_state); |
This file contains 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
mavlink_message_t msg; | |
mavlink_status_t status; | |
mavlink_heartbeat_t hb; | |
mavlink_msg_heartbeat_decode(&msg,&hb); | |
#ifdef DEBUG | |
Serial.print(millis()); | |
Serial.print("\ncustom_mode: ");Serial.println(hb.custom_mode); | |
Serial.print("Type: ");Serial.println(hb.type); |
This file contains 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
// Mavlink variables | |
unsigned long previousMillisMAVLink = 0; // will store last time MAVLink was transmitted and listened | |
unsigned long next_interval_MAVLink = 1000; // next interval to count | |
const int num_hbs = 60; // # of heartbeats to wait before activating STREAMS from Pixhawk. 60 = one minute. | |
int num_hbs_past = num_hbs; | |
This file contains 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
// Send the message with the standard UART send function | |
// uart0_send might be named differently depending on | |
// the individual microcontroller / library in use. | |
unsigned long currentMillisMAVLink = millis(); | |
if (currentMillisMAVLink - previousMillisMAVLink >= next_interval_MAVLink) { | |
// Timing variables | |
previousMillisMAVLink = currentMillisMAVLink; | |
SerialMAV.write(buf, len); |
This file contains 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
// Pack the message | |
mavlink_msg_heartbeat_pack(255,0, &msg, type, autopilot_type, system_mode, custom_mode, system_state); | |
uint16_t len = mavlink_msg_to_send_buffer(buf, &msg); |
This file contains 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
void Mav_Request_Data() | |
{ | |
mavlink_message_t msg; | |
uint8_t buf[MAVLINK_MAX_PACKET_LEN]; | |
// To be setup according to the needed information to be requested from the Pixhawk | |
const int maxStreams = 1; | |
const uint8_t MAVStreams[maxStreams] = {MAV_DATA_STREAM_ALL}; | |
const uint16_t MAVRates[maxStreams] = {0x02}; | |
This file contains 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
mavlink_message_t msg; | |
mavlink_status_t status; | |
while(SerialMAV.available()) { | |
uint8_t c = SerialMAV.read(); | |
// Try to get a new message | |
if(mavlink_parse_char(MAVLINK_COMM_0, c, &msg, &status)) { | |
case MAVLINK_MSG_ID_HEARTBEAT: // #0: Heartbeat |
This file contains 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
void loop() { | |
// Initialize the required buffers | |
mavlink_rc_channels_override_t sp; | |
mavlink_message_t msg; | |
uint8_t buf[MAVLINK_MAX_PACKET_LEN]; | |
//We have to send the heartbeats to indicate side by side connection | |
mav_heartbeat_pack(); |
This file contains 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
boolean current_arm = false; | |
String current_mode = STABILIZE; | |
int current_roll = 0; | |
int current_pitch = 0; | |
int current_throttle = 0; //Min value is 1150 to run motors | |
int current_yaw = 0; |
This file contains 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
void mav_heartbeat_pack() { | |
mavlink_message_t msg; | |
uint8_t buf[MAVLINK_MAX_PACKET_LEN]; | |
// Pack the message | |
mavlink_msg_heartbeat_pack(255,0, &msg, type, autopilot_type, system_mode, custom_mode, system_state); | |
uint16_t len = mavlink_msg_to_send_buffer(buf, &msg); | |
SerialMAV.write(buf, len); | |
} |