ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

matlab and ROS communication in the same computer

asked 2015-12-14 01:51:16 -0600

Terry Su gravatar image

updated 2015-12-15 01:52:31 -0600

Hello,

Recently, I can use the ROS to receive the sick lidar's signals(ubuntu 14.04LTS and Jade ROS with a sick lidar). Now I want to use matlab to read the signals from ROS, therefore I want to ask that did anyone install the matlab R2015 version with robotic operating toolbox in the ubuntu OS computer which the ROS is in the same computer,too? I ask this question because I want to get the signals directly, and then I use the other computer which is window OS.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2015-12-14 02:08:54 -0600

updated 2015-12-16 07:01:53 -0600

Yes, there's no problem with that. I've in the same computer running ROS and MATLAB and I can stablish a connection without any problem. You just have to specify the localhost parameter when you create the connection in MATLAB.

EDIT 1 The problem is the topic you're subscribing to. If you take a look at the message type of the topic, is a dynamic reconfigure message, not a laser scan message. Are you sure that there are only those two topics? You're missing the topic in which the laser scan data is being published (usually is called /scan).

If you don't have the laser scan data topic, then the problem is not with MATLAB, is in your ROS node.

EDIT 2 Of course the data is static, with the receive function you read your laser data for a specific instant, and then you plot it. If you want to display the laser data in real time you have to be reading always, that is, inside a loop. You have 2 options here:

  • The simple one, is do what you've being doing until now, but inside a loop:

    while (something)
    scan = receive(laser subscriber)
    plot(scan)
    end
    
  • The other option is with a callback function. You can assign a callback function to your subscriber, and everytime there's new data published by the topic, your latest message from your subscriber will be updated. That way you don't have to use the receive function, you can just access the laser data with YourLaserSubscriberName.LatestMessage. Either way, you also need a loop to represent the data, but not for computation stuff... You can check how to add a callback function here. An example of a callback function to access the laser data could be:

    function laserCallback (~, message)
    global ranges;
    ranges = message.Ranges;
    end
    

To understand the difference between the two options, I suggest you try this: create two subscribers of your /scantopic, one with the callback function and the other one without it. Then plot the latest message of both, they'll be identical. Now change what the laser sees (put some obstacle or something) and plot again. The message from the subscriber without the callback has not change, whereas the one with the callback yes, because it's updated each time the laser publish new data.

Hope I was clear enough :)

edit flag offensive delete link more

Comments

Hello S.Prieto, After I read the tutorial of ROS in the MATLAB as this link : http://www.mathworks.com/help/robotic... I want to use Simulink to receive ROS messages, did you use the Simulink to connect to the ROS? Or just use MATLAB.

Terry Su gravatar image Terry Su  ( 2015-12-15 21:37:38 -0600 )edit

Sorry, I don't use Simulink... I just use MATLAB to communicate and interact with my robot, but I'm assuming it would be similar. First you'd like to check if the message you're interested in is a ROS message or is created by you, which in that case you'd have to create iit n MATLAB also. Good luck!

S.Prieto gravatar image S.Prieto  ( 2015-12-16 02:05:30 -0600 )edit

Hello S.Prieto, I have a problem which is about MATLAB with ROS. When I type "rostopic list", it shows the "/sick_tim551_2050001/parameter_descriptions and /sick_tim551_2050001/parameter_updates. Then,I type " laser=rossubscriber('/sick_tim551_2050001/parameter_updates')" to see pubish and subscribe

Terry Su gravatar image Terry Su  ( 2015-12-16 04:32:11 -0600 )edit

It show the message: Subscriber with properties:

    TopicName: '/sick_tim551_2050001/parameter_upda…'
  MessageType: 'dynamic_reconfigure/Config'
LatestMessage: [1x1 Config]
   BufferSize: 1
NewMessageFcn: []
Terry Su gravatar image Terry Su  ( 2015-12-16 04:33:53 -0600 )edit

But when I type the "scandata = receive(laser,10)" , it doesn't show anything which is about the lidar detection. Do you know any wrongs here? Thank you.

Terry Su gravatar image Terry Su  ( 2015-12-16 04:35:23 -0600 )edit

Oh, it has the /scan,too. I thought the /scan is the example's topic before. I have tried it and it works! But I have a problem here. Does your robot's signal run on the matlab continuesly? It means your data is changed with time. Thank you.

Terry Su gravatar image Terry Su  ( 2015-12-16 05:56:53 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-12-14 01:51:16 -0600

Seen: 1,215 times

Last updated: Dec 16 '15