Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This is the full instructions to get setup as a developer for MAVSDK

Getting started

Step 1 : The first thing you want to do is download QGroundControl (QGC) here. This will allow you to configure your vehicle and start playing with the simulator.

Step 2 : Now you will need to install and run a simulator for future development and testing. Follow these instructions for Linux, MacOS, and Windows.

Linux (Ubuntu)

  1. Inside your terminal type the following command to make the user a member of the group "dialout".
sudo usermod -a -G dialout $USER
  • Now you need to logout and log back into your user.
  1. Download the ubuntu_sim_nuttx.sh file then run it.
wget https://raw.githubusercontent.com/PX4/Devguide/master/build_scripts/ubuntu_sim_nuttx.sh
source ubuntu_sim_nuttx.sh
  • You may need to acknowledge some prompts as the script progresses.
  1. Restart the computer when this is finished.

  2. If you're looking to setup any other distrobution then please follow the instructions located here.

  3. Now you're able to to run the simulator.

cd ~/src/Firmware
make posix jmavsim
  • The first time you run the simulator it will take a while to build. Everything should run and a new screen of the simulator should open. You will see a drone on the ground.
  1. You can now open QGC and it will automatically connect to the simulator.

MacOS

  1. First you should install the latest Java Development Kit 8 (JDK) from here.

  2. Then you will need to install Homebrew. Follow the instructions from this page.

  3. Then you will need to have Python 3.7+ installed. You can follow the instructions to download and install here.

  • If you already have a python version installed then you may need to setup a symlink for the new version after you have installed it.
## This will check the version. If it's not what you just installed then proceed with the other commands
python --version
sudo unlink /usr/local/bin/python
sudo ln -s /usr/local/bin/python3.x /usr/local/bin/python
  1. Once you have installed Homebrew and Python then run these commands in your terminal in this order.
brew cask install xquartz java
brew tap PX4/px4
brew install px4-dev
brew install px4-sim
sudo easy_install pip
sudo -H pip install nose tornado pyserial empy toml pandas jinja2 pyyaml
  • 'brew install px4-dev' is used to install the PX4 toolchain.
  • 'brew install px4-sim' is used to install the PX4 Simulation toolchain.
  • This is assuming you're installing on a fresh install of MacOS. If you have previously installed any of these dependencies then you may run into problems, be sure to read the outputs in case there are errors.
  • You may have to run commands a few times as it might fail for various reasons, such as a timeout.
  1. Close your terminal to restart a session. This will ensure everything is running correctly.

  2. Assuming you already have 'git' installed you will need to fork the PX4/Firmware repository.

  • If you do not have git installed then run the following in your terminal.
brew install git
  1. Once you have forked the repository then clone it to a directory on your computer.
git clone https://github.com/<youraccountname>/Firmware.git
  1. After the clone is complete then type the following commands.
cd Firmware
make posix jmavsim

