In order to run a C++ application that uses MAVLink protocol, first, you must have installed the MAVSDK C++ library. On Ubuntu or Fedora, the users should install the MAVSDK C++ *.deb or *.rpm packages from the Github release page (https://github.com/mavlink/MAVSDK/releases) or, the second option, they must build and install the MAVSDK C++ Library. This last option will be presented here.
So, please follow the steps:
1.Build & Install MAVSDK core C++ Library
- [a] First, get the NavQ ready:
$ sudo apt update
$ sudo apt upgrade
Now we’re going to build this library on the NavQ. So let’s start:
- [b] Go here to build the C++ SDK from source:
https://mavsdk.mavlink.io/develop/en/contributing/build.html
and follow all the steps from ‘Building SDK from Source’. In my case, I use the instructions for the ‘Linux’ Operating System (OS). Use the latest stable build (master) and build the Release libraries.
But, if you can have a problem to build the Release binaries (only in Raspberry Pi – from my experience, for the NavQ is working correctly), in this situation, make the Debug C++ library.
- [c] Troubleshooting - the vast majority of common build issues can be resolved by updating submodules and cleaning the distribution (it wasn't my case, but I inserted this information here just in case):
$ cd ~
$ cd MAVSDK
$ git submodule update --recursive
$ rm -rf build
Then attempt to make it again – repeat the [b] step once again.
- [d] Install the SDK and use the system-wide install as described here: https://mavsdk.mavlink.io/develop/en/contributing/build.html#install-artifacts. If you build a new version of MAVSDK, don't bother how to uninstall the previous version of the MAVSDK, this is because “System-wide installation overwrites any previously installed version of the SDK”.
2. Set up TELEM2 on the FMU
Communication between NavQ and FMU (FMUK66) requires some configuration to be done on the FMU side through the QGroundControl. First, connect the QGroundControl to the HoverGames drone. Second, navigate in QGroundControl to Settings → Parameters → MAVLinkand set the MAV_1_CONFIG to TELEM 2.
The rest of the parameters (MAV_1_FORWARD, MAV_1_MODE, etc.) will appears only after you will reboot the FMU. So, press the Tools button (right-up corner) and select Reboot Vehicle. Now you can set these parameters accordingly with the following image:
Also, you'll need to make sure that, the settings for SER_TEL2_BAUD (Settings → Parameters → Serial) is like in the next image:
3. Configuring the serial port on NavQ
Make sure that your NavQ is set up correctly to communicate over serial by running the following command:
$ stty -F /dev/ttymxc2 921600
4. Building one C++ example and test, base on it, all the setup
- [a] Now build one example:
$ cd ~
$ cd MAVSDK
$ cd examples/takeoff_land/
$ mkdir build && cd build
$ cmake ..
$ make
- [b] Now run the example app (from the example/takeoff_land/build directory) as shown:
$ ./takeoff_and_land serial:///dev/ttymxc2:921600
In the end, if all is OK, you will get this (or something similar):
$ ./takeoff_and_land serial:///dev/ttymxc2:921600
[11:35:13|Info ] MAVSDK version: v0.29.0 (mavsdk_impl.cpp:27)
[11:35:13|Debug] New: System ID: 0 Comp ID: 0 (mavsdk_impl.cpp:404)
Waiting to discover system…
[11:35:13|Debug] Component Autopilot (1) added. (system_impl.cpp:344)
[11:35:13|Debug] Discovered 1 component(s) (UUID: 10832640680271026576) (system_impl.cpp:517)
Discovered system with UUID: 10832640680271026576
Discovered a component with type 1
Vehicle is getting ready to arm
Vehicle is getting ready to arm
Vehicle is getting ready to arm
Here is a short movie that presents a connection from a C++ application (running on NavQ - RDDRONE-8MMNavQ) to FMUK66:
If you develop your code in C/C++, you have all the tools and packages installed and configured – now you are ready to work with MAVLink from a C++ program, so happy coding! But mainly because I need to work in Python, I will continue with all packages require to be installed for Python.
The steps required to connect from a Python application to the FMUK66 flight management unit base on MAVLink protocolSo, for all of you who want to work in Python, please continues with:
5. Building mavsdk_server
The MAVSDK programming language-specific libraries (e.g., Swift, Python) share a standard backend (called "mavsdk_server"). This server may be optionally built as part of the MAVSDK C++ library. In our case, we need this server so let’s start building it.
- [a] Go to the MAVSDK directory and:
$ sudo cmake -DBUILD_BACKEND=ON --symlink-install --cmake-args "-DCMAKE_SHARED_LINKER_FLAGS='-latomic'" "-DCMAKE_EXE_LINKER_FLAGS='-latomic'" -Bbuild/default -H.
In the end, you will get:
-- Configuring done
-- Generating done
-- Build files have been written to: /home/navq/MAVSDK/build/default
And, now the last step:
$ sudo cmake --build build/default
- [b] Take note, the file mavsdk_server that you will need for MAVSDK-Python is in the directory: MAVSDK/build/default/src/backend/src/
- [c] To check the mavsdk_server you can use:
./mavsdk_server -v
[03:38:31|Info ] MAVSDK version: v0.30.1 (mavsdk_impl.cpp:27)
[03:38:31|Debug] New: System ID: 0 Comp ID: 0 (mavsdk_impl.cpp:405)
[03:38:31|Info ] Server started (grpc_server.cpp:44)
[03:38:31|Info ] Server set to listen on 0.0.0.0:37277 (grpc_server.cpp:45)
[03:38:31|Info ] Waiting to discover system on -v... (connection_initiator.h:22)
[03:38:31|Warn ] Unknown protocol (cli_arg.cpp:71)
[03:38:31|Error] Connection failed: Invalid connection URL (connection_initiator.h:48)
6. Install MAVSDK-Python
To install MAVSDK-Python, simply run:
$ pip3 install mavsdk
Copy that mavskd_server file into MAVSDK-Python/mavsdk/bin/
7. Testing the MAVLink connection based on a python program
- [a] First the mavsdk_server must be active:
$ cd ~
$ cd MAVSDK/build/default/src/backend/src/
$ ./mavsdk_server -p 50051 serial:///dev/ttymxc2:921600
- [b] Download from the repository an example, in my case I downloaded the same example used in the case of C/C++ test:
$ wget https://raw.githubusercontent.com/mavlink/MAVSDK-Python/master/examples/takeoff_and_land.py
- [c] Replace the following two code line (from: takeoff_and_land.py):
drone = System()
await drone.connect(system_address="udp://:14540")
with:
drone = System(mavsdk_server_address='localhost', port=50051)
await drone.connect(system_address="serial:///dev/ttymxc2:921600")
On each example downloaded from the repository, in order to work correctly, you must replace the two lines of code previously presented.
- [d] In the end, run the program:
$ python takeoff_and_land.py
If all is correctly installed and configured, you will get the following messages:
Waiting for mavsdk_server to be ready...
Connected to mavsdk_server!
Waiting for drone to connect...
Drone discovered with UUID: 10832640680271026576
Waiting for drone to have a global position estimate...
That was all !!!!... and now have fun with code development for HoverGames drone !!!! By !
Comments