Skip to the content
FixTheRobot Explore Robotics / UAV / Module 6 / M6-L4

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.

  • UAV Software and Flight-Controller Integration
  • Implementation-specific
  • About 75 minutes

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

  1. Install the Micro XRCE-DDS Agent following the PX4 ROS 2 user guide (from source or a package) and confirm MicroXRCEAgent runs.
  2. Create a ROS 2 workspace and clone px4_msgs at the branch or tag matching your PX4 version into src/; build with colcon build and source install/setup.bash.
  3. Start PX4 SITL, then the agent: MicroXRCEAgent udp4 -p 8888. Watch the agent log for the client connecting.
  4. In a sourced terminal run ros2 topic list | grep fmu; then ros2 topic hz /fmu/out/vehicle_odometry and ros2 topic echo /fmu/out/vehicle_status --once.
  5. Run the bridge health check script from lesson M6-T9 and record the rate and the NED zz.
# 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_odometry
Agent and ROS 2 checks.

Break 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 zz is negative while flying.
  • You reproduced and fixed the QoS mismatch.

If it does not work

Troubleshooting
SymptomLikely causeWhat to check
No /fmu topicsAgent not running, wrong port, or client not connectedCheck the agent log and that PX4 is running; in SITL the client uses UDP 8888
Topics but no dataQoS or message version mismatchUse best-effort QoS; rebuild px4_msgs from the matching tag
colcon build failsMissing dependencies or wrong ROS distro sourcedInstall 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.