Use MATLAB Robotics System Toolbox to receive ROS message

19 views (last 30 days)
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!

Accepted Answer

wjchen84 on 9 Apr 2015
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:
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.
Chawki CRTL
Chawki CRTL on 5 May 2018
Edited: Chawki CRTL on 5 May 2018
I don't know how to thank you "wjchen84", you saved my life thank you so much :)

Sign in to comment.

More Answers (4)

Stefan on 13 Jun 2017
Edited: Stefan on 13 Jun 2017
I ran into the same problem with 2 computers:
- Windows7 + Matlab R2017a with Robotics System Toolbox
- Ubuntu 14.04 + ROS
The solution was to do explicitly indicate variable ROS_IP on the Ubuntu PC (as shown by wjchen84 at step5).
For interested readers, I'd like to indicate some other links that I found useful on the same topic:
google: "defining the ROS_IP solved my problem. I had different network interfaces (wlan0, eth0, etc) and I had to explicitly tell ROS which one to use. This is clearly explained in : "This setting is only needed in situations where you have multiple addresses for a computer and need to force ROS to a particular one."

Aaditya Saraiya
Aaditya Saraiya on 14 Sep 2017
Thank you so much. This works. Interfaced Ubuntu 16.04 (ROS Kinetic Kame) and MATLAB 2016a on Windows 10.

Ilya Boyur
Ilya Boyur on 3 Nov 2017
Hello everybody, I ran into the same problem with Windows 10 (MATLAB 2017a) and Ubuntu 16.04 amd64 ROS Kinetic. I did as wjchen84 suggested, except I edited file C:\Windows\system32\drivers\etc\hosts and on Ubuntu /etc/hosts: UBUNTU_PC_IP WINDOWS_PC_IP
Rebooted machines, turned off firewalls as suggested. Now, when I run in MATLAB (Windows):
[name, address] =resolvehost('UBUNTU_PC_IP')
name =
address =
Seems to work fine, yeah? But:
*The value of the ROS_MASTER_URI environment variable, http://UBUNTU_PC_IP:11311, is an invalid URI.
Check the URI for correctness.*
As the same, direct IP configuration for setenv() in MATLAB doesn't work.
How to check that my host names resolved right if not with resolvehost? Hope anyone faced the same issue.
Ilya Boyur
Ilya Boyur on 6 Dec 2017
Thanks, Pavel, removing underscores in hosts file resolved the issue.

Sign in to comment.

sarra elghali
sarra elghali on 13 Mar 2018
Hi everyone,I ahd the same problem with Windows 10 (MATLAB 2017a) and Ubuntu 16.04 amd64 ROS Kinetic. I did fellow all the steps. (for my windows IP adress, I'm not sure if i should take IPv4 Address or default Gateway)
setenv('ROS_MASTER_URI','') >> setenv('ROS_MASTER_URI','') >> setenv('ROS_IP','') >> rosinit *The value of the ROS_MASTER_URI environment variable,, will be used to connect to the ROS master. The value of the ROS_IP environment variable,, will be used to set the advertised address for the ROS node. Initializing global node /matlab_global_node_67130 with NodeURI*
Now, when I try to get message using this commande msgg=receive(hw,10) // hw is the name of my subscriber i got this error : Error using robotics.ros.Subscriber/receive (line 325) The function did not receive any data and timed out.
Can anyone help me please ?
sarra elghali
sarra elghali on 14 Mar 2018
Hi, thanks for your replay, My ROS_IP is and ROS_MASTER_URI is, they alreday have the same Mask. when I use !ping in matlab command window, It's ping to that adress successfully. you can see here , I even got a no error when I connect to ROS master
[name, address] =resolvehost('WindowsPCIP')
name =
address =
>> [name, address] =resolvehost('UbuntuPCIP')
name =
address =
>> setenv('ROS_MASTER_URI','http://ubuntupcip:11311') >> setenv('ROS_IP','windowspcip') >> rosinit
The value of the ROS_MASTER_URI environment variable, http://ubuntupcip:11311, will be used to connect to the ROS master. The value of the ROS_IP environment variable, windowspcip, will be used to set the advertised address for the ROS node. Initializing global node /matlab_global_node_09027 with NodeURI http://windowspcip:49943/
But I still got an empty msg from my subscriber
hw_status =
Subscriber with properties:
TopicName: '/Niryo_one/hardware_status'
MessageType: 'niryo_one_msgs/HardwareStatus'
LatestMessage: [0×1 HardwareStatus]
BufferSize: 1
NewMessageFcn: []
>> hwmesg=rosmessage(hw_status)
hwmesg =
ROS HardwareStatus message with properties:
MessageType: 'niryo_one_msgs/HardwareStatus'
Header: [1×1 Header]
RpiTemperature: 0
ConnectionUp: 0
ErrorMessage: ''
CalibrationNeeded: 0
CalibrationInProgress: 0
MotorNames: {0×1 cell}
MotorTypes: {0×1 cell}
Temperatures: [0×1 int32]
Voltages: [0×1 double]
HardwareErrors: [0×1 int32]
In Ubuntu, I already run those command
export ROS_MASTER_URI=http://UbuntuPCIP:11311
export ROS_IP=UbuntuPCIP and I added in /etc/hosts file UbuntuPCIP WindowsPCIP
My ros nodes in Ubuntu_Pc run at start_up,automatically but I don't this is may cause problems.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!