UAV Systems Engineering · M6-L4 · Hands-on lab (runs on your machine)
Connect ROS 2 with PX4
The bridge lab: get PX4 topics into ROS 2 and verify rate, content and QoS.
What you will do
You will connect a running PX4 SITL to ROS 2 through the Micro XRCE-DDS Agent and read /fmu/out/vehicle_odometry and /fmu/out/vehicle_status. The two classic mistakes (version mismatch between px4_msgs and firmware, and a QoS mismatch) are part of the exercise.
Before you start
- Lab “Run PX4 SITL” completed and the PX4 tag you used recorded.
- ROS 2 installed on a supported release for your Ubuntu version (follow the ROS 2 installation guide), plus colcon.
- Lessons M6-T8 and M6-T9.
Steps
- Install the Micro XRCE-DDS Agent following the PX4 ROS 2 user guide (from source or a package) and confirm
MicroXRCEAgentruns. - Create a ROS 2 workspace and clone
px4_msgsat the branch or tag matching your PX4 version intosrc/; build withcolcon buildand sourceinstall/setup.bash. - Start PX4 SITL, then the agent:
MicroXRCEAgent udp4 -p 8888. Watch the agent log for the client connecting. - In a sourced terminal run
ros2 topic list | grep fmu; thenros2 topic hz /fmu/out/vehicle_odometryandros2 topic echo /fmu/out/vehicle_status --once. - Run the bridge health check script from lesson M6-T9 and record the rate and the NED .
# terminal 1: PX4 SITL (see the SITL lab)
# terminal 2:
MicroXRCEAgent udp4 -p 8888
# terminal 3 (after sourcing ROS 2 and the px4_msgs workspace):
ros2 topic list | grep fmu
ros2 topic hz /fmu/out/vehicle_odometry
ros2 topic info -v /fmu/out/vehicle_odometryBreak it on purpose
- Subscribe from a node using reliable QoS and see that nothing arrives; fix it with the QoS profile of lesson M6-T9.
- Run the agent on a different ROS domain ID from your node and note the symptom.
- Build px4_msgs from a different tag than the firmware and see what happens to the messages.
How to know it worked
/fmu/out/…topics are listed and publish at a steady rate.- You can state the rate of vehicle_odometry and why the sign of is negative while flying.
- You reproduced and fixed the QoS mismatch.
If it does not work
| Symptom | Likely cause | What to check |
|---|---|---|
| No /fmu topics | Agent not running, wrong port, or client not connected | Check the agent log and that PX4 is running; in SITL the client uses UDP 8888 |
| Topics but no data | QoS or message version mismatch | Use best-effort QoS; rebuild px4_msgs from the matching tag |
| colcon build fails | Missing dependencies or wrong ROS distro sourced | Install the dependencies the PX4 guide lists; source the right ROS 2 distribution |
References
Record your progress
Saved in this browser. This lab runs on your own machine, so the site cannot check it for you.