Emergency Yaw recovery using EKF-GSF estimator (PR PX4/PX4-ECL#766) Major sensor calibration improvements (Gyro, Mag, Level) Main Features and Improvements Migration Guide. DEPRECATED: VTOL is no longer supported in FMUv2 hardware; PX4/Drivers. Enable SPI DMA adds centralized DMA map (PR #14207) Move primary IMU to new InvenSense driver (PR #14356).
Flow data is transmitted via wireless at a lower rate. The recommended mounting orientation (meaning: zero rotation) is defined as Y on flow board pointing towards front of vehicle, as shown in the following picture. On PX4, the orientation should be set using the parameter SENSFLOWROT. Dec 03, 2020 #Driver Development. PX4 device drivers are based on the Device (opens new window) framework. # Creating a Driver PX4 almost exclusively consumes data from uORB.Drivers for common peripheral types must publish the correct uORB messages (for example: gyro, accelerometer, pressure sensors, etc.).
The camera trigger driver allows the use of the AUX ports to send out pulses in order to trigger a camera. This can be used for multiple applications including timestamping photos for aerial surveying and reconstruction, synchronising a multi-camera system or visual-inertial navigation.
In addition to a pulse being sent out, a MAVLink message is published containing a sequence number (thus the current session's image sequence number) and the corresponding timestamp.
Trigger Modes/Configuration
Trigger Modes
Four different modes are supported, controlled by the TRIG_MODE parameter:
Value | Description |
---|---|
0 | Camera triggering is disabled. |
1 | Camera triggered on time interval ('intervalometer'). Triggering can be enabled and disabled by using the MAV_CMD_DO_TRIGGER_CONTROL MAVLink command. See command interface for more details. |
2 | Camera triggered on time interval. Triggering always enabled. |
3 | Camera triggered based on distance. A shot is taken every time the set horizontal distance is exceeded. The minimum time interval between two shots is however limited by the set triggering interval. |
4 | Triggers automatically when flying a survey in Mission mode. |
If it is your first time enabling the camera trigger app, remember to reboot after changing the TRIG_MODE
parameter.
Trigger Hardware Configuration
You can choose which AUX pins to use for triggering using the TRIG_PINS parameter. The default is 56, which means that trigger is enabled on AUX 5 and AUX 6.
DO NOT CHANGE THE DEFAULT VALUE OF TRIG_PINS
IF YOU NEED ACTUATOR OUTPUTS.With TRIG_PINS set to its default value of 56, you can use the AUX pins 1, 2, 3 and 4 as actuator outputs (for servos/ESCs). Due to the way the hardware timers are handled (1234 and 56 are 2 different groups handled by 2 timers), this is the ONLY combination which allows the simultaneous usage of camera trigger and FMU actuator outputs.
Trigger Interface Backends
The camera trigger driver supports several backends for triggering different types of camera interfaces. The type of camera can be specified using the TRIG_INTERFACE parameter:
Value | Interface | Description |
---|---|---|
1 | GPIO interface | The AUX outputs are pulsed high or low (depending on the TRIG_POLARITY parameter) every TRIG_INTERVAL duration. This can be used to trigger most standard machine vision cameras directly. Note that on PX4FMU series hardware (Pixhawk, Pixracer, etc.), the signal level on the AUX pins is 3.3v. |
2 | Seagull MAP2 interface | This allows the use of the Seagull MAP2 to interface to a multitude of supported cameras. Pin 1 of the MAP2 should be connected to the lower AUX pin of TRIG_PINS (therefore, pin 1 to AUX 5 and pin 2 to AUX 6 by default). In this mode, PX4 also supports automatic power control and keep-alive functionalities of Sony Multiport cameras like the QX-1. |
3 | MAVLink interface | In this mode, no actual hardware output is used - the driver only sends the CAMERA_TRIGGER MAVLink message (by default, if the MAVLink application is in onboard mode. Otherwise, a custom stream will need to be enabled). PX4 must separately forward all MAVLink camera messages from a GCS to a connected MAVLink camera. |
4 | Generic PWM interface | Allows the use of infrared triggers or servos to trigger your camera. |
Other Parameters
- TRIG_POLARITY - Relevant only while using the GPIO interface. Sets the polarity of the trigger pin. Active high means that the pin is pulled low normally and pulled high on a trigger event. Active low is vice-versa.
- TRIG_INTERVAL - Defines the time between two consecutive trigger events in milliseconds.
- TRIG_ACTIVATION_TIME - Defines the time in milliseconds the trigger pin is held in the 'active' state before returning to neutral. In PWM modes, the minimum is limited to 40 ms to make sure we always fit an activate pulse into the 50Hz PWM signal.
The full list of parameters pertaining to the camera trigger module can be found on the parameter reference page.
Download Px4 Flow (com16) Driver Installer
Trigger Command Interface

The camera trigger driver supports the following commands.
MAV_CMD_DO_TRIGGER_CONTROL
MAV_CMD_DO_TRIGGER_CONTROL - Accepted in TRIG_MODE 1
('command controlled' mode).
Command Parameter | Description |
---|---|
Param #1 | Trigger enable/disable (set to 0 for enable, 1 for start) |
Param #2 | Sequence reset (set to 1 to reset image sequence number, 0 to keep current sequence number) |
Param #3 | Trigger pause/restart (set to 0 for pause, 1 for restart). Pausing does not switch off/retract the camera. |
MAV_CMD_DO_DIGICAM_CONTROL
MAV_CMD_DO_DIGICAM_CONTROL - Accepted in all modes. This is used by the GCS to test-shoot the camera from the user interface. The trigger driver does not yet support all camera control parameters defined by the MAVLink spec.
Command Parameter | Description |
---|---|
Param #5 | Trigger one-shot command (set to 1 to trigger a single image frame) |
Param #7 | Trigger test shot - not logged or forwarded to GCS for geotagging (set to 1 to trigger a test shot) |
MAV_CMD_DO_SET_CAM_TRIGG_DIST
MAV_CMD_DO_SET_CAM_TRIGG_DIST - Accepted in 'mission controlled' mode (TRIG_MODE
4)
This command is auto-generated during missions to trigger the camera based on survey missions from the GCS.
Command Parameter | Description |
---|---|
Param #1 | Trigger distance between shots (if >0 ). 0 : triggering paused. -1 : triggering disabled. |
Param #2 | Trigger activation time in ms - for GPIO mode only (TRIG_INTERFACE 1 ) |
Param #2 | Trigger single shot immediately (if >0) |
MAV_CMD_DO_SET_CAM_TRIGG_INTERVAL
MAV_CMD_DO_SET_CAM_TRIGG_INTERVAL - Accepted in 'mission controlled' mode (TRIG_MODE
4)
This command is auto-generated during missions to trigger the camera based on survey missions from the GCS.
Command Parameter | Description |
---|---|
Param #1 | Trigger interval time. |
Param #2 | Shutter activation time in ms - for GPIO mode only (TRIG_INTERFACE 1 ) |
Param #2 | Trigger single shot immediately (if >0) |
Testing Trigger Functionality
On the PX4 console:
From QGroundControl:
Click on Trigger Camera in the main instrument panel. These shots are not logged or counted for geotagging.
Examples
Sony QX-1 example (Photogrammetry)
In this example, we will use a Seagull MAP2 trigger cable to interface to a Sony QX-1 and use the setup to create orthomosaics after flying a fully autonomous survey mission.
Trigger Settings
The camera trigger can be configured from the QGroundControlSettings tab > Camera page
TRIG_INTERFACE
: 2, Seagull MAP2.TRIG_MODE
: 4, Mission controlled.
Leave the rest of the parameters at their defaults.
You will need to connect the Seagull MAP2 to the auxiliary/FMU pins on your autopilot. Pin 1 goes to AUX 5, and Pin 2 to AUX 6. The other end of the MAP2 cable will go into the QX-1's 'MULTI' port.
Camera Configuration
We use a Sony QX-1 with a 16-50mm f3.5-5.6 lens for this example.
To avoid autofocus and metering lag when the camera is triggered, the following guidelines should be followed :
- Manual focus to infinity
- Set camera to continuous shooting mode
- Manually set exposure and aperture
- ISO should be set as low as possible
- Manual white balance suitable for scene
Mission Planning
Geotagging
Download/copy the logfile and images from the flight and point QGroundControl to them. Then click Start Tagging.
You can verify the geotagging using a free online service like Pic2Map. Note that Pic2Map is limited to only 40 images.
Reconstruction
We use Pix4D for 3D reconstruction.
Camera-IMU Sync Example (VIO)
In this example, we will go over the basics of synchronising IMU measurements with visual data to build a stereo Visual-Inertial Navigation System (VINS). To be clear, the idea here isn't to take an IMU measurement exactly at the same time as we take a picture but rather to correctly time stamp our images so as to provide accurate data to our VIO algorithm.
The autopilot and companion have different clock bases (boot-time for the autopilot and UNIX epoch for companion), so instead of skewing either clock, we directly observe the time offset between the clocks. This offset is added or subtracted from the timestamps in the MAVLink messages (e.g HIGHRES_IMU) in the cross-middleware translator component (e.g Mavros on the companion and mavlink_receiver
in PX4). The actual synchronisation algorithm is a modified version of the Network Time Protocol (NTP) algorithm and uses an exponential moving average to smooth the tracked time offset. This synchronisation is done automatically if Mavros is used with a high-bandwidth onboard link (MAVLink mode onboard
).
For acquiring synchronised image frames and inertial measurements, we connect the trigger inputs of the two cameras to a GPIO pin on the autopilot. The timestamp of the inertial measurement from start of exposure and a image sequence number is recorded and sent to the companion computer (CAMERA_TRIGGER message), which buffers these packets and the image frames acquired from the camera. They are matched based on the sequence number (first image frame is sequence 0), the images timestamped (with the timestamp from the CAMERA_TRIGGER
message) and then published.
The following diagram illustrates the sequence of events which must happen in order to correctly timestamp our images.
Step 1
First, set the TRIG_MODE
to 1 to make the driver wait for the start command andreboot your FCU to obtain the remaining parameters.
Step 2
For the purposes of this example we will be configuring the trigger to operatein conjunction with a Point Grey Firefly MV camera running at 30 FPS.
TRIG_INTERVAL
: 33.33 msTRIG_POLARITY
: 0 (active low)TRIG_ACT_TIME
: 0.5 ms. The manual specifies it only has to be a minimum of 1 microsecond.TRIG_MODE
: 1, because we want our camera driver to be ready to receive images before starting to trigger. This is essential to properly process sequence numbers.TRIG_PINS
: 56, Leave default.
Step 3
Wire up your cameras to your AUX port by connecting the ground and signal pins to the appropriate place.
Step 4
You will have to modify your driver to follow the sequence diagram above. Public reference implementations for IDS Imaging UEye cameras and for IEEE1394 compliant cameras are available.
PX4 can be built on the console or in an IDE, for both simulated and hardware targets.
Downloading PX4 Source Code
The PX4 source code is stored on Github in the PX4/Firmware repository. We recommend that you fork this repository (creating a copy associated with your own Github account), and then clone the source to your local computer.
Forking the repository allows you to better manage your custom code. Later on you will be able to use git to share changes with the main project.
The steps to fork and clone the project source code are:
- Sign up to Github.
Go to the Firmware repository and click the Fork button near the upper right corner.This will create and open the forked repository.
Copy the repository URL for your Firmware repository fork. The easiest way to do this is to click the Clone or download button and then copy the URL:
- Open a command prompt/terminal on your computer
- On OS X, hit ⌘-space and search for 'terminal'.
- On Ubuntu, click the launch bar and search for 'terminal'.
- On Windows, find the PX4 folder in the start menu and click on 'PX4 Console'.
- Clone the repository fork using the copied URL. This will look something like:Windows users refer to the Github help. You can use a git command line client as above or instead perform the same actions with the Github for Windows app.
This will copy most of PX4 onto your computer (the rest of the code is automatically fetched from other git submodules when you build PX4).
If you're just experimenting (and don't want to make any sort of permanent changes) you can simply clone the main Firmware repository as shown:
First Build (Using the jMAVSim Simulator)
For the first build we'll build for a simulated target using a console environment. This allows us to validate the system setup before moving on to real hardware and an IDE.
Navigate into the Firmware directory and start jMAVSim using the following command:
This will bring up the PX4 console below:
The drone can be flown by typing:
The drone can be landed by typing commander land
and the whole simulation can be stopped by doing CTRL+C (or by entering shutdown
).
The simulation setup is documented in full detail here: jMAVSim Simulation.
Flying the simulation with the ground control station is closer to the real operation of the vehicle. Click on a location in the map while the vehicle is flying (takeoff flight mode) and enable the slider. This will reposition the vehicle.
NuttX / Pixhawk Based Boards
Building
To build for NuttX- or Pixhawk- based boards, navigate into the Firmware directory and then call make
with the build target for your board.
In the example below the first part of the build target px4fmu-v2
is the autopilot hardware version and default
is the configuration name (in this case the 'default' configuration). All PX4 build targets follow this logic).
For example, to build for Pixhawk 1 you would use the following command:
A successful run will end with this output:
The following list shows the build commands for common boards:
- Pixhawk 1:
make px4fmu-v2_default
- HKPilot32:
make px4fmu-v2_default
- Pixfalcon:
make px4fmu-v2_default
- Dropix:
make px4fmu-v2_default
- mRo Pixhawk:
make px4fmu-v3_default
(supports 2MB Flash) - mRo X-2.1:
make auav-x21_default
- Pixhawk 2:
make px4fmu-v3_default
- Pixracer:
make px4fmu-v4_default
- MindPX/MindRacer:
make mindpx-v2_default
- Pixhawk Mini:
make px4fmu-v3_default
- Pixhawk 3 Pro:
make px4fmu-v4pro_default
- Crazyflie 2.0:
make crazyflie_default
- Intel® Aero Ready to Fly Drone:
make aerofc-v1_default
- Pixhawk 4:
make px4fmu-v5_default
- AUAV-X2 (Discontinued):
make px4fmu-v2_default
Uploading Firmware (Flashing the board)
Append upload
to the make commands to upload the compiled binary to the autopilot hardware via USB. For example
A successful run will end with this output:
Other Boards
The following boards have more complicated build and/or deployment instructions.
Raspberry Pi 2/3 Boards
The command below builds the target for Raspberry Pi 2/3 Navio2.
Cross-compiler Build
The 'px4' executable file is in the directory build/posix_rpi_cross/.Make sure you can connect to your RPi over ssh, see instructions how to access your RPi.
Then set the IP (or hostname) of your RPi using:
And upload it with:
Then, connect over ssh and run it with (as root):
Native Build
If you're building directly on the Pi, you will want the native build target (posix_rpi_native).
The 'px4' executable file is in the directory build/posix_rpi_native/.Run it directly with:
A successful build followed by executing px4 will give you something like this:
Autostart
To autostart px4, add the following to the file /etc/rc.local (adjust itaccordingly if you use native build), right before the exit 0
line:
Parrot Bebop
Support for the Parrot Bebop is at an early stage and should be used very carefully.
Build
Turn on your Bebop and connect your host machine with the Bebop's wifi. Then, press the power buttonfour times to enable ADB and to start the telnet daemon.
This will upload the PX4 mainapp into /usr/bin and create the file /home/root/parameters if not alreadypresent. In addition, we need the Bebop's mixer file and the px4.config. Currently, both files haveto be copied manually using the following commands.
Run
Connect to the Bebop's wifi and press the power button four times. Next,connect with the Bebop via telnet or adb shell and run the commands bellow.
Download Px4 Flow (com16) Drivers
Kill the Bebop's proprietary driver with
and start the PX4 mainapp with:
In order to fly the Bebop, connect a joystick device with your host machine and start QGroundControl. Both,the Bebop and the joystick should be recognized. Follow the instructions to calibrate the sensorsand setup your joystick device.
Autostart
To auto-start PX4 on the Bebop at boot, modify the init script /etc/init.d/rcS_mode_default
. Comment the following line:
Replace it with:
Enable adb server by pressing the power button 4 times and connect to adb server as described before:
Re-mount the system partition as writeable:
In order to avoid editing the file manually, you can use this one : https://gist.github.com/mhkabir/b0433f0651f006e3c7ac4e1cbd83f1e8
Save the original one and push this one to the Bebop
Sync and reboot:
OcPoC-Zynq Mini
Build instructions for the OcPoC-Zynq Mini are covered in:
- Aerotenna OcPoC-Zynq Mini Flight Controller > Building PX4 for OcPoC-Zynq (PX4 User Guide)
QuRT / Snapdragon Based Boards
This section shows how to build for the Qualcomm Snapdragon Flight.
Build
If you use the Qualcomm ESC board (UART-based), then please follow their instructions here. If you use normal PWM-based ESCs boards, then you may continue to follow the instructions on this page.
The commands below build the targets for the Linux and the DSP side. Both executables communicate via muORB.
To load the SW on the device, connect via USB cable and make sure the device is booted. Run this in a new terminal window:
Go back to previous terminal and upload:
Note that this will also copy (and overwrite) the two config files mainapp.config and px4.config to the device. Those files are stored under /usr/share/data/adsp/px4.config and /home/linaro/mainapp.config respectively if you want to edit the startup scripts directly on your vehicle.
The mixer currently needs to be copied manually:
Run
Run the DSP debug monitor:
Note: alternatively, especially on Mac, you can also use nano-dm.
Go back to ADB shell and run px4:
Note that the px4 will stop as soon as you disconnect the USB cable (or if you ssh session is disconnected). To fly, you should make the px4 auto-start after boot.
Autostart
To run the px4 as soon as the Snapdragon has booted, you can add the startup to rc.local
:
Either edit the file /etc/rc.local
directly on the Snapdragon:
Or copy the file to your computer, edit it locally, and copy it back:
For the auto-start, add the following line before exit 0
:
Make sure that the rc.local
is executable:
Then reboot the Snapdragon:
Compiling in a Graphical IDE
The PX4 system supports Qt Creator, Eclipse and Sublime Text. Qt Creator is the most user-friendly variant and hence the only officially supported IDE. Unless an expert in Eclipse or Sublime, their use is discouraged. Hardcore users can find an Eclipse project and a Sublime project in the source tree.
Qt Creator Functionality
Qt creator offers clickable symbols, auto-completion of the complete codebase and building and flashing firmware.
Qt Creator on Linux
Before starting Qt Creator, the project file needs to be created:
Then load the CMakeLists.txt in the root firmware folder via File -> Open File or Project -> Select the CMakeLists.txt file.
After loading, the 'play' button can be configured to run the project by selecting 'custom executable' in the run target configuration and entering 'make' as executable and 'upload' as argument.
Qt Creator on Windows
Qt Creator on Mac OS
Before starting Qt Creator, the project file needs to be created:
That's it! Start Qt Creator, then complete the steps in the video below to set up the project to build.
