This section contains examples showing how to use Dronecode SDK.
|Takeoff and Land||Shows basic usage of the SDK (connect to port, detect system (vehicle), arm, takeoff, land, get telemetry)|
|Fly Mission||Shows how to create, upload, and run missions.|
|Fly QGC Plan Mission||Fly a mission imported from a QGroundControl mission plan.|
|Offboard Velocity Control||Demonstrates how to control a vehicle in Offboard mode using velocity commands (in both the NED and body frames).|
|Follow Me Mode||Demonstrates how to put vehicle in Follow Me Mode and set the current target position and relative position of the drone.|
|VTOL Transitions||Shows how to transition a VTOL vehicle between copter and fixed-wing modes.|
The examples are "largely" built and run in the same way, as described in the following section (any exceptions are covered in the page for the associated example).
Some of the examples define flight behaviour relative to the default home position in the simulator (e.g. Fly Mission). Care should be taken if using them on a real vehicle.
Trying the Examples
The easiest way to test the examples is to use a simulated PX4 vehicle that is running on the same computer. First start PX4 in SITL (Simulation), optionally start QGroundControl to observe the vehicle, then build and run the example code.
Setting up a Simulator
JMAVSim can only be used to simulate multicopters. Gazebo additionally supports a number of other vehicles (e.g. VTOL, Rovers, fixed-wing etc.).
After running a standard installation, a simulation can be started from the PX4 /Firmware directory using the command:
- Multicopter (jMAVSim):
make posix_sitl_default jmavsim
- Multicopter (Gazebo):
make posix_sitl_default gazebo
- VTOL (Gazebo):
make posix_sitl_default gazebo_standard_vtol
You can use QGroundControl to connect to PX4 and observe vehicle movement and behaviour while the examples are running. QGroundControl will automatically connect to the PX4 simulation as soon as it is started.
See QGroundControl > Download and Install for information about setting up QGroundControl on your platform.
Building the Examples
To build the examples follow the instructions below, replacing takeoff_and_land with the name of the specific example. Any exceptions will be covered in the page for the associated example(s).
First Build and install the SDK C++ Library system-wide using the command below:
make clean make default sudo make default install
Then build the example:
cd example/takeoff_land/ mkdir build && cd build cmake .. make
cmake --build . --target install
Modify the example as described in Building C++ Apps > SDK Installed Locally (this is required for Windows).
Build the example as described in Building C++ Apps. Below we show how for the takeoff_land example, but all the other examples are built in the same way:
cd example/takeoff_land/ mkdir build && cd build cmake .. -G "Visual Studio 15 2017 Win64" cmake --build .
The debug binary for the example is stored under \Debug folder.
Running the Examples
You can then run the example, specifying the connection URL as the first argument.
When running with the Simulator, you will use the connection string:
On Linux/macOS you would run the following (from the /build directory):
For Windows you would run the following (from the \build\Debug\ directory):
Most examples will create a binary with the same name as the example. The name that is used is specified in the CMakeLists.txt file as the first value in the call to
If you have already started the simulation the example code should connect to PX4, and you will be able to observe behaviour through the SDK terminal, SITL terminal, and/or QGroundControl.
Linux: Error loading shared libraries
The following error is raised when you run an application/example on Linux and the Dronecode SDK shared library cannot be found:
error while loading shared libraries: libdronecode_sdk.so: cannot open shared object file: No such file or directory
The solution is to update the linker cache so that the system can find the library. On Ubuntu call the following:
For more information/other Linux flavours see Linux Documentation > Shared Libraries.