DIYDrones,

I have two question related to MAVLink commands.  First, I'm trying to send a MAVLink command to my MAV which will make the plane fly to the desired waypoint and then continue on its mission.  For example, If the MAV's mission was A-B-C-D-HOME and the MAV has already reached waypoint A in autopilot mode.  I am wondering if there is a MAVLink command so that I can insert a waypoint into the middle of a mission.  Therefore, the mission would end up something like A-X-B-C-D-HOME.  Obviously the X MAVLink would either have to send lat,long and alt of a waypoint struct.  Is there a predefined MAVLink command to do this?  

Secondly, I was wondering if there was a way to send my MAV and guided waypoint.  For example, if my MAV was in autopilot mode flying the same mission A-B-C-D-HOME and I sent my MAV a MAVLink command to go the X waypoint in guided mode.  Is there a MAVLink command to do this?

I know that this page shows all of the predefined APM MAVLink commands, but there isn't very much description on what they do.  It seems that one of the NAV commands might be designed for what i'm trying to do but i'm not sure.  Any help would be very appreciated.

Views: 5621

Reply to This

Replies to This Discussion

has anyone had any break through, my progress into something very similar is here

Matthew, 

I have been able to successfully send a guided waypoint in a MAVLink message.  Is this what you are trying to do?

Hi David, in regards to your message

"Matthew, 

I have been able to successfully send a guided waypoint in a MAVLink message.  Is this what you are trying to do?" 

This is exactly what I am trying to do, I take it you saw my work on the link I provided, I'm just a little stuck with what exactly I need to send, and how, I don't suppose you could help me out with this problem and share your experiencewith sending guided waypoint ?

Thanks, Matt

Matt,

I'm sure about your progamming experience but here a snippit of my code that receives a waypoint as a parameter and send this waypoint to the UAV over the serial port (using XBEE).

void mavlinkCallback(const AU_UAV_ROS::Command cmd)
{
sysid = cmd.planeID;
if (sysid >= 32 && sysid <= 64) {
WPSendSeqNum++;

mavlink_message_t mavlinkMsg;
// Refer to message_definitions for parameter explination

mavlink_msg_mission_item_pack(sysid, compid, &mavlinkMsg,
sysid, serial_compid, WPSendSeqNum, MAV_FRAME_GLOBAL, MAV_CMD_NAV_WAYPOINT, 2, 0, 20.0, 100.0, 1.0, 0.0, cmd.latitude, cmd.longitude, cmd.altitude);

// Send message over serial port
static uint8_t buffer[MAVLINK_MAX_PACKET_LEN];
int messageLength = mavlink_msg_to_send_buffer(buffer, &mavlinkMsg);
if (debug) printf("Writing %d bytes\n", messageLength);
int written = write(fd, (char*)buffer, messageLength);
tcflush(fd, TCOFLUSH);
if (messageLength != written) fprintf(stderr, "ERROR: Wrote %d bytes but should have written %d\n", written, messageLength);

}
else {
// command is for simulated UAV

}

}


Most of the MAVLink helper functions are contained in mavlink.h so this is needed:

#include "mavlink/v1.0/ardupilotmega/mavlink.h"

Also, to be able to send and receive from the Xbee you will need to establish it as a serial port.  For this information look at the open and setup port functions here: https://github.com/mavlink/mavlink_ros/blob/master/src/mavlink_ros_...

Let me know if you need some more help...

Hi David,

Thanks for the response, I actualyl think I have found a fix for a problem i was having.

Im beginning to think the altitude sent has to be an offset from the altitude the drone achieved gps lock at and not true altitude above sea level.

After changing my alt value to 1-2 (meters) I'm ready to go test, however It raining today so that wont happen, I have however held my drone indoor and tested the code.

After sending the command the drone wants to fly in a circle for an odd reason quickly (may be trying to loiter with the radius i have defined as 1m for circling waypoint) before then attempting to fly in the direction of the co-ordinates sent which to the best of my knowledge means the apm is correctly carrying out he command

.

Hopefully this means all is well, however Im going to have to wait for the rain to stop and ground to dry a little before i bite the bullet and try it....

Hi Matthew,

im working on a project that sound like the one you did and i want to know if you solve your problem and if it works fine for you?

Actuelly im trying to send message to PiX4 using mavlink lib (mavlink_msg_set_mode_pack(..))and i wonder how you did to find the 

@brief Pack a set_mode message
@param system_id ID of this system

@param component_id ID of this component (e.g. 200 for IMU)
@param msg The MAVLink message to compress the data into

Reply to Discussion

RSS

© 2019   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service