Skip to content

ROS 2

ROS 2 is a powerful general purpose robotics library that can be used with the PX4 Autopilot to create powerful drone applications.

Tip

The PX4 development team highly recommend that you use/migrate to this version of ROS!

This is the newest version of ROS (Robot Operating System). It significantly improves on ROS "1", and in particular allows a much deeper and lower-latency integration with PX4.

ROS benefits from an active ecosystem of developers solving common robotics problems, and access to other software libraries written for Linux. It can be used, for example, for computer vision solutions.

ROS 2 enables a very deep integration with PX4, to the extent that you can create flight modes in ROS 2 that are indistinguisable from internal PX4 modes, and directly read from and write to internal uORB topics at high rate. It is recommended (in particular) for control and communication from a companion computer where low latency is important, when leveraging existing libraries from Linux, or when writing new high level flight modes.

Communication between ROS 2 and PX4 uses middleware that implements the XRCE-DDS protocol. This middleware exposes PX4 uORB messages as ROS 2 messages and types, effectively allowing direct access to PX4 from ROS 2 workflows and nodes. The middleware uses uORB message definitions to generate code to serialise and deserialise the messages heading in and out of PX4. These same message definitions are used in ROS 2 applications to allow the messages to be interpreted.

INFO

ROS 2 can also connect with PX4 using MAVROS instead of XRCE-DDS. This option is supported by the MAVROS project (it is not documented here).

To use the ROS 2 over XRCE-DDS effectively, you must (at time of writing) have a reasonable understanding of the PX4 internal architecture and conventions, which differ from those used by ROS. In the near term future we plan to provide ROS 2 APIs to abstract PX4 conventions, along with examples demonstrating their use.

Topics

The main topics in this section are:

  • ROS 2 User Guide: A PX4-centric overview of ROS 2, covering installation, setup, and how to build ROS 2 applications that communicate with PX4.
  • ROS 2 Offboard Control Example: A C++ tutorial examples showing how to do position control in offboard mode from a ROS 2 node.
  • ROS 2 Multi Vehicle Simulation: Instructions for connecting to multipole PX4 simulations via single ROS 2 agent.
  • PX4 ROS 2 Interface Library: A C++ library that simplies interacting with PX4 from ROS 2. Can be used to create and register flight modes wrtten using ROS2 and send position estimates from ROS2 applications such as a VIO system.

Further Information