Robotics StackExchange | Archived questions

Collect sensor data from LaserScan

I am using a robot in simulator with a laser sensor (sensor_msgs/LaserScan). I'd like to collect all sensor data that the robot scans, is there any way to do that in rospy?

Asked by Turtle on 2017-04-21 03:51:56 UTC

Comments

why don't u just use rosbag record ... if you want to some real-time calculation on the Laser data I recommend to switch to C++

Asked by mohsen1989m on 2017-04-21 05:19:54 UTC

Answers

rospy has a logger, use it

topic = 'sensor_msgs/LaserScan/topic'
 rospy.loginfo("I will publish to the topic %s", topic)

and some latter in the callback:

def callback(data):
    rospy.loginfo(rospy.get_caller_id() + "I heard %s", data.data)

if you maybe need to collect the data to later use it / reproduce it for analytics purposes then a Rosbag is the way to go :)

import rosbag
from std_msgs.msg import Int32, String

bag = rosbag.Bag('test.bag', 'w')

try:
    str = String()
    str.data = 'foo'

    i = Int32()
    i.data = 42

    bag.write('chatter', str)
    bag.write('numbers', i)
finally:
    bag.close()

Asked by ΦXocę 웃 Пepeúpa ツ on 2017-04-21 05:03:48 UTC

Comments

Thanks! :)

Asked by Turtle on 2017-04-21 05:51:07 UTC