Hi everyone,
  Recently I used ArduinoMAVlink to test mavlink. After I uploaded the following code to my Arduino UNO, I connected myarduino board with apm (not pixhawk) through USB (aiming to disguise my arduino board as a ground control station to send mavlink message to apm to make it arm ).Unfortunately,the apm copter didn't arm  .But when I connected arduino board to qgroundcontrol, the qGCS did receive the mavlink message .
I felt confused :
1.Did I use the correct sysid ,compid target_sysid ,target_compid ?if not ,how to change my id??
 I used the default id which is 1.It is defined in the file called Arducopter.pde .
2.Here has some detail: when I compiled my code ,#include<FastSerial.h>did not work (had some compile problem) ,so i deleted the "FastSerialPort0(Serial)"line to make it compile  successfully,,but can this be a factor to cause my apm copter  has no response?
 
3.In my code ,I only send an "Arm message " to my copter.
 
// Arduino MAVLink test code.
 
#include <FastSerial.h>
#include "C:\Users\Dell1\Desktop\arduino-mavlink-master\arduino-mavlink-master\libraries\mavlink\include\common\mavlink.h"        
   
 int flag =0;
 
//FastSerialPort0(Serial);
 
void setup() {
        Serial.begin(115200);
       
}
 
void loop() {
    int type = MAV_TYPE_GCS ;
    uint8_t autopilot_type =MAV_AUTOPILOT_INVALID;     //MAV_AUTOPILOT_GENERIC;//
    uint8_t system_mode = MAV_MODE_PREFLIGHT;       ///< Booting up
    uint32_t custom_mode = 0;                   ///< Custom mode, can be defined by user/adopter
    uint8_t system_state = MAV_STATE_STANDBY;     //< System ready for flight
    mavlink_message_t msg;
    mavlink_message_t msg2;
    uint8_t buf[MAVLINK_MAX_PACKET_LEN];
    uint8_t buf2[MAVLINK_MAX_PACKET_LEN];
   //send heartbeat packages
    mavlink_msg_heartbeat_pack(255,MAV_COMP_ID_MISSIONPLANNER, &msg, type,        autopilot_type,system_mode,custom_mode,system_state);
 
    // Copy the message to the send buffer
    uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);
 
     Serial.write(buf, len);
     delay(1000);
     if(flag!=1){
     //use MAV_CMD_COMPONENT_ARM_DISARM #400 to arm the apm copter
     mavlink_msg_command_long_pack( 255,MAV_COMP_ID_MISSIONPLANNER,  &msg2, 1,  MAV_COMP_ID_SYSTEM_CONTROL, MAV_CMD_COMPONENT_ARM_DISARM, 1, 0.0, 0.0, 0.0,0.0, 0.0, 0.0, 0.0);
 
     uint16_t len2 = mavlink_msg_to_send_buffer(buf2, &msg2);
     Serial.write(buf2, len2);
     delay(300);
     flag++;
     }
     comm_receive();    
}
 
void comm_receive() {
 
     //receive mavlink from apm
}

ArduinoMAVlink.zip

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • Hi Mario, this works for me:

    ARM:

    mavlink_msg_command_long_pack(0xFF, 0xBE, &msg, 1, 1, 400, 1,1.0,0,0,0,0,0,0);
    len = mavlink_msg_to_send_buffer(buf, &msg);
    _MavLinkSerial.write(buf, len);

    DISARM:

    mavlink_msg_command_long_pack(0xFF, 0xBE, &msg, 1, 1, 400, 1,0,0,0,0,0,0,0);
    len = mavlink_msg_to_send_buffer(buf, &msg);
    _MavLinkSerial.write(buf, len);

This reply was deleted.

Activity