Skip to content

PX4 Camera Architecture/Integration

This topic provides a brief overview of how PX4 camera support is implemented.

INFO

See Camera for information about using cameras.

Overview

PX4 integrates with three types of cameras:

All of these cameras need to respond to MAVLink commands received over MAVLink or found in missions (the specific protocol depends on the camera).

The broad architecture used is described below.

PX4 does not have specific handling for MAVLink cameras that support the Camera Protocol v2, other than re-emitting camera items in missions as commands

Ground stations are expected to communicate with these cameras directly in order to send commands. PX4 must be configured to route MAVLink traffic between the camera and ground stations if needed.

INFO

The camera_trigger, camera_capture and camera_feedback modules are not used with this camera.

FC-connected Cameras

Cameras attached to flight controller outputs need PX4 to activate the outputs to trigger the camera, and may need PX4 to detect when a camera capture pin has been triggered by the camera hotshoe (in order to improve the logged camera-capture time).

This work is handled by three PX4 components: camera_trigger driver, camera_capture driver, camera-feedback module.

camera_trigger subscribes to the VehicleCommand topic and monitors for updates to its supported commands. Thes updates occur when either a command is received via MAVLink or when a camera item is reached in a mission.

The commands enable and disable triggering, and configure triggering at time and distance intervals. The driver tracks these intervals, and when needed triggers the outputs. The driver publishes a CameraTrigger topic (with feedback field set to false) that causes a CAMERA_TRIGGER MAVLink message to be emitted.

The camera_capture driver, if enabled, monitors the camera capture pin and on triggering publishes a CameraTrigger topic (with feedback field set to true) which also causes a CAMERA_TRIGGER MAVLink message to be emitted.

The camera_feedback module monitors for updates to the CameraTrigger topic, and publishes a CameraCapture topic for CameraTrigger updates from either camera_trigger or camera_capture. The information that is used depends on whether the camera capture pin is enabled and the value is of the CameraTrigger.feedback field. This CameraCapture topic is logged, and can be used to get the time of the capture.

MAVLink cameras that support the older Camera Protocol v1 are integrated in much the same way as FC-connected cameras.

camera_trigger subscribes to the VehicleCommand topic and monitors for updates in the commands it supports. This happens when either a command is received via MAVLink or when a camera item is found in a missions.

The commands enable and disable triggering, and configure triggering at time and distance intervals. The driver tracks these intervals, but with the "MAVLink backend" does not need to actually trigger any outputs (since the commands are forwarded to the camera). When the camera would trigger the driver publishes a CameraTrigger topic (with feedback field set to false) that causes a CAMERA_TRIGGER MAVLink message to be emitted. The camera_feedback module should then log a corresponding CameraCapture topic.

Camera Commands in Missions

PX4 re-emits camera items found in missions as MAVLink commands for all supported Camera Protocol v2 and Camera Protocol v1 commands. The system id of the emitted commands is the same as the ID of the autopilot. The component id of the commands can vary, but these are usually sent to either MAV_COMP_ID_CAMERA (100) or MAV_COMP_ID_ALL (see the individual camera documents for what ID is used in each case).

The commands are emitted irrespective of whether or not there is a connected camera of any type, provided there is a MAVLink channel to emit to.

INFO

More generally PX4 re-emits all mission commands that may be consumed by external MAVLink components, such as gimbals. Commands for waypoints and conditional behaviour are not emitted.

The sections below highlight interesting parts of the codebase

Commands supported in missions

Commands supported in missions, including camera commands, are shown in these methods:

Flow for re-emitting camera commands found in missions

The MAVLink streaming code monitors for changes to the VehicleCommand topic and publishes them over MAVLink. The MAVLink command is sent irrespective of whether the camera is a MAVLink camera, or connected to the flight controller.

The camera_trigger driver, if enabled, also monitors for changes to the VehicleCommand. If it is configured with a backend for a camera connected to the flight controller outputs, it will trigger those outputs appropriately.

Logging

CameraCapture topics are logged when there is a CameraTrigger update. The logged topic will depend on whether or not the camera capture pin is enabled.

Note that camera capture events are not logged when using the MAVLink cameras that support Camera Protocol v2, because the corresponding trigger events are not generated within PX4.

See Also