Search code examples
rosdata-distribution-serviceros2

Subscribe to ROS2 topic from native ePromisa DDS program


I'm trying to read a ROS2 topic from another ePromisa DDS-based program. I have a ROS2 publisher node sending data to a topic. I want to read from that topic in the non-ROS DDS program.

I've already generated the appropriate matching IDL files. But I'm having trouble getting them to run at the same time.

From what I understand I need to launch ROS2 with the FastDDS server explicitly. I tried to do this by using the discovery config file found in the ePromisa docs.

However, I get an error...

ROS2: RROR] [1625247859.663887254] [rcl]: Failed to fini publisher for node: 1 terminate called after throwing an instance of 'rclcpp::exceptions::RCLError' what(): failed to initialize rcl node: rcl node's rmw handle is invalid, at /tmp/binarydeb/ros-foxy-rcl-1.1.11/src/rcl/node.c:428

Does anyone have any thoughts or know where to find a definitive guide to reading ROS2 topics from DDS?


Solution

  • The solution is simpler than that.

    First of all, have in mind that Fast-DDS implements the DDS standard, and so it is compatible with any other DDS solution. Thus, you do not have to use explicit Fast-DDS features (as +Discovery-Server*) to communicate your entities (you do not even have to use Fast-DDS explicitly).

    There are two main points to have in mind when connecting Fast-DDS with ROS2:

    Topic name

    ROS2 mangles the DDS topic so the ROS2 nodes does not match and communicate with external DDS entities (ups, that's what we wanna do). This mangling is usually done by adding rt/ before the topic name. This is, if using topic chatter the real topic name that will be sent in DDS is rt/chatter.

    Type name

    Every topic in DDS is related with a data type. This data type has a unique name. As in Topic, ROS2 mangle this name as well, creating something like std_msgs::msg::dds_::String_ for the string data type.

    Solution

    In order to communicate a Fast-DDS with ROS2 you need to create the entities (DataWriters and DataReaders) of Fast-DDS with the topic and type name specific in ROS2.

    How to know which is the exact name of the topic and type using by a ROS2 node? This is a good question, and sometimes it is hard to investigate (type names are normally harder due to package names included in the mangling). For this propose, I recommend to use Fast-DDS-Monitor: an open source GUI that allow to monitor a DDS network. By using this tool you will discover every topic in the network, and there you can easily find the topic name and type the ROS2 entities are using. Check the Fast-DDS-Monitor documentation to learn how to use it, and download it from eProsima site.