Receive Data ROS2

21 views (last 30 days)
Hossein Moghimi
Hossein Moghimi on 9 May 2022
Moved: Remo Pillat on 26 Jan 2023
We are trying to connect a Linux based machine (using Ubuntu 18.04 with ROS2 Dashing) to Matlab running on a Windows 10 PC, using ROS2 DDS services. They both are connected on the same network and their subnets are the same (PC is 10.221.114.24 and the device is 10.221.114.161). I set the domain ID of both to 5. When I create a node in either of them, I can detect it in another (using ros2 node list). Likewise, I can do the same for topics (using ros2 topic list). I have a basic publisher and subscriber (std_msgs string), which work perfectly fine, when run in the Linux device. When I run the publisher on the Linux machine; although Matlab in my PC can detect both the publisher’s node and the topic, the Matlab "receive" function always timeout and does not receive any messages. I tried both “reliable” and “besteffort” reliability settings, in the Matlab “ros2subscriber” function, with no luck. I also have turned all firewalls off. Moreover, I have tried to follow all guidelines given in this page, with no luck.
I tested this on both Matlab 2020a and 2021b with no luck.
Here is the Matlab code:
clear all
clc
setenv("ROS_DOMAIN_ID","5");
ros2 topic list
topicList=ros2("topic","list");
if(sum(contains(topicList, "test_publisher_topic")))
SubscriberNode=ros2node("/matlab_subscriber");
pause(2);
msgSub=ros2subscriber(SubscriberNode, "/test_publisher_topic" ,"Reliability", "besteffort");
while(1)
Message=receive(msgSub, 5);
disp(Message)
end
else
disp('hossein_topic not present!')
end
ERROR Code:
Error using ros2subscriber/receive (line 458)
Subscriber did not receive any messages and timed out.
Any idea?
Best
Hossein
  9 Comments
Hossein Moghimi
Hossein Moghimi on 10 May 2022
Hi,
I went home yesterday, so sorry for the late reply. Well I tried the standalone router and no success. I ran a c++ subscriber on the ubuntu machine and have been able to get the messages. I did what you asked above (the coomands have been run on Ubuntu machine) and below is the result:
root@qrb5165-rb5:~# ros2 topic info /test_publisher_topic
Topic: /test_publisher_topic
Publisher count: 1
Subscriber count: 0
root@qrb5165-rb5:~# ros2 node list
/matlab_subscriber
root@qrb5165-rb5:~# ros2 node info /matlab_subscriber
/matlab_subscriber
Subscribers:
Publishers:
Services:
so both Matlab and Ubuntu machine can see the node and topic but the disp callback never happen. The recive with 10 second timeout also fails.
By the way I tested this on both Matlab 2020b and 2021b.
Just out of curocity, my ROS2 is Dashing, NOT Foxy. I assume it cannot be the issue?
Hossein Moghimi
Hossein Moghimi on 11 May 2022
Hi
@Cam Salzberger I tried turning all virus protection and firewalls off and still get the same error. As I mentioned above Matlab can see the nodes and topics on the ubuntu machine. The ubuntu machine, likewise, can see Matlab nodes. but I think the subscription simply does NOT happen. I am almost out of options and have no idea why it is happening.
Just one thing. To make sure that the office (possible) hardware firewalls do not interfier with the DDS, I did not connect the standalone router to the internet. the IP addresses assigned to the machines are 169.254.45.14 (PC) and 169.254.4.1 (ubuntu machine). I created the followowing "DEFAULT_FASTRTPS_PROFILES.xml" file and copied it in the matlab current directory.
<?xml version="1.0" encoding="UTF-8" ?>
<profiles>
<transport_descriptors>
<transport_descriptor>
<transport_id>veelpeers</transport_id> <!-- string -->
<type>UDPv4</type> <!-- string -->
<maxInitialPeersRange>1000</maxInitialPeersRange> <!-- uint32 -->
</transport_descriptor>
</transport_descriptors>
<participant profile_name="participant_somename" is_default_profile="true">
<rtps>
<builtin>
<metatrafficUnicastLocatorList>
<locator/>
</metatrafficUnicastLocatorList>
<domainId>4</domainId>
<initialPeersList>
<locator>
<udpv4>
<address>169.254.45.14</address>
</udpv4>
</locator>
<locator>
<udpv4>
<address>169.254.4.1</address>
</udpv4>
</locator>
</initialPeersList>
</builtin>
<userTransports>
<transport_id>veelpeers</transport_id>
</userTransports>
<useBuiltinTransports>false</useBuiltinTransports>
</rtps>
</participant>
</profiles>
I followed this page and use the following commands after saving the .xml file in the ubuntu machine as well.
export FASTRTPS_DEFAULT_PROFILES_FILE=<path_to_xml_file>
export RMW_FASTRTPS_USE_QOS_FROM_XML=1
Still it does exactly the same as before. Can you think of any solutions?

Sign in to comment.

Answers (1)

Cam Salzberger
Cam Salzberger on 11 May 2022
Moved: Remo Pillat on 26 Jan 2023
Sorry, this is a pretty new issue to me. I think I've seen one-directional communication, but not the inability to see the subscribers in MATLAB. And usually this issue is with ROS 1 not ROS 2.
Both R2020a and R2021b use Dashing on their back-end as well, so version incompatibility should not be the issue. If you upgrade to R2022a, it uses Foxy, so you may get an issue at that point fi your Ubuntu is still using Dashing.
If, after making your XML file, you are still able to see the MATLAB nodes in "ros2 node list" and are able to receive messages from MATLAB publishers on Ubuntu, then the XML file is working correctly. The environment variables you set, however, I believe only apply to Foxy (and maybe Eloquent), but not Dashing.
The one thing I think should be tried next is a bit intensive. If you are able to install ROS 2 Dashing on your Windows machine, we can isolate whether the issue is with MATLAB's ROS 2 implementation, or with the general ROS 2 communication between Windows and Ubuntu.
-Cam

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!