PX4 Ethernet Setup
Last updated
Last updated
Ethernet connectivity provides a fast, reliable, and flexible communication alternative to using USB or other serial connections.
It can be used to connect to ground stations, companion computers, and other MAVLink systems. It is particularly recommended when connecting to systems that "natively" use Ethernet - for example IP radios.
This topic covers:
PX4 supports Ethernet connectivity on flight controllers (and later) that have an Ethernet port. It may also be supported on other boards.
Supported flight controllers include:
To connect systems over Ethernet you need to configure them to run on the same IP network, so that each system has a unique IP address and can find the other systems. This might be done using a DHCP server to allocate addresses, or by manually configuring the addresses of each system on the network.
There is no single "out of the box configuration" that we can provide that will necessarily work in your local network. Therefore as an example of the kind of configuration you might do, below we show how to set up the systems on an IP network with static addresses in the range 192.168.0.Xxx
, where PX4 has a statically allocated address 192.168.0.4
and the computer has address 192.168.0.1
. If you wanted to connect a companion computer or other system to the network you could use a similar approach to allocate a static address.
:::note There is nothing "special" about the network configuration (other than perhaps the tools used to modify the network settings); it works much the same as any home or business network. Which is to say that a knowledge of how IP networks work is highly desirable! :::
Network settings are defined in the configuration file /fs/microsd/net.cfg
on the SD card. This is a text file, that defines each setting on a new line as a name=value
pair. A configuration file might look like this:
Where the values are:
DEVICE
: Interface name. Default is eth0
.
BOOTPROTO
: Protocol for getting PX4 IP address. Valid values for proto are: dhcp
, static
, fallback
(use DHCP but fall back to static address after time, if that fails)
IPADDR
: Static IP address (used if BOOTPROTO is static
or fallback
)
NETMASK
: Network mask
ROUTER
: The address of the default route.
DNS
: The address of the DNS server.
To set the above "example" configuration using the QGroundControl:
Connect the flight controller to the computer with the USB cable.
Open QGroundcontrol > Analyze Tools > MAVLink Console
Enter commands "like" the ones below into the MAVLink Console (to write the values to the configuration file):
Once the network configuration has been set you can disconnect the USB cable.
Reboot the flight controller to apply the settings.
To setup the Ubuntu Computer:
In a terminal, create and open a netplan
configuration file: /etc/netplan/01-network-manager-all.yaml
Below we do this using the nano text editor.
Copy and paste the following configuration information into the file (note: the indentations are important!):
Save and exit the editor.
Apply the netplan configuration by entering the following command into the Ubuntu terminal.
The setup for a companion computer will depend on the companion computer's operating system.
A Linux operating system may support netplan
, in which case the instructions would be the same as above, but using a unique IP address.
The Ethernet port configuration sets the properties of the serial link (which is how PX4 views the Ethernet connection). This includes the set of MAVLink messages that are streamed, the data rate, the UDP ports that a remote system can connect listen to, etc.
PX4 configures the serial port to connect to a GCS via MAVLink, using the parameters shown below:
1000
Configure Ethernet port
1
Broadcast HEARTBEAT
messages
0
Send the "normal" set of MAVLink messages (i.e. the GCS set)
0
Disable software throttling of MAVLink traffic
100000
Maximum sending rate
14550
MAVLink Remote Port of 14550 (GCS)
14550
MAVLink Network Port of 14550 (GCS)
To connect QGroundControl to PX4 over Ethernet:
Connect the ground station computer and PX4 using an Ethernet cable.
Assuming that the values are set as described in the rest of this topic the setup will look like this:
QGroundControl should then connect if you select this link.
To setup MAVSDK-Python running on a companion computer:
For example, your code will connect to the PX4 using:
:::note MAVSDK can connect to the PX4 on port 14550
if you don't modify the PX4 Ethernet port configuration. However this is not recommended because the default configuration is optimised for communicating with a GCS (not a companion computer). :::
:::note Prerequisites:
You have followed the Ethernet network and port setup as discussed at the top of this page. :::
To set up ROS 2:
Connect your flight controller and companion computer via Ethernet.
If everything is setup correctly, the following output should be displayed in the terminal:
Tutorial showing how to connect Pixhawk 6X + Raspberry Pi on CM4 baseboard via wired Ethernet.
Blog dupliciates a lot of material from this topic.
PX4 uses the module to apply and update network settings.
Note that the above setup gives the flight controller an address on the Ethernet network. You also need to to use MAVLink.
If you're using Ubuntu for your ground station (or companion computer) then you can use to configure the network.
Below we show how you write a setup to the netplan configuration file "/etc/netplan/01-network-manager-all.yaml
", which would run on the same network as used by the PX4 setup above. Note that there are many more and instructions in the documentation.
:::note You must separately configure the PX4 IP address and other network settings (). :::
Normally a companion computer would use port 14540
(rather than 14550
) and stream the set of MAVLink messages specified in the Onboard
profile. You can configure this setup by changing and to 14540
and to 2
(Onboard). Note however that this will still work using the GCS profile.
For more information on MAVLink serial port configuration see
Assuming you have already so your ground station computer and PX4 run on the same network, and
so your ground station computer and PX4 run on the same network.
Start QGroundControl and (Application Settings > Comm Links) specifying the server address and port as the IP address and port assigned in PX4, respectively.
:::note should not be needed (the default are appropriate for a GCS). :::
so your companion computer and PX4 run on the same network.
Modify the to connect to a companion computer. You might change the parameters and to 14540
, and to 2
(Onboard).
Follow the instructions in to install and use MAVSDK.
You have a supported autopilot hardware running PX4 firmware that includes middleware. Note that PX4 v1.14 and later include the required module by default.
has been set up correctly on the companion computer.
, either manually or by customizing the system startup script. Note that you must use the IP address of the companion computer and the UDP port on which the agent is listening (the example configuration above sets the companion IP address to 192.168.0.1
, and the agent UDP port is set to 8888
in the next step).
. For example, enter the following command in a terminal to start the agent listening on UDP port 8888
.
Run a in a new terminal to confirm the connection is established:
(px4.io blog):