Robotics StackExchange | Archived questions

How to plot laser scan data into Matlab ?

Hi I have recorded a simulation and created a bag file. I'm using a python code ( http://wiki.ros.org/rosbag/Code%20API ) 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))
bag.close()

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

Asked by RosUser on 2016-06-07 15:27:39 UTC

Comments

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.

Asked by JamesWell on 2016-06-09 03:59:52 UTC

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

Asked by RosUser on 2016-06-09 04:35:34 UTC

Have you tried msg.min... etc?

Asked by JamesWell on 2016-06-09 06:07:38 UTC

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

Asked by RosUser on 2016-06-09 06:37:38 UTC

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.

Asked by JamesWell on 2016-06-11 03:27:46 UTC

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

Asked by RosUser on 2016-06-11 05:01:17 UTC

Answers