PX4 Integration
Learn how to integrate GRID with PX4
Overview
As PX4 is a popular open-source flight control software, GRID has been designed with PX4 integration in mind to make the jump from simulation to real flight as seamless as possible. This page will cover the basic clients and communication structure used to deploy real world drones from GRID.
MavLinkClient
To facilitate communication from GRID to a PX4-enabled drone, we have created a MavLinkClient
class.
This client handles low-level communication via MavLink, the lightweight messaging protocol at the heart of PX4.
Features of the MavLinkClient
include:
- It enables fundamental message exchange between GRID and drone with acknowledgment and error handling while also providing basic functionality such as position and velocity setpoint modification.
- With the breadth of PX4 development, we support the common MavLink message set out of the box but constructed the client with extensibility in mind. Any custom message types are parsed automatically and can be handled by the user as desired.
- The client handles RTSP video streams from the drone to allow video/image ingestion into GRID.
The MavLinkClient
is typically used as part of a higher level class to ease the deployment from the AirGen simulation environment while including any formfactor-specific functionality.
An example of this is the ModalAIDrone
which uses the MavLinkClient
to replicates the functionality of AirGenDrone
for a ModalAI Starling 2 Max.
MavLink Connection Configuration
To configure the MavLinkClient
, you need to provide the following connection parameters to match your drone’s setup:
ground_control_station_ip
: IP address of the GRID-connected computer from which commands are to be sent to the drone, referred to as the ground control station (GCS) in MavLink terminologymavlink_port
: port number for mavlink connectioncommunication_protocol
: communication protocol to use, i.e. ‘udp’, ‘tcp’vehicle_ip
: IP address of the drone where the RTSP video streams can be foundcamera_streams
: dictionary of camera streams to be used, where the key is the stream name and the value is a dictionary containing the port and path for the RTSP streamarm_enable
: whether to enable arming the droneknown_messages
: list of known MavLink messages which should be expected by the client. This is used to filter out unknown messages and can be useful for debugging.
The exact networking configuration of your drone is manufacturer-specific. Please refer to your drone’s documentation for the correct networking information.
Utilities
In addition to establishing a connection and setting up continuous communication, the MavLinkClient
provides several utility functions to simplify common tasks and ensure robust drone operations:
-
Robust Command Sending:
Theattempt_command
method sends arbitrary MavLink commands with built-in retry logic, ensuring that critical commands (such as arming, setting offboard control, or custom message rates) are reliably executed. -
Message Filtering and Handling:
Incoming messages are processed and filtered based on a predefined list of known message types. This helps both to handle expected messages (likeHEARTBEAT
,LOCAL_POSITION_NED
, andCOMMAND_ACK
) and to flag any unexpected communications, aiding in debugging and system monitoring. -
Heartbeat and Component Discovery:
Before enabling further operations, the client waits for a heartbeat from the drone. It then proceeds to automatically discover system components (e.g., the main drone and any associated camera module), dynamically configuring targets for subsequent commands. -
Video Stream Management:
Integrated with aVideoStreamManager
, the client supports RTSP video streaming. Theget_single_frame
method, for example, captures a single image from a specified camera stream and converts it to a usable RGB format. -
Setpoint Maintenance:
A dedicated thread continually updates and transmits flight setpoints, providing smooth and consistent control during offboard operations. Theupdate_setpoint
utility further enables dynamic adjustment of key flight parameters on the fly.
Overall, these utilities ensure that the MavLinkClient
can not only handle low-level communication tasks but also provide higher-level operational robustness and flexibility for real-world drone integration with GRID.
For full details on the MavLinkClient
class, please refer to the MavLinkClient
API documentation.