How to create a custom Fast RTPS Listener (like sensor_combiner)?

Hello! (First-time poster so please excuse any errors.) I have been following the PX4-ROS 2 Bridge tutorial and am able to get the Sanity Check and Offboard Control examples working with SITL simulation through jMAVSim.

However, I am stuck when it comes to generating a custom RTPS listener (similar to sensor_combined_listener.cpp). To illustrate this, let’s say I want to create a wind_listener.cpp to print the contents of Wind.msg:

Broadly, I am unsure of:

  • what files must be created (e.g., wind_listener.cpp,, and where (e.g., /px4_ros_com_ros2/src/px4_ros_com/src/examples/listeners or elsewhere),
  • what edits must be made (e.g., to which CMakeLists.txt),
  • what build process must be completed (e.g., build_ros2_workspace.bash)

I have tried several approaches (including fastrtpsgen -example x64Linux2.6gcc ../micrortps_agent/idl/sensor_combined_.idl) but I think I am missing something higher-level from the tutorial. Any advice is appreciated. Thank you!

I don’t have a ton of experience with ROS2 but this is what I can tell you.
First of all, I greatly recommend you to check this link to learn about writing publishers or subscribers in ROS2.

For your questions:

  • You can create wind_listerner.cpp file in the examples folder but you don’t have to.
    *You don’t have to make a launch file at first. It is generally used for launching multiple nodes at once.
  • You need to add your node to CMakeList as a custom_executable (examples are in that CMakeList)
  • If you have any new dependencies you need to add them to CMakeList and package.xml files.
  • I believe build_ros2_workspace.bash should be enough.

Thank you so much! This was very helpful. I read through the ROS2 link and was able to write the wind_listener.cpp and edit CMakeLists.txt and package.xml files and build the workspace as you described.

However, when I run ros2 run px4_ros_com wind_listener, I only get Starting wind listener node... but no data.

I presume this has something to do with the fact that Wind publisher started is not listed under Publishers when I run micrortps_agent -t UDP.
(SensorCombined publisher started is listeed.)

Furthermore, If I check:
ros2 topic echo /Wind_PubSubTopic
I get: WARNING: topic [/Wind_PubSubTopic] does not appear to be published yet
Could not determine the type for the passed topic

Are there any changes that must be made to micrortps_agent in order to start the publisher?

Update: I am able to get - Wind publisher started to appear after editing uorb_rtps_message_ids.yaml (on both the PX4-Autopilot and px4_ros_com_ros2 sides.) However, my make px4_sitl_rtps now fails with an error as described in my reply to another post:

src/modules/micrortps_bridge/micrortps_client/microRTPS_client.cpp:55:10: fatal error: uORB_microcdr/topics/wind.h: No such file or directory
   55 | #include <uORB_microcdr/topics/wind.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.