Which MAVLink commands to control the drone


I would like to write a C/C++ program to control a quadrotor but I’m not sure of which commands to use. Here’s some context: I am using a Pixhawk4 (and a Pixhawk 4 mini for an other drone but I guess it works the same way) on which I connected the GPS module and a telemetry module. Then on a computer, an other telemetry module is connected. For now, I am able to read and send MAVLink messages. My final goal would be to build a neural network to send decision order (go left,right,up,down,forward,backward, speed doesn’t matter) through MAVLink.

So my question is, which MAVLink commands is/are the most suited for this case ?

I found some that could be interesting but I am not sure how to make them work properly (the autopilot reject the commands, i suspect it’s a mode problem) : SET_POSITION_TARGET_LOCAL_NED, MANUAL_CONTROL, MAV_CMD_DO_REPOSITION (sent in a COMMEND_INT command), MAV_CMD_NAV_WAYPOINT ? Am I going to the right direction or is there better command ?

Any help would be appreciated.

You might want to build on top of MAVSDK which provides an API that’s much more simple than having to deal with raw MAVLink. Just look at offboard examples, or goto.

I’m linking the examples from the v1.4 branch as they work against MAVSDK installed from release where you find a .deb to install.

I installed the .deb from your link and downloaded the code from this branch GitHub - mavlink/MAVSDK at v1.4
But I have trouble building the offboard example. I tried to build with those lines ( from Building library from Source · MAVSDK Guide ):

cmake -Bbuild/default -H. -DCMAKE_BUILD_TYPE=Release
cmake --build build/default -j8 --config Release

An error happens on the second cmake:

geyart@Latitude-3500:~/projects/MAVSDK/examples/offboard$ cmake --build build/default -j8
-- Configuring done
-- Generating done
-- Build files have been written to: /home/geyart/projects/MAVSDK/examples/offboard/build/default
Consolidate compiler generated dependencies of target offboard
[ 50%] Building CXX object CMakeFiles/offboard.dir/offboard.cpp.o
In file included from /home/geyart/projects/MAVSDK/examples/offboard/offboard.cpp:14:
/usr/local/include/mavsdk/plugins/action/action.h:16:10: fatal error: plugin_base.h: No such file or directory
   16 | #include "plugin_base.h"
      |          ^~~~~~~~~~~~~~~
compilation terminated.
gmake[2]: *** [CMakeFiles/offboard.dir/build.make:76: CMakeFiles/offboard.dir/offboard.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/offboard.dir/all] Error 2
gmake: *** [Makefile:91: all] Error 2

Something is not right: the include is in /usr/local/ this is not what is installed from the .deb as it would be in /usr/.

I suggest to remove the version you installed manually and try again:

sudo rm -rf /usr/local/include/mavsdk /usr/local/lib/libmavsdk* /usr/local/lib/cmake/MAVSDK

Thanks! I may have mishandled the installation which was put in /usr/local/ but now it’s working with the right setup.

1 Like