Files
Nuno Marques 288b114841 feat(uxrce_dds_client): bridge out-of-tree uORB messages over uXRCE-DDS (#29782)
* feat(uxrce_dds_client): bridge the topics of out-of-tree messages

Out-of-tree uORB messages build into PX4 like any other, but the
bridge reads only dds_topics.yaml, so bridging one means editing that
file and carrying the change through every PX4 update.

When $EXTERNAL_MODULES_LOCATION/msg/dds_topics.yaml exists, the build
passes it to the generator after dds_topics.yaml, and the generator
appends each file's lists to those before it. A topic declared twice
in the same list stops the build, since it would be bridged twice.
A single file, as Zenoh's build passes, yields its lists unchanged.

Assisted-by: Claude-Code:claude-opus-5-5

* test(uxrce_dds_client): test the topic generator in the Python checks

The generator runs only inside a firmware build, so a change that
breaks joining topic files, or the check for repeated topics, would
first show up as a broken build. The tests run it on its own: a second
file appends its topics to each list, lists split across files give
the same header as one file, files without topics add nothing, and a
repeated topic stops it. The Python checks job installs empy for the
generator, in the range PX4's requirements.txt gives.

Assisted-by: Claude-Code:claude-opus-5-5

* feat(scripts): copy out-of-tree messages into px4_msgs

ROS 2 needs every bridged message in px4_msgs, and copy_to_ros_ws.sh
copies only PX4's own. An optional second argument, the external
modules location, adds the messages of its msg directory, if it has
any. A message with the name of a PX4 message would replace PX4's
definition in px4_msgs, so the script refuses it before copying
anything.

A test in the Python checks runs the script on throwaway workspaces:
PX4's messages alone, a location's messages added, a location without
messages, and the refusals of a PX4 message name and of a location
without a msg directory.

Assisted-by: Claude-Code:claude-opus-5-5

* docs(uxrce_dds): document bridging out-of-tree messages

The uXRCE-DDS page covers dds_topics.yaml but not the topics of
out-of-tree messages. Describe their topics file and the copy into
px4_msgs there, and point to it from the External Modules page.

Assisted-by: Claude-Code:claude-opus-5-5
2026-11-22 09:04:15 +00:00

3.3 KiB

External Modules (Out-of-Tree)

External modules provide a convenient mechanism for developers to manage/group proprietary modules that they want add to (or update in) PX4 firmware. External modules can use the same includes as internal modules and can interact with internal modules via uORB.

This topic explains how to add an external ("out of tree") module to the PX4 build.

:::tip We encourage you to contribute your changes into PX4, where possible! :::

Usage

To create an external module:

  • Create an external directory folder for grouping the external modules:

    • This can be located anywhere outside of the PX4-Autopilot tree.
    • It must have the same structure as PX4-Autopilot (i.e. it must contain a directory called src).
    • Later we refer to this directory using EXTERNAL_MODULES_LOCATION.
  • Copy an existing module (e.g. examples/px4_simple_app) to the external directory, or directly create a new module.

  • Rename the module (including MODULE in CMakeLists.txt) or remove it from the existing PX4-Autopilot cmake build config. This is to avoid conflicts with internal modules.

  • Add a file CMakeLists.txt in the external directory with content:

    set(config_module_list_external
        modules/<new_module>
        PARENT_SCOPE
        )
    
  • Add a line EXTERNAL to the modules/<new_module>/CMakeLists.txt within px4_add_module(), for example like this:

    px4_add_module(
    	MODULE modules__test_app
    	MAIN test_app
    	STACK_MAIN 2000
    	SRCS
    		px4_simple_app.c
    	DEPENDS
    		platforms__common
    	EXTERNAL
    	)
    

Out-of-Tree uORB Message Definitions

uORB messages can also be defined out-of-tree. For this, the $EXTERNAL_MODULES_LOCATION/msg folder must exist.

  • Place all new message definitions within the $EXTERNAL_MODULES_LOCATION/msg directory. The format of these new out-of-tree message definitions are the same as for any other uORB message definition.

  • Add a file $EXTERNAL_MODULES_LOCATION/msg/CMakeLists.txt with content:

    set(config_msg_list_external
        <message1>.msg
        <message2>.msg
        <message3>.msg
        PARENT_SCOPE
        )
    

    where <message#>.msg is the name of the uORB message definition file to be processed and used for uORB message generation.

The out-of-tree uORB messages will be generated in the same locations as the normal uORB messages. The uORB topic headers are generated in <build_dir>/uORB/topics/, and the message source files are generated in <build_dir>/msg/topics_sources/.

The new uORB messages can be used like any other uORB message as described here. To bridge them to ROS 2, see uXRCE-DDS: Out-of-Tree Messages.

:::warning The out-of-tree uORB message definitions cannot have the same name as any of the normal uORB messages. :::

Building External Modules and uORB Messages

Execute make px4_sitl EXTERNAL_MODULES_LOCATION=<path>.

Any other build target can be used, but the build directory must not yet exist. If it already exists, you can also just set the cmake variable in the build folder.

For subsequent incremental builds EXTERNAL_MODULES_LOCATION does not need to be specified.