MATLAB: Matlab ROS subscriber basic example

Robotics System Toolboxrossubscriberturtlebot

Have you a step by step example to create a subscriber I do this
setenv('ROS_IP','192.168.1.41') % adress PC with Matlab setenv('ROS_HOSTNAME','192.168.1.41') setenv('ROS_MASTER_URI','http://192.168.1.28:11311/') % adress turtlebot rosinit rostopic list
Here I am able to see all the topics that are on the turtlebot And I am able to command to move my turtlebot with
velocity = -0.1; % meters per second robot = rospublisher('/mobile_base/commands/velocity') velmsg = rosmessage(robot) velmsg.Linear.X = velocity; for i=1:50000 i send(robot,velmsg); end
I can also ask to my Turtle to emitting a noise
soundpub = rospublisher('/mobile_base/commands/sound', 'kobuki_msgs/Sound') soundmsg = rosmessage('kobuki_msgs/Sound'); soundmsg.Value = 6; % Any number 0-6 send(soundpub,soundmsg);
But when I want to subscribe to a topic…
odom = rossubscriber('/odom')
odomdata = receive(odom,3);
I have this error message
Error using robotics.ros.Subscriber/receive (line 325)
The function did not receive any data and timed out.
When I apply : rostopic info /odom I obtain :
Type: nav_msgs/Odometry Publishers: * /mobile_base_nodelet_manager (<http://turtlebot.local:58513/>) Subscribers: * /matlab_global_node_86572 (<http://192.168.1.65:49791/>) * /matlab_turtlebot_69671 (<http://192.168.1.65:49752/>)
What I should do to be able to subscribe and read a topic of my Turtlebot with Matlab My configuration is Turtlebot : Ubuntu 14.4 + Indigo PC : Windows10 + Matlab 2017a (I stop all firewall)
Thank you in advance for your help

Best Answer

My problem come to multipl IP adress for my Matlab computer...
.
To help other persone, the configuration that work well with my Turtlebot
In my case, the IP adress are
PC with Matlab : 192.168.1.41
Turtlebot computer : 192.168.1.28
.
In the .bashrc, I have
source /opt/ros/indigo/setup.bash
export ROS_MASTER_URI=http//192.168.1.28:11311
export ROS_HOSTNAME=192.168.1.28
export ROS_IP=192.168.1.28
.
In Matlab 2 solutions are possible:
solution 1:
setenv('ROS_IP','192.168.1.41') % adress PC with Matlab
setenv('ROS_HOSTNAME','192.168.1.41')
setenv('ROS_MASTER_URI','http://192.168.1.28:11311/') % adress turtlebot
rosinit
.
solution 2 :
rosinit('http://192.168.1.28:11311', 'NodeHost', '192.168.1.41')