Use MATLAB Robotics System Toolbox to receive ROS message

6 visualizaciones (últimos 30 días)
wjchen84
wjchen84 el 9 de Abr. de 2015
Respondida: Tricky el 2 de Sept. de 2024
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!

Respuesta aceptada

wjchen84
wjchen84 el 9 de Abr. de 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:
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.
  3 comentarios
Mark Levin
Mark Levin el 16 de Dic. de 2015
Does it works with real robot? I mean, if I have Turtlebot for example (I have Jackal, but I don't think there is a difference) - should I change bashrc on the robot?
Chawki CRTL
Chawki CRTL el 5 de Mayo de 2018
Editada: Chawki CRTL el 5 de Mayo de 2018
I don't know how to thank you "wjchen84", you saved my life thank you so much :)

Iniciar sesión para comentar.

Más respuestas (6)

Stefan
Stefan el 13 de Jun. de 2017
Editada: Stefan el 13 de Jun. de 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:
https://nl.mathworks.com/matlabcentral/answers/119559-why-is-the-ros-subscriber-callback-in-matlab-not-triggered-when-messages-are-published-from-an-exter
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 http://www.ros.org/wiki/ROS/EnvironmentVariables : "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 el 14 de Sept. de 2017
Thank you so much. This works. Interfaced Ubuntu 16.04 (ROS Kinetic Kame) and MATLAB 2016a on Windows 10.

Ilya Boyur
Ilya Boyur el 3 de Nov. de 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:
192.168.111.100 UBUNTU_PC_IP
192.168.111.5 WINDOWS_PC_IP
Rebooted machines, turned off firewalls as suggested. Now, when I run in MATLAB (Windows):
[name, address] =resolvehost('UBUNTU_PC_IP')
name =
'ubuntu_pc_ip'
address =
'192.168.111.100'
Seems to work fine, yeah? But:
setenv('ROS_MASTER_URI','http://UBUNTU_PC_IP:11311');
setenv('ROS_IP','WINDOWS_PC_IP');
rosinit
*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.
  2 comentarios
Pavel Roslovets
Pavel Roslovets el 8 de Nov. de 2017
Try to remove underscores from host names:
setenv('ROS_MASTER_URI','http://UBUNTUPCIP:11311');
setenv('ROS_IP','WINDOWSPCIP');
rosinit
Don't forget to do it in host file
Ilya Boyur
Ilya Boyur el 6 de Dic. de 2017
Thanks, Pavel, removing underscores in hosts file resolved the issue.

Iniciar sesión para comentar.


sarra elghali
sarra elghali el 13 de Mzo. de 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','http://192.168.65.82:11311') >> setenv('ROS_MASTER_URI','http://192.168.65.82:11311') >> setenv('ROS_IP','192.168.65.80') >> rosinit *The value of the ROS_MASTER_URI environment variable, http://192.168.65.82:11311, will be used to connect to the ROS master. The value of the ROS_IP environment variable, 192.168.65.80, will be used to set the advertised address for the ROS node. Initializing global node /matlab_global_node_67130 with NodeURI http://192.168.65.80:50121/*
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 ?
  2 comentarios
Ilya Boyur
Ilya Boyur el 14 de Mzo. de 2018
Hi, Sarra Elghali, check first connection between computers/systems running ros:
  • simple command line ping, MATLAB !ping
  • rosnode ping - from MATLAB and from actually ros-running linux
If there are any problems - check your network - all nodes should be also in same network submask (f.e. 255.255.255.0, than node with ROS_IP 192.168.1.2 will publish to 192.168.1.5 and will not publish to 192.168.5.5). Then, let's see what you have.
sarra elghali
sarra elghali el 14 de Mzo. de 2018
Hi, thanks for your replay, My ROS_IP is 192.168.65.80 and ROS_MASTER_URI is 192.168.65.82, they alreday have the same Mask. when I use !ping 192.168.65.82 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 =
'windowspcip'
address =
'192.168.65.80'
>> [name, address] =resolvehost('UbuntuPCIP')
name =
'ubuntupcip'
address =
'192.168.65.82'
>> 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 192.168.65.82 UbuntuPCIP 192.168.65.80 WindowsPCIP
My ros nodes in Ubuntu_Pc run at start_up,automatically but I don't this is may cause problems.

Iniciar sesión para comentar.


alisha
alisha el 11 de Jul. de 2023
Appreciate everyone's help. Flappy Bird

Tricky
Tricky el 2 de Sept. de 2024
Great info! It is useful and helpful for me subway

Community Treasure Hunt

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

Start Hunting!

Translated by