Matlab ROS subscriber basic example

조회 수: 3 (최근 30일)
Vincent Talon
Vincent Talon 2017년 7월 7일
댓글: xupeng 2019년 11월 19일
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

채택된 답변

Vincent Talon
Vincent Talon 2017년 7월 11일
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
xupeng
xupeng 2019년 11월 19일
thanks for your answer, it soluts my problem whice disturbe me for a long time .

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sebastian Castro
Sebastian Castro 2017년 7월 10일
편집: Sebastian Castro 2017년 7월 10일
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

카테고리

Help CenterFile Exchange에서 Publishers and Subscribers에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by