This section contains examples showing how to use DroneCore.

  • Takeoff and Land - Shows basic usage of DroneCore (connect to port, detect device, arm, takeoff, land, get telemetry)
  • Fly Mission - Shows how to create, upload, and run missions.

All examples are all 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 examples are designed to automatically connect to a simulated PX4 vehicle that is running on the same computer.

In order to test them, first start PX4 in SITL (Simulation), optionally start QGroundControl to observe the vehicle, then build and run the example code.

The simulator broadcasts to the standard PX4 UDP port for connecting to offboard APIs (14540). The examples connect to this port by default, using DroneCore::add_udp_connection().

Setting up a Simulator

PX4 supports a number of simulators. In order to set up the jMAVSim or Gazebo simulator, you can simply follow the standard PX4 toolchain setup instructions for macOS or Ubuntu Linux.

Once the simulator is installed, it can be started from the PX4 /Firmware directory using the command:

  • jMAVSim: make posix_sitl_default jmavsim
  • Gazebo: make posix_sitl_default gazebo

Windows is not recommended for PX4/DroneCore development - by preference you should use a dual-boot Linux computer, or run both simulated PX4 and DroneCore in a virtual machine.

Using QGroundControl

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 DroneCore C++ Library. Make sure that you install the library and headers locally (rather than system-wide) using the command below:

make default install

Then build and run the example:

cd example/takeoff_and_land/
mkdir build && cd build
cmake ..


First Build and install the DroneCore C++ Library. Make sure that you install the library and headers in the standard location:

cmake --build . --target install

Build and run the example as shown below (in this case takeoff_and_land, but all the other examples are built and run in the same way):

cd example/takeoff_land/
mkdir build && cd build
cmake --build .

The debug binary for the example is stored under \Debug folder.

Running the Examples

On all platform you can then run the new executable (from the \build directory):


If you have already started the simulation the example code should connect to PX4, and you will be able to observe behaviour through the DroneCore terminal, SITL terminal, and/or QGroundControl.

© Dronecode 2017. License: CC BY 4.0            Updated: 2018-02-01 00:34:22

results matching ""

    No results matching ""