ROS Toolbox not sending or receiving data, though topics are published

조회 수: 8 (최근 30일)
Penelope
Penelope 2025년 6월 24일
답변: Penelope 2025년 6월 24일
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.

채택된 답변

Penelope
Penelope 2025년 6월 24일
I found the solution to my problem to be following these steps;
  1. Go to settings, ROS toolbox
  2. Browse for your Python executable - in my case, it was found in /home/penelope/anaconda3/envs/ezloophw-cv-upgrade/bin/python3.10 (I wonder if this is because I use a miniconda environment? Is it not usually automatically detected?)
  3. Click recreate python environment
  4. Set RMW implementation to cyclonedds
  5. Ensure your terminal is using cyclonedds by installing it and typing export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 ROS 2 Network Connection and Exploration에 대해 자세히 알아보기

태그

제품


릴리스

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by