How to plot laser scan data into Matlab ?

asked 2016-06-07 15:27:39 -0500

RosUser gravatar image

updated 2016-06-12 05:15:44 -0500

Hi I have recorded a simulation and created a bag file. I'm using a python code ( ) for reading laser scan information.

from __future__ import print_function
import rosbag
bag = rosbag.Bag('2016-06-06-12-57-11.bag')
for topic, msg, t in bag.read_messages(topics=['/base_scan']):
    for i in range(msg.min.ranges, msg.max.ranges):
        print("%f %f " % (msg.min.ranges, msg.max.ranges))

How can I read all the laser scan data by using python ?

edit retag flag offensive close merge delete


Try running a rostopic list to see if your laser scans are published (they probably are). Then you can start by changing the '/odom/ to the laser topic.

JamesWell gravatar imageJamesWell ( 2016-06-09 03:59:52 -0500 )edit

It is published.This is my idea that doesn't work yet

for topic, msg, t in bag.read_messages(topics=['/base_scan']):
for (min.ranges[i],max.ranges[i])
    print("%f " % (msg.ranges[i]))
RosUser gravatar imageRosUser ( 2016-06-09 04:35:34 -0500 )edit

Have you tried msg.min... etc?

JamesWell gravatar imageJamesWell ( 2016-06-09 06:07:38 -0500 )edit

Yes! it dosen't work ... File "", line 5 for (msg.min.ranges[i],msg.max.ranges[i]) ^ IndentationError: expected an indented block

RosUser gravatar imageRosUser ( 2016-06-09 06:37:38 -0500 )edit

That's a python error. You should indent your python code properly. You can paste the full script here and I can check the indents if necessary, but try correcting them yourself first.

JamesWell gravatar imageJamesWell ( 2016-06-11 03:27:46 -0500 )edit

I have tried different things after I have searched the error where it is due to mixing Tab and space So I tried change for loop but it did not worked!I have edited my question code to full script

RosUser gravatar imageRosUser ( 2016-06-11 05:01:17 -0500 )edit