- Could use a pause after the first topic list call to allow a newly-created introspection node time to get metacommunication on the network. I know that's not the issue here, but it's good practice.
- Minor improvement to the conditional on checking if the topic is listed
- Use reliable to avoid potentially dealing with dropped messages
- Use the subscriber callback rather than receive to avoid blocking and allow the script to work no matter if MATLAB subscriber or Ubuntu publisher was created first
- Specify the message type for the same reason
Receive Data ROS2
8 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Cam Salzberger
2022 年 5 月 11 日
移動済み: Remo Pillat
2023 年 1 月 26 日
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
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!