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 diydrones2 to add comments!

Join diydrones2

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

Hank Deucker left a comment on PIXHAWK
"Tomorrow, I am thinking about the wording at the moment."
7 hours ago
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
20 hours ago
DIY Drones via Twitter
New! Online Training on Drones for Disaster Response https://t.co/brqRuujjY2
Tuesday
DIY Robocars via Twitter
https://t.co/8EMCvYW6oz
Tuesday
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…
Monday
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…
Sunday
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 #…
Saturday
DIY Robocars via Twitter
RT @Heavy02011: Join us Saturday online: Virtual Race League: @DIYRobocars Race #2 - Parking Lot Nerds https://t.co/aJUu4sdutx #Meetup via…
Saturday
DIY Robocars via Twitter
RT @donkey_car: Yay, we are part of the virtual @makerfaire with @diyrobocars. Come see our race or better yet train a model and race with…
May 21
DIY Robocars via Twitter
RT @chr1sa: The @DIYRobocars Virtual AI Race is going to be part of the virtual @makerfaire on Sat! https://t.co/wnMDAboLID
May 20
DIY Robocars via Twitter
RT @tawnkramer: Please join us next week for our second DIYRobocars online race. We will be using a new Mountain Track course! https://t.co…
May 19
DIY Robocars via Twitter
RT @SmallpixelCar: I realized that the size of the cones in @diyrobocars is known. If we can detect the bounding box, which can be done wit…
May 19
DIY Drones via Twitter
RT @chr1sa: Our next @DIYRobocars autonomous car virtual race is this Saturday. Sign up here to compete or just spectate on @Twitch https:/…
May 19
DIY Drones via Twitter
Definitive Guide to Setup Drone Delivery System https://t.co/7ibwcgF24h
May 19
DIY Robocars via Twitter
RT @DAVGtech: The next @diyrobocars virtual robocar race is this Saturday. One of many interesting issues we are taking a stab at is "how c…
May 18
DIY Robocars via Twitter
RT @chr1sa: cc @DIYRobocars @donkey_car https://t.co/ewbyqZ3xC0
May 18
More…