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

DIY Robocars via Twitter
RT @chr1sa: The dev team is having fun with virtual @DIYRobocars track generation with Unity on the @donkey_car discord: https://t.co/l0Jd9…
12 hours ago
DIY Drones via Twitter
Review of the new Nivida Jetson NX for robocars https://t.co/bWjd3sH2o4
yesterday
DIY Robocars via Twitter
RT @chr1sa: My review of the new @NVIDIAEmbedded Jetson Xavier NX in robotics and @DIYRobocars applications https://t.co/O7TfJZhiF9 https:/…
Monday
DIY Drones via Twitter
RT @chr1sa: Somehow I missed this, but last week @Nvidia released a new version of its Isaac robot development framework. Lots of new Lidar…
Monday
DIY Robocars via Twitter
RT @Smartphone89: DonkeyCar Racing League Korea #donkeycar @diyrobocars https://t.co/mDlHDR1d98
Friday
Jørn Ramnæs liked VIDEO LINK's profile
May 28
Mark Harrison left a comment on Moderators
"Wow, Ning2 looks really great on mobile. I had sort of drifted away as my browse-time went more on my phone, so this is great."
May 28
Hank Deucker left a comment on PIXHAWK
"I am sure most will say not again, Pixhawk telemetry. I do need help and all can be reassured that I have spent many hours scouring the net for useful information. I am not new at quadcopter flying, I started in 2012 and have progressed through many…"
May 28
DIY Robocars via Twitter
https://t.co/rLmFr8M2UK
May 28
Hank Deucker left a comment on PIXHAWK
"Tomorrow, I am thinking about the wording at the moment."
May 28
DIY Drones via Twitter
Welcome to the new DIY Drones design!. You may have noticed that DIY Drones looks a little different today. That's… https://t.co/cg2EmeDGMQ
May 27
DIY Drones via Twitter
New! Online Training on Drones for Disaster Response https://t.co/brqRuujjY2
May 26
DIY Robocars via Twitter
https://t.co/8EMCvYW6oz
May 25
DIY Robocars via Twitter
RT @OttawaAVGroup: We are going to try something new this week. We will be having a drop-in style meeting Wednesday @ 7-9pm EST. Pop in and…
May 25
DIY Robocars via Twitter
RT @tawnkramer: Thanks Everyone for another fun virtual race! Amazing Ai racers competing head-to-head, Virtual Makers Fair event. Catch us…
May 23
DIY Robocars via Twitter
RT @make: Find out the latest from @diyrobocars at 10am PT from @chr1sa of @3DRobotics on Virtually Make Faire! #makerfaire #maketogether #…
May 23
More…