Documentation for using PX4 in the SWARM Developer System

PX4 AutoPilot Integration

To support real world systems, the SWARM Developer System enables the use of the PX4 firmware stack in the Simulation In the Loop (SITL) configuration. To achieve this, we have fully integrated PX4 into the automated process workflow and provided common tools such as MavROS integration in Python and C++, a custom Python-based MavServer for executing Offboard trajectories and provided integration for Ground Controls.

This works is just the beginning of our integration with popular, 3rd Party autopilots. In the future, we will have a fully customizable autopilot integration stack, allowing you to easily integrate your custom firmware in a realistic set of choices.

Currently Supported Versions

  • v1.13.X - Currently tested with v1.13.2
  • v1.12.X - Currently tested with v1.12.2
  • v1.11.X - Experimental support with some degradation of performance

Using PX4

To get started using PX4, you have 2 options:

  1. Utilize the built-in PX4 version
  2. Run your own version of PX4 (Local Only!)

Built-In PX4

The built-in version of PX4 is capable of running a single or multiple set of PX4-based agents, which are controllable via the SWARM Firmware system or ROS 1. Each agent is provided it's own ROS node with appropriate topic support.

To utilize the local PX4 version, you only need to edit your Simulation Settings section for the selected agent, changing the AutoPilot field in the agent information section to PX4 from SWARM. Below is an example:

                    ...
                    "Agents": {
                        "Drone1": {
                            "Vehicle": "Multirotor",
                            "AutoPilot": "PX4",
                    ...    
                
                    

Using A Local Version

If you want to use your own version of PX4, you will need to make a few modifications to the default SITL system.

To utilize the local PX4 version, you need to edit your Simulation Settings section for the selected agent, changing the AutoPilot field in the agent information section to PX4 from SWARM. You will also need to add an option to the VehicleOptions section that says "UseLocalPX4" and set it to true. Below is an example:

                    ...
                    "Agents": {
                        "Drone1": {
                            "Vehicle": "Multirotor",
                            "VehicleOptions": {
                                "UseLocalPX4": true
                            },
                            "AutoPilot": "PX4",
                    ...    
                
                    

Next, you will need to edit your PX4 so that a new set of offboard ports are available. This is because the SWARM system connects over the traditional UDP-based port 14540. We will add a new set of ports on 14530.

First, go to your PX4 repo and open the file at: PX4-Autopilot/ROMFS/px4fmu_common/init.d-posix/px40-rc.mavlink. In this file, you will add a new set of ports, mapping them to the range of 14530. See below for an example:

#!/bin/sh
# shellcheck disable=SC2154

udp_offboard_port_local=$((14580+px4_instance))
udp_offboard_port_local_2=$((14590+px4_instance))
udp_offboard_port_remote=$((14540+px4_instance))
udp_offboard_port_remote_2=$((14530+px4_instance))
[ $px4_instance -gt 9 ] && udp_offboard_port_remote=14549 # use the same ports for more than 10 instances to avoid port overlaps
udp_onboard_payload_port_local=$((14280+px4_instance))
udp_onboard_payload_port_remote=$((14030+px4_instance))
udp_onboard_gimbal_port_local=$((13030+px4_instance))
udp_onboard_gimbal_port_remote=$((13280+px4_instance))
udp_gcs_port_local=$((18570+px4_instance))

# GCS link
mavlink start -x -u $udp_gcs_port_local -r 4000000 -f
mavlink stream -r 50 -s POSITION_TARGET_LOCAL_NED -u $udp_gcs_port_local
mavlink stream -r 50 -s LOCAL_POSITION_NED -u $udp_gcs_port_local
mavlink stream -r 50 -s GLOBAL_POSITION_INT -u $udp_gcs_port_local
mavlink stream -r 50 -s ATTITUDE -u $udp_gcs_port_local
mavlink stream -r 50 -s ATTITUDE_QUATERNION -u $udp_gcs_port_local
mavlink stream -r 50 -s ATTITUDE_TARGET -u $udp_gcs_port_local
mavlink stream -r 50 -s SERVO_OUTPUT_RAW_0 -u $udp_gcs_port_local
mavlink stream -r 20 -s RC_CHANNELS -u $udp_gcs_port_local
mavlink stream -r 10 -s OPTICAL_FLOW_RAD -u $udp_gcs_port_local

# API/Offboard link
mavlink start -x -u $udp_offboard_port_local -r 4000000 -f -m onboard -o $udp_offboard_port_remote
mavlink start -x -u $udp_offboard_port_local_2 -r 4000000 -f -m onboard -o $udp_offboard_port_remote_2

# Onboard link to camera
mavlink start -x -u $udp_onboard_payload_port_local -r 4000 -f -m onboard -o $udp_onboard_payload_port_remote

# Onboard link to gimbal
mavlink start -x -u $udp_onboard_gimbal_port_local -r 400000 -m gimbal -o $udp_onboard_gimbal_port_remote

                    

Notice that we add the additional offboard port in the same way as the original one. This allows you to utilize multiple PX4 aircraft simultaneously. All other ports and communication will be the same.

Running A Local Version

To run the local version of PX4, you will need to do the following:

  • Start the PX4 SITL agent with make px4_sitl none_iris
  • Start the SWARM Client with python3 main.py --map-name SWARMHome
  • Once it has connected, run the rest of your setup (MavROS, ROS Nodes, etc.)

Tags: