ROS2 Example Not working

8 views (last 30 days)
Adhémar
Adhémar on 15 Dec 2024
Answered: Josh Chen on 17 Jan 2025
I'm on Windows 10 trying to make a project work using Matlab ROS2
I have a lot of bugs, so I decided to just start from the beginning and run the tutorial:
openExample('ros/ExchangeDataWithROS2PublishersAndSubscribersExample')
When running the first command:
>> exampleHelperROS2CreateSampleNetwork
Error using ros2subscriber (line 319)
Unable to find topic /pose on the ROS 2 network. Use "ros2 topic list" to display the list of available topics.
Error in exampleHelperROS2CreateSampleNetwork (line 23)
twistSub = ros2subscriber(node_2,'/pose');
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I have that bug. Doing a rosinit doesn't help. However, if I start to create the topic on my ROS2 Windows environment works (by doing ros2 topic echo). I'm having A lot of other bugs like that and I'm sure there is a common issue to them, hope someone can help me. I added the rossupport.txt for help
Thank in advance.

Answers (1)

Josh Chen
Josh Chen on 17 Jan 2025
Hi Adhémar,
Based on the error log you showed, at the moment of executing "ros2subscriber" at line 23 in "exampleHelperROS2CreateSampleNetwork", the '/pose' topic is not visible.
It is hard to tell what exactly is the root cause without getting more information, but here is some quick steps to help troubleshooting:
1. If you haven't done so, update to latest version (R2024b Update 4).
2. Pub a breakpoint at line 21, and run "exampleHelperROS2CreateSampleNetwork", when it reaches the breakpoint, see if you can see '/pose' in the output of the following code in MATLAB Command Window:
>> ros2 topic list
3. If you can see that topic in step 1, now manually run line 23 to create the subscriber.
4. If step 2 failed to create the subscriber with the same error message, try providing the message type and see if you can create the subscriber:
>> twistSub = ros2subscriber(node_2,'/pose','geometry_msgs/Twist');
Few things to clarify:
1. When you said "create the topic on ROS2 windows env", do you mean you publish the message to the topic in MATLAB, and use local installed ROS2 terminal to run "ros2 topic echo"?
2. rosinit doesn't help -> this is expected. rosinit only required for ROS 1, not ROS 2.
3. Copy the command and run it manually in MATLAB Command Window instead of Live Editor, and see if it works.
4. Make sure you are creating publisher and subscriber in nodes under same domain ID.
If you are still seeing the same issue after trying the above troubleshooting suggestions, I would suggest to reach out to MathWorks Technical Support. Our technical support team can work with you to dig deeper and see what is the root cause.
Hope this helps,
Thanks,
Josh

Categories

Find more on Publishers and Subscribers in Help Center and File Exchange

Tags

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!