If you are on MacOS Catalina then you might have a problem with cmake. Run xcode-select --install then sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/* /usr/local/include/ in your terminal and it should all work.

  • The first time you run the simulator it will take a while to build. Everything should run and a new screen of the simulator should open. You will see a drone on the ground.
  1. You can now open QGC and it will automatically connect to the simulator.

Windows

  1. First you should install the latest Java Development Kit 8 (JDK) from here.

  2. Then you will need to have Python 3.6+ installed. You can follow the instructions to download and install here.

  3. Download the latest version of Cygwin Toolchain. Run it, choose your desired installation location, let it install.

  • Tick the box at the end of the installation to clone the PX4 repository, build and run simulation with jMAVSim (this simplifies the process to get you started).
  1. Navigate to the toolchain installation directly C:\PX4\ then click on run-console.bat to start the Cygwin bash console. Once inside the console type the following
cd Firmware
make posix jmavsim
  • Everything should run and a new screen of the simulator should open. You will see a drone on the ground.
  1. You can now open QGC and it will automatically connect to the simulator.

Step 3 : After getting QGC and the simulator up you will now want to setup your development environment for C++, Python, or Swift.

C++

  1. Build the C++ library
  • MacOS

    a. Make sure to have Xcode installed

    b. In the terminal run the following command to install cmake

    brew install cmake

    c. Follow the instructions for building the library in linux from (b) on.

  • Linux

    a. First install the dependencies

    sudo apt-get update -y
    sudo apt-get install cmake build-essential colordiff git doxygen -y

    b. Clone the MAVSDK repository (or your fork):

    git clone https://github.com/mavlink/MAVSDK
    cd MAVSDK

    c. Checkout the release/branch you want to build (the develop branch is checked out by default).

    • Latest stable build (master):
    git checkout master
    • Head revision with latest features (develop):
    git checkout develop

    d. Update the submodules:

    git submodule update --init --recursive

    e. Build the (debug) C++ library by calling:

    cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=ON -Bbuild/default -H.
    cmake --build build/default
  • Windows

    a. Build Tools for Visual Studio 2017: Download and install (only the "Visual C+ Build Tools" are needed from installer).

    b. cmake: Download the installer and run it. Make sure to tick "add to PATH" during the installation.

    c. Follow the Linux build steps from (b) to (d)

    d. Then build the SDK in Windows:

    cd /your/path/to/DronecodeSDK
    cmake -G "Visual Studio 15 2017" -DBUILD_SHARED_LIBS=ON -Bbuild/default -H.
    cmake --build build/default --config Debug
  1. Install the SDK
  • System-wide Install

    Warning System-wide installation is not yet supported on Windows (see #155) so you will need to install the SDK locally.

    Windows gurus, we'd love your help to implement this).

    a. System-wide installation copies the SDK headers and binaries to the standard system-wide locations for your platform (e.g. on Ubuntu Linux this is /usr/local/).

    b. To install the SDK system-wide:

    sudo cmake --build build/default --target install # sudo is required to install to system directories!
    
    # First installation only
    sudo ldconfig  # update linker cache

    Warning System-wide installation overwrites any previously installed version of the SDK.

  • Local Install

    a. Local installation copies the SDK headers/library to a user-specified location inside the SDK source directory.

    b. On Linux/macOS use the CMAKE_INSTALL_PREFIX variable to specify a path relative to the folder from which you call cmake (or an absolute path). For example, to install into the DronecodeSDK/install/ folder you would call:

    cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=install -Bbuild/default -H.
    cmake --build build/default --target install

    Tip If you already have run cmake without setting CMAKE_INSTALL_PREFIX, you may need to clean the build first:

    rm -rf build/default
    
  1. Build the backend
  • To build the backend on Ubuntu/MacOS:

    a. Navigate into the SDK directory and build the project

    cd DronecodeSDK
    cmake -DBUILD_BACKEND=ON -Bbuild/default -H.
    cmake --build build/default
  • To build the backend on Windows:

    a. Navigate into the SDK directory and build the project

    cmake -G "Visual Studio 15 2017" -DBUILD_BACKEND=ON -Bbuild/default -H.
    cmake --build build/default
  1. Build API reference documentation
  • Extract the documentation to markdown files (one per class) on macOS or Linux using the commands:
    rm -rf docs/install  # Remove previous docs
    ./tools/generate_docs.sh

Python (Available for MacOS and Linux)

  1. You will first need to install go.
  • Type this command into your terminal for MacOS.
brew install go
  • Type this command into your terminal for Linux.
sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt update
sudo apt install golang-go -y
  1. Then you can setup the backend
  • Download, build, and run the backend.
pip install mavsdk aioconsole
  • Now that everything is installed you're able to run the example.
examples/takeoff_and_land.py
  • Python is actively being developed, and should be released soon. Follow this repo for any and all updates.

Swift (Available for MacOS)

  1. We need to install a few packages first.
  • Run this command.
brew install xcodegen carthage
  1. First, let's get the example app so you can see how everything is implemented.
  • Clone the example app.
git clone https://github.com/mavlink/MAVSDK-Swift-Example
  • Later on you may receive a warning stating that You don't have /User/yourusername/.gem/ruby/x.x.x/bin in your PATH. To solve this run the following command replacing the x.x.x with what you received.
echo 'export PATH="$HOME/.gem/ruby/x.x.x/bin:$PATH"' >> ~/.bash_profile
  • Then close your terminal and open it again. Confirm the path has been written to your bash_profile by running this.
cat ~/.bash_profile
  • Now you can go back into the example app directory and create the Xcode project from the project.yml file with xcodegen.
cd MAVSDK-Swift-Example
xcodegen
  • Now install the xcodeproj gem.
gem install --user xcodeproj
  • Get the dependencies with Carthage.
rm -rf Carthage ~/Library/Caches/org.carthage.CarthageKit ~/Library/Caches/carthage
carthage bootstrap --platform ios
  • Now you can open the project with.
open MAVSDK-Swift-Example.xcodeproj
  • You can run the simulator then run the app and it will automatically connect. Once you've familiarized yourself with everything we can move forward with installing the MAV Swift SDK on your own app.
  1. Now, create a new Xcode project using Swift.
  • Then go into your terminal and run the following.
cd YourProject
gem install --user xcodeproj
  • Using the editor of your choice create a new Cartfile and add the following.
github "mavlink/MAVSDK-Swift" ~> 0.6.0
  • You will need to also create a .gitignore file and add the follwoing.
/Carthage

Now, inside your project folder and in the terminal run the following.

rm -rf Carthage ~/Library/Caches/org.carthage.CarthageKit ~/Library/Caches/carthage
carthage bootstrap --platform ios
  1. Back in your Xcode project you will need to import some libraries
  • On your application targets’ General settings tab, in the “Linked Frameworks and Libraries” section, drag and drop all files with the file extension .framework under the new /Carthage/Build/iOS/ folder in your project into here, except for RxBlocking.framework, RxCocoa.framework, and RxTest.framework.
  • On your application targets’ Build Phases settings tab, click the + icon and choose New Run Script Phase. Create a Run Script in which you specify your shell (ex: /bin/sh), add the following contents to the script area below the shell:
/usr/local/bin/carthage copy-frameworks
  • Add the paths to the frameworks under “Input Files".
$(SRCROOT)/Carthage/Build/iOS/BoringSSL.framework
$(SRCROOT)/Carthage/Build/iOS/CgRPC.framework
$(SRCROOT)/Carthage/Build/iOS/mavsdk_server.framework
$(SRCROOT)/Carthage/Build/iOS/MAVSDK_Swift.framework
$(SRCROOT)/Carthage/Build/iOS/RxSwift.framework
$(SRCROOT)/Carthage/Build/iOS/SwiftProtobuf.framework
$(SRCROOT)/Carthage/Build/iOS/SwiftGRPC.framework
  • Add the paths to the copied frameworks to the “Output Files”.
$(DERIVED_FILE_DIR)/$(FRAMEWORKS_FOLDER_PATH)/BoringSSL.framework
$(DERIVED_FILE_DIR)/$(FRAMEWORKS_FOLDER_PATH)/CgRPC.framework
$(DERIVED_FILE_DIR)/$(FRAMEWORKS_FOLDER_PATH)/mavsdk_server.framework
$(DERIVED_FILE_DIR)/$(FRAMEWORKS_FOLDER_PATH)/MAVSDK_Swift.framework
$(DERIVED_FILE_DIR)/$(FRAMEWORKS_FOLDER_PATH)/RxSwift.framework
$(DERIVED_FILE_DIR)/$(FRAMEWORKS_FOLDER_PATH)/SwiftProtobuf.framework
$(DERIVED_FILE_DIR)/$(FRAMEWORKS_FOLDER_PATH)/SwiftGRPC.framework
  • You will then need to go into Build Settings, click on All, then search for bitcode. You need to change Enable Bitcode from "Yes" to "No".
  1. Start MAVLink connection The steps below assume that your iOS device has a network connection to the drone, e.g. using WiFi. By default, the SDK will connect using MAVLink on UDP port 14540, which is running by default when PX4 is run in SITL (software in the loop simulation). For now, the backend is limited to UDP even though the core supports UDP, TCP, and serial. Import the SDK with the following code.
import MAVSDK_Swift
let drone = Drone()

Then activate with drone.startMavlink.subscribe()

  • For advanced users: note that startMavlink will run the SDK backend in a background thread on the iOS device. You could connect the SDK to another backend (say, running on a computer with IP 192.168.0.42 by omitting the second line above and running only: let drone = Drone(address: "192.168.0.42", port: 50051).

If you're using a wifi bridge then you can start a UDP connection with the following:

drone.setMavlinkPort(mavlinkPort: "udp://:14550")
  1. Start writing code
  • After that, you can start using the SDK, for instance:
drone.action.arm()
     .andThen(drone.action.takeoff())
     .subscribe()

or

drone.telemetry.position()
     .do(onNext: { next in print(next) })
     .subscribe()

You can learn more about MAVSDK_Swift here

BONUS Telemetry through wifi for iPad or iPhone

Follow these instructions and you will be able to connect your iPad or iPhone to your drone through QGC on the device

  • If you're using the SiK Radio then you will need to connect to the ESP8266 through your browser (192.168.4.1) and set the UART_BAUDRATE to 57600. The Sik Radio isn't compatible with 921600
@Ayshine

This comment has been minimized.

Copy link

Ayshine commented Dec 3, 2019

step 5 of downloading the simulator for Linux (both 16 and 18) I am getting "No such file or directory" when running cd ~/src/Firmware. I don't seem to get any errors for the prior steps. Is there any way to check what I did wrong ? Where should I try to locate the Firmware folder?

@unipheas

This comment has been minimized.

Copy link
Owner Author

unipheas commented Dec 5, 2019

step 5 of downloading the simulator for Linux (both 16 and 18) I am getting "No such file or directory" when running cd ~/src/Firmware. I don't seem to get any errors for the prior steps. Is there any way to check what I did wrong ? Where should I try to locate the Firmware folder?

When you run the script prior to this step, is there an error of some sort?

@Ayshine

This comment has been minimized.

Copy link

Ayshine commented Dec 5, 2019

Maybe an old installation attempt left some broken files preventing a clear installation. I'll reinstall ubuntu 16 partition from scratch and try this with clean OS installation. Meanwhile, I completed the installation above on a Windows machine with C++ development environment. But, I don't know how to test the installation. Is there any documentation available for that?

@unipheas

This comment has been minimized.

Copy link
Owner Author

unipheas commented Dec 5, 2019

Maybe an old installation attempt left some broken files preventing a clear installation. I'll reinstall ubuntu 16 partition from scratch and try this with clean OS installation. Meanwhile, I completed the installation above on a Windows machine with C++ development environment. But, I don't know how to test the installation. Is there any documentation available for that?

It should tell you where it has installed. Maybe an update has changed it. I don't think you'd need a full reinstall of Ubuntu.
That said, you can find all of the documentation at https://www.dronecode.org/documentation/

@MaEtUgR

This comment has been minimized.

Copy link

MaEtUgR commented Dec 19, 2019

Hey @unipheas nice guide. Cool to see you found good use for the Cygwin toolchain in your workflow. Just wanted to note that the toolchain is self contained and you don't need to install JDK or Python on your machine to use it. The only thing you really need is an empty Windows installation but I suggest to install the native git client e.g. to use gitk and an IDE that supports unix line endings. Maybe you can write in your guide why you install JDK and Python...

@unipheas

This comment has been minimized.

Copy link
Owner Author

unipheas commented Dec 25, 2019

Thank you. I'll be revisiting this in a few months. I've got a few things to take care of right now and also am dealing with really bad internet connections, so I'm moving. Once that's all dealt with then I'll be able to spend more time working on a better guide and getting everything setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.