- If you try to create a publisher or subscriber in MATLAB for that custom message type, are they able to be created?
- Can you create a blank message of the correct type with rosmessage?
- Are you able to publish that message, and receive it on another machine that is looking for that message type (if you have any)?
- If you create a subscriber for that message type, does it receive the messages? Are you able to create a callback that accesses data within them?
MATLAB unable to receive messages of a custom ROS message type
14 views (last 30 days)
Show older comments
Hi all,
I am trying to run a ROS node to drive a small rover using a motion capture system, which entails subscribing to ROS messages containing position information. I have successfully been able to set up a ROS network and detect the message type using rostopic list in both terminal and MATLAB, but unable to receive any information through rostopic echo in MATLAB, although it works perfectly fine on terminal. I have also previously run rosgenmsg successfully to build the message type. I have tested sending and receiving information using std_msgs, and found that MATLAB has no problem picking that up, so my instinct says it is a custom message type issue. I would also add that the suscriber I in the script lists all the subtopics of the message correctly, indicating successful build using rosgenmsg.
I do not get any error messages of any kind, just a time out of the rostopic echo function in the MATLAB command window.
Would anyone have any idea for a possible workaround for this problem?
(I am running Ubuntu 16.04 and MATLAB R2019a)
Thanks
4 Comments
Cam Salzberger
on 13 Jun 2019
Edited: Cam Salzberger
on 13 Jun 2019
Hmm, so far my understanding is that there are two times when the communication did not go through:
- Non-MATLAB publishing custom message, and MATLAB is trying to use "rostopic echo" to view them.
- Non-MATLAB publishing a "one-off" message using "rostopic pub", and MATLAB has a subscriber for that topic (LatestMessage property does not update).
Let me know if my understanding is incorrect.
Two possible hypothesis come to mind:
- Something is going on with the ROS command line tools (rostopic specifically), though the two failures seem to make this unlikely.
- Something is up with the Master itself.
Did you use the same Master when doing your tests above as you do under your normal setup? Or did you create a separate MATLAB master for that? Is your normal Master located on MATLAB or on the other machine?
One other possible thing to check is MATLAB-to-MATLAB communication using "rostopic echo". Can you run this code and let me know if anything is echoed?
rosinit
p = rospublisher('/test_topic', 'qualysis/Subject');
m = rosmessage(p);
t = timer('TimerFcn', @(~, ~) send(p, m), 'Period', 1, 'ExecutionMode','fixedRate', 'TasksToExecute', 30);
start(t)
rostopic echo /test_topic
Don't forget to stop and delete the timer once you Ctrl+C to stop the echo. Otherwise it hangs around, though I limited the number of times it runs in case you forget.
Answers (1)
Cam Salzberger
on 17 Jun 2019
Edited: Cam Salzberger
on 17 Jun 2019
Hey Harvard,
Now that things have been narrowed down, hopefully I can offer some potential solutions. One of the biggest causes I've seen for communication not happening in ROS (especially one way having an issue, and the other not) is the originating node not advertising itself properly. Essentially, one of the machines is incapable resolving the address to the other machine, and so communication in that direction wasn't possible, though it could still receive incoming data. One of the other common symptoms I saw for this was that "rosnode ping <pub_name>" would time out when called from the subscriber node side.
The most common solution for this issue is to ensure that the "ROS_IP" environment variable is set on the originating machine (in the terminal before running the node). The value of this variable should be the computer's own IP address. Make sure that "ROS_HOSTNAME" is not set if you are using "ROS_IP", as the "ROS_HOSTNAME" will supercede it.
Another possible issue is if your machine (either machine, I suppose) has a hostnames file (which specifies how the DNS lookup can determine the IP for the target machine from a hostname), and the target machine hostname doesn't match the IP of that machine.
It's also possible that the port for the ROS master is unblocked, but the specific port that the publisher-subscriber connection is using is blocked by your firewall. That one is tougher to check safely, and usually not an issue, so I'd save checking that for last.
You can get more diagnostic information out of the native ROS tools. The aptly-named "roswtf" command is pretty useful (run from one of the machines running ROS natively). rqt_graph is also useful for visualizing the network, which may indicate issues in the form of cut off nodes or similar.
I hope that helps to get you going.
-Cam
2 Comments
Yoseph Kebede
on 28 Sep 2023
What solved the problem? Cam suggested multiple ways out of which I have tried most. I am using Ubuntu WSL and Matlab on the same computer which I am trying to communicate to eachother. What should I do?
See Also
Categories
Find more on 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!