Matlab ROS subscriber basic example

10 visualizaciones (últimos 30 días)
Vincent Talon
Vincent Talon el 7 de Jul. de 2017
Comentada: xupeng el 19 de Nov. de 2019
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

Respuesta aceptada

Vincent Talon
Vincent Talon el 11 de Jul. de 2017
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')
  1 comentario
xupeng
xupeng el 19 de Nov. de 2019
thanks for your answer, it soluts my problem whice disturbe me for a long time .

Iniciar sesión para comentar.

Más respuestas (1)

Sebastian Castro
Sebastian Castro el 10 de Jul. de 2017
Editada: Sebastian Castro el 10 de Jul. de 2017
If you try to echo the /odom topic on the Turtlebot and in MATLAB (same syntax), do you see any messages?
rostopic echo /odom
If you don't see anything on the robot, then it's not sending anything and it's not a MATLAB issue. If you see something on the robot but not in MATLAB, then it could be a connectivity issue and maybe changing the port on the URI could help?
- Sebastian

Categorías

Más información sobre Publishers and Subscribers en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by