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

Revision history [back]

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.

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.

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:

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 :)