Using a serial port
Reference : https://docs.px4.io/main/en/companion_computer/pixhawk_rpi.html
The ROS 2 guide and the uXRCE-DDS page cover options for setting up uXRCE-DDS and ROS. This tutorial uses ROS 2 “Humble” and covers the specific setup using the RDK X5 Module. Both guides are worth reading!
Pixhawk/PX4
Next, we TELEM2
set up ROS 2 instead of MAVLink. We do this by changing the parameters in QGroundControl. QGroundControl can be connected via USB or use TELEM1
the telemetry radio it is connected to.
The configuration steps are as follows:
- Connect your Pixhawk to your laptop using the USB cable and open QGroundControl if it is not already connected.
- Check/change the following parameters in QGroundControl:
markdown MAV_1_CONFIG = 0 (Disabled) UXRCE_DDS_CFG = 102 (TELEM2) SER_TEL2_BAUD = 921600
MAV_1_CONFIG=0 and UXRCE_DDS_CFG=102 are used to disable MAVLink on TELEM2 and enable the uXRCE-DDS client on TELEM2 respectively. rateSER_TEL2_BAUD
is used to set the data rate of the communication link. You can also use or
similarly configure the connection.TELEM1``MAV_1_CONFIG``MAV_0_CONFIG
information
You will need to restart the flight controller to apply any changes to these parameters. - Check that the uxrce_dds_client module is running. You can do this by running the following command in the QGroundControl MAVLink console:
markdown uxrce_dds_client status
information
If the client module is not running, you can start it manually in the MAVLink console:
uxrce_dds_client start -t serial -d /dev/ttyS4 -b 921600
Note that /dev/ttyS4
this is the PX4 port mapping for the USX10 Pixhawk 6X. For other flight controllers, please check the Serial Port Mapping section TELEM2
on their overview page .
ROS
The steps to set up ROS 2 and Micro XRCE-DDS Agent on the RDK X5 Module are as follows:
- Install ROS 2 Humble according to the official tutorial.
- Install git using the RDK X5 Module terminal:
markdown sudo apt install git
- Install the uXRCE_DDS agent:
markdown git clone https://github.com/eProsima/Micro-XRCE-DDS-Agent.git cd Micro-XRCE-DDS-Agent mkdir build cd build cmake .. make sudo make install sudo ldconfig /usr/local/lib/
See uXRCE-DDS > Micro XRCE-DDS Agent Installation for alternative methods of installing the agent. - Start the agent in the RDK X5 Module terminal:
markdown sudo MicroXRCEAgent serial --dev /dev/ttyS2 -b 921600
Note how we use the serial port we set up previously and the same baud rate as the PX4.
Now that both the agent and client are running, you should see activity in both the MAVLink console and the RDK X5 Module terminal. You can view the available topics on the RDK X5 Module using the following command:
source /opt/ros/humble/setup.bash
ros2 topic list
That’s it. Once you’re connected, refer to the ROS 2 Guide for more information on using PX4 with ROS 2.
Using Ethernet
PX4 v1.14
information
uXRCE-DDS replaces the Fast-RTPS Bridge used in PX4 v1.13. If you were previously using the Fast-RTPS Bridge, please follow the migration guide.
PX4 uses the uXRCE-DDS middleware, which allows uORB messages to be published and subscribed to on the companion computer , just like ROS 2 topics. This enables fast and reliable integration between PX4 and ROS 2, and makes it easier for ROS 2 applications to get vehicle information and send commands.
PX4 uses an XRCE-DDS implementation that leverages eProsima Micro’s XRCE -DDS.
The following guide describes the architecture and various options for setting up clients and proxies. It specifically covers the options that are most important to PX4 users.
Architecture
The uXRCE-DDS middleware consists of a client running on PX4 and a broker running on a companion computer, which exchange data bidirectionally over a serial or UDP link. The broker acts as a proxy for the client, enabling it to publish and subscribe to topics in the global DDS data space.
In order for a PX4 uORB topic to be shared over a DDS network, you need to run the uXRCE-DDS client on the PX4 and connect it to the microXRCE-DDS proxy running on the companion device.
The PX4 uxrce_dds_client publishes content to/from a defined set of uORB topics into the global DDS data space.
The eProsima micro XRCE-DDS_Agent_ runs on the companion computer and acts as a proxy for clients in the DDS/ROS 2 network.
The agent itself has no dependencies on client code and can be built and/or installed independently of PX4 or ROS.
Code that wants to subscribe/publish to PX4 does have a dependency on the client code; it needs uORB message definitions that match the ones used to create the PX4 uXRCE-DDS client so that it can interpret the messages.
Code
The PX4 uxrce_dds_client is generated at build time and included by default in the PX4 firmware. This agent does not depend on the client code. It can be built standalone, in a ROS 2 workspace, or installed as a snap package on Ubuntu.
When building PX4, the code generator compiles support for a subset of uORB topics in /src/modules/uxrce_dds_client/dds_topics.yaml into uxrce_dds_client using the uORB message definitions in the source tree ( PX4-Autopilot/msg ).
A PX4 master or release build automatically exports a set of uORB message definitions from the build to the associated branch in PX4/px4_msgs.
ROS 2 applications need to be built in a workspace that contains the same message definitions used to create the uXRCE-DDS client module in the PX4 firmware. You can add these message definitions to your ROS 2 workspace by cloning the interface package PX4/px4_msgs into your workspace and switching to the corresponding branch. Note that all message-related code generation is handled by ROS 2.
Micro XRCE-DDS Agent
The Micro XRCE-DDS Agent can be installed on a companion machine using a binary package, built and installed from source code, or built and run within a ROS 2 workspace. All of these methods will get all the dependencies needed to communicate with the client (such as FastCDR).
information
The official (and more complete) installation guide is Eprosima: micro XRCE-DDS Installation Guide. This section summarizes the options tested with PX4 during the creation of these documents.
warn
The version based on the PX4 Micro XRCE-DDS Client v2.x
is not compatible with the latest Agent version v3.x
.
Installing the standalone
On Ubuntu, you can build the Agent standalone version from source and install it using the following command:
git clone -b v2.4.2 https://github.com/eProsima/Micro-XRCE-DDS-Agent.git
cd Micro-XRCE-DDS-Agent
mkdir build
cd build
cmake ..
make
sudo make install
sudo ldconfig /usr/local/lib/
information
The corresponding topics in the official guide link to various build configuration options, but these have not been tested.
To start the proxy and set up a connection to the uXRCE-DDS client running on the emulator:
MicroXRCEAgent udp4 -p 8888
from Snap package
Install from the snap package on Ubuntu using the following command:
sudo snap install micro-xrce-dds-agent --edge
To start the agent, use the settings that connect to the uXRCE-DDS client running on the emulator (note that the command names are different when you build the agent locally):
micro-xrce-dds-agent udp4 -p 8888
information
At the time of writing, the stable version installed from snap can connect to PX4, but will fail when creating a theme. Using --edge
the development version obtained above works fine.
Building/
You can build and launch the agent within a ROS 2 workspace (or build it standalone and launch it from a workspace). You must have already installed ROS 2 as described in the ROS 2 User Guide > Installing ROS 2.
warn
This method will use existing ROS 2 versions of the Agent dependencies, such as fastcdr
and fastdds
. This greatly speeds up the build process, but requires that the Agent dependency versions match the ROS 2 version.
To build the agent in ROS:
- Create a workspace directory for the agent:
markdown mkdir -p ~/px4_ros_uxrce_dds_ws/src
- Clone the source code of eProsima Micro-XRCE-DDS-Agent to
/src
the directory (main
default clone branch):markdown cd ~/px4_ros_uxrce_dds_ws/src git clone -b v2.4.2 https://github.com/eProsima/Micro-XRCE-DDS-Agent.git
- Get the ROS 2 development environment and compile the workspace using the following commands
colcon
:
To run the Micro XRCE-DDS agent in a workspace:
- Provide the source
local_setup.bash
to make the executable available in the terminal (even ifsetup.bash
using a new terminal). - Start the agent with settings that connect to the uXRCE-DDS client running on the emulator:
markdown MicroXRCEAgent udp4 -p 8888
Start the broker and
Start
The agent is used to connect to the client over a specific channel, such as UDP or a serial connection. Channel settings are specified using command-line options when the agent is started. These settings are documented in the eProsima User Guide: Micro XRCE-DDS Agent > Agent CLI. Note that the agent supports multiple channel options, but PX4 only supports UDP and serial connections.
information
You should create one proxy instance for each channel you need to connect to.
For example, the PX4 emulator runs the uXRCE-DDS client over UDP on port 8888, so to connect to the emulator you can start the proxy with:
MicroXRCEAgent udp4 -p 8888
When using real hardware, the settings depend on the hardware, operating system, and channel. For example, if you are using an RPi UART0
serial port, you can use this command to connect (based on the information in Raspberry Pi Documentation > Configuring UARTs ):
sudo MicroXRCEAgent serial --dev /dev/AMA0 -b 921600
information
For more information on setting up communication channels, see Pixhawk+ Companion Settings > Serial Port Settings and its subdocuments.
Start the
All firmware and simulators include the uXRCE-DDS client module ( uxrce_dds_client ) by default. This module must be enabled with the appropriate settings for the channel you wish to use to communicate with the agent.
information
The emulator 8888
automatically starts a client on the localhost UDP port using the default uxrce-dds namespace.
Configuration can be done using the UXRCE-DDS parameters:
- UXRCE_DDS_CFG: Set the port to connect to, for example
TELEM2
,,Ethernet
orWifi
. - If using an Ethernet connection:
- UXRCE_DDS_PRT: Used to specify the proxy UDP listening port. The default value is
8888
. - UXRCE_DDS_AG_IP: Specifies the IP address of the proxy.
int32
Since PX4 does not support string parameters, the IP address must be provided in string format. The default2130706433
value is localhost127.0.0.1
. You can use Tools/convert_ip.py to convert between formats:- To get
int32
the IP version in decimal dot notation, use the following command:markdown python3 ./PX4-Autopilot/Tools/convert_ip.py <the IP address in decimal dot notation>
- To get the IP address in dot-decimal notation from the version
int32
:markdown python3 ./PX4-Autopilot/Tools/convert_ip.py -r <the IP address in int32 notation>
- To get
- UXRCE_DDS_PRT: Used to specify the proxy UDP listening port. The default value is
- If using a serial connection:
- SER_TEL2_BAUD, SER_URT6_BAUD (and so on): Use
_BAUD
the parameters associated with the serial port to set the baud rate. For example,SER_TEL2_BAUD
if you are connecting to a companion device, you would need to set this valueTELEM2
. For more information, see Serial Port Configuration.
- SER_TEL2_BAUD, SER_URT6_BAUD (and so on): Use
- Some setups may also require setting these parameters:
- UXRCE_DDS_KEY: uXRCE-DDS key. If you are using a multi-client single-agent configuration, each client should have a unique, non-zero key. This is especially important for multi-vehicle simulations, where all clients connect to the same agent via UDP. (See the official eprosima documentation.
uxr_init_session
) - UXRCE_DDS_DOM_ID: The DDS domain ID. This provides logical isolation between DDS networks and can be used to distinguish clients on different networks. By default, ROS 2 runs on ID 0.
- UXRCE_DDS_PTCFG: uXRCE-DDS participant configuration. It allows to restrict visibility of DDS topics to localhost only and use user-defined participant configuration files stored on the broker side.
- UXRCE_DDS_SYNCT: Bridge time synchronization enabled. The uXRCE-DDS client module can synchronize the timestamps of messages exchanged over the bridge. This is the default configuration. In some cases, such as during simulation, this feature may be disabled.
- UXRCE_DDS_KEY: uXRCE-DDS key. If you are using a multi-client single-agent configuration, each client should have a unique, non-zero key. This is especially important for multi-vehicle simulations, where all clients connect to the same agent via UDP. (See the official eprosima documentation.
information
Many ports already have default configurations. To use these ports, you must first disable the existing configurations:
TELEM1
ByTELEM2
default, they are set up to connect to the Ground Station (GCS) and companion computer via MAVLink. This can be disabled by setting MAV_0_CONFIG=0 or MAV_1_CONFIG=0 to zero. For more information, see MAVLink Peripherals.- Other ports can be configured similarly. See Serial Port Configuration.
After the settings are completed, you may need to restart PX4 for the parameters to take effect. These parameters will be retained after subsequent restarts.
You can also start uxrce_dds_client from the command line. This can be called as part of system startup or through the MAVLink Shell (or the system console). This method is useful when you need to set a custom client namespace, as no arguments are given for this. For example, the following command can be used to connect to a remote host via Ethernet 192.168.0.100:8888
and set the client namespace to /drone/
.
uxrce_dds_client start -t udp -p 8888 -h 192.168.0.100 -n drone
Option -p
or -h
used to bypass UXRCE_DDS_PRT
and UXRCE_DDS_AG_IP
.
Launching the
The simulator startup logic ( init.d-posix/rcS ) uses the client startup command for single-vehicle and multi-vehicle simulations, which sets the appropriate instance ID and DDS namespace. By default, the client is started on the localhost UDP port 8888
without any additional namespace.
Environment variables are provided to override certain UXRCE-DDS parameters. These variables allow users to create custom startup files for their simulations:
PX4_UXRCE_DDS_NS
: Use this to specify the topic namespace ).ROS_DOMAIN_ID
: Use this to replace UXRCE_DDS_DOM_ID.PX4_UXRCE_DDS_PORT
: Use it to replace UXRCE_DDS_PRT.
For example, the following command can be used to start a Gazebo simulation running the che client on the DDS domain 3
, port, and topic namespace .9999
drone
ROS_DOMAIN_ID=3 PX4_UXRCE_DDS_PORT=9999 PX4_UXRCE_DDS_NS=drone make px4_sitl gz_x500
Example
px4_ros_com
https://docs.px4.io/main/en/ros2/offboard_control.html https://github.com/PX4/px4_ros_com.git
uav_command_pub
px4-ros2-interface-lib
https://docs.px4.io/main/en/ros2/px4_ros2_interface_lib.html https://github.com/Auterion/px4-ros2-interface-lib
More
Please refer to the official PX4 documentation https://docs.px4.io/main/en/middleware/uxrce_dds.html
No responses yet