Use MATLAB Robotics System Toolbox to receive ROS message

Illustration
wjchen84 - 2023-05-15T12:24:10+00:00
Question: Use MATLAB Robotics System Toolbox to receive ROS message

I was trying to use Robotics System Toolbox(MATLAB 2015a on windows 7) to communicate with the ROS running on Ubuntu 14.04. The "rosinit" was successful and MATLAB can see the rosnode list, rostopic list, etc. I can also create the rossubscriber from MATLAB to any topic successfully.   But when I run "receive" command, it just wait forever until timeout. It seems no new message is coming which should not be the case (as I am sure the ROS on Ubuntu is constantly publishing the new kinect images).   I have tried several different settings for rosinit, such as using ROS_MASTER_URI, ROS_IP, etc. Also the two PCs can ping each other's IP successfully. So I think the network connection between the two machines should be good. But MATLAB still couldn't receive the message although it can see and subscribe the topic.   Could anyone suggest any possible cause for this issue? Your help would be really appreciated!

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

I figureed out the solution for this problem. The following steps seem to be helpful:
 
 
1. In Ubuntu PC hosts file (/etc/hosts), add the hostnames and the IP addresses of both Ubuntu PC and Windows PC
2. In Windows PC host file (/windows/system32/driver/etc/host), do the same thing as in previous step
3. Turn off all the firewalls on Window PC and Ubuntu PC (if there is any)
4. Reboot both machines to make the new host files effective
5. Set the following environment variables on Ubuntu PC
 
 
   sudo gedit ~/.bashrc

Add the following lines in .bashrc file, save and then restart terminal

   export ROS_MASTER_URI=http://Ubuntu_PC_IP:11311
   export ROS_IP=Ubuntu_PC_IP

6. On Windows MATLAB, set the environment variables for ROS:

   setenv('ROS_MASTER_URI','http://Ubuntu_PC_IP:11311')
   setenv('ROS_IP','Windows_PC_IP')
   rosinit

Then it should work. I did almost everything except Step 2, which caused the above problem. I hope this would help someone who has the similar problem.


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!