ROS Toolbox not sending or receiving data, though topics are published
Show older comments
Hello all,
I'm trying to simply publish or subscribe to data using the ROS toolbox in Matlab (my ROS2 version is Humble), but am unable to do so. I have set up two python scripts, one a publisher and one a subscriber, to simply send each other data, and it works perfectly. I have been trying for the past 4 hours to have a Matlab subscriber and a python publisher or a python subscriber and a Matlab publisher, but neither result has worked.
% Set domain ID
setenv('ROS_DOMAIN_ID', '49');
setenv('ROS_IP', '10.239.18.116')
% Create node
node = ros2node("/matlab_pub_node", 49);
% Create publisher
pub = ros2publisher(node, "/my_topic", "std_msgs/String", ...
"Reliability", "reliable", ...
"Durability", "volatile", ...
"History", "keeplast", ...
"Depth", 1);
% Create and send message in a loop
msg = ros2message(pub);
disp("Publishing every 5 seconds...");
while true
msg.data = ['Hello from MATLAB at ', datestr(now)];
send(pub, msg);
disp(['Sent: ', msg.data]);
pause(5);
end
I am running this in Matlab 2025a, and then, in a terminal in Ubuntu 22.04, am running
ros2 topic echo /my_topic
The topic will connect, but no data is said to be received. A very similar result happens when I attempt to publish data from a terminal and subscribe to it in Matlab.
As you can see, I have covered several bases; Domain ID, IP, QoS, and have been unsuccessful. I have also ensured both terminal and Matlab are using rmw_fastrtps_cpp DDS. This has also failed. I am unsure what to try at this point. Some guidance would be greatly appreciated.
Accepted Answer
More Answers (0)
Categories
Find more on ROS 2 Network Connection and Exploration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!