# Micro XRCE-DDS

[Micro XRCE-DDS](https://docs.px4.io/main/en/middleware/uxrce_dds.html) allows [uORB topics](https://docs.px4.io/main/en/middleware/uorb.html) on the FMU to be published in [ROS 2](https://docs.ros.org/en/rolling/index.html) in AuterionOS.

{% hint style="info" %}
Micro XRCE-DDS is supported in APX4 3.0 and later. It is enabled and configured by default.
{% endhint %}

{% hint style="info" %}
Setting up Micro XRCE-DDS on an existing Auterion-powered vehicle is only possible for the manufacturer of that vehicle.
{% endhint %}

The DDS bridge comprises two components:

1. The *Micro XRCE-DDS Agent*, which is installed and enabled by default in AuterionOS, and
2. The *Micro XRCE-DDS Client*, which must be enabled in the flight controller.

## Enabling the Micro XRCE-DDS Client

The PX4 module *Micro XRCE-DDS Client* is called `uxrce_dds_client` and is configured by a set of PX4 parameters:

<table><thead><tr><th width="221">PX4 Parameter</th><th>Value</th></tr></thead><tbody><tr><td><code>UXRCE_DDS_CFG</code></td><td>Ethernet</td></tr><tr><td><code>UXRCE_DDS_PRT</code></td><td><code>8888</code></td></tr><tr><td><code>UXRCE_DDS_AG_IP</code></td><td><p>The IPv4 address of the Skynode in <strong>int32</strong> format.</p><p>For example, the default parameter value <code>170461697</code> is equivalent to the IP address <code>10.41.10.1</code>.</p></td></tr></tbody></table>

Reboot the device after making these changes in order for them to apply.

After rebooting APX4, verify in the MAVLink Shell that the Micro XRCE-DDS Client is running and connected:

```sh
uxrce_dds_client status
```

```bash
nsh> uxrce_dds_client status
INFO  [uxrce_dds_client] Running, connected
INFO  [uxrce_dds_client] Using transport:     udp
INFO  [uxrce_dds_client] Agent IP:            10.41.10.1
INFO  [uxrce_dds_client] Agent port:          8888
INFO  [uxrce_dds_client] Custom participant:  yes
INFO  [uxrce_dds_client] Localhost only:      no
INFO  [uxrce_dds_client] Payload tx:          46079 B/s
INFO  [uxrce_dds_client] Payload rx:          11680 B/s
```

{% hint style="info" %}
A script is provided in APX4 to convert IPv4 addresses from decimal dot notation to `int32` format. The script is also available upstream: <https://github.com/PX4/PX4-Autopilot/blob/main/Tools/convert_ip.py>

```sh
python3 ./Tools/convert_ip.py A.B.C.D
```

{% endhint %}

{% hint style="info" %}
The FMU must have Ethernet enabled and an IPv4 address in the same subnet as the Skynode to use Micro XRCE-DDS.
{% endhint %}

## Adding or removing topics

The list of topics the FMU publishes and subscribes to using Micro XRCE-DDS is defined in [src/modules/uxrce\_dds\_client/dds\_topics.yaml](https://github.com/PX4/PX4-Autopilot/blob/main/src/modules/uxrce_dds_client/dds_topics.yaml).

The **dds\_topics.yaml** file has three sections:

1. `publications`: Topics published to ROS 2,
2. `subscriptions`: Topics subscribed to from ROS 2, and
3. `subscriptions_multi`: Topics subscribed to from ROS 2 for which a separate instance of the uORB topic is created for the incoming ROS 2 messages.

To add a topic to Micro XRCE-DDS, specify the topic name and message type under the appropriate section. For example, the following creates a publisher for the `vehicle_odometry` topic:

```yaml
publications:
  ...
  - topic: /fmu/out/vehicle_odometry
    type: px4_msgs::msg::VehicleOdometry
```

## Testing communication between APX4 and ROS 2 <a href="#testing-communication-between-px4-and-ros-2" id="testing-communication-between-px4-and-ros-2"></a>

To verify that your APX4 to ROS 2 communication is working and that you are receiving messages from the flight controller, run the following command in your Skynode's [SSH shell](https://docs.auterion.com/hardware-integration/auterionos-system-guide/connecting-to-skynode). You should see the frequency at which the messages are coming through.

```bash
ros_setup 
ros2 topic hz /fmu/out/vehicle_odometry
```
