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

Collect sensor data from LaserScan

asked 2017-04-21 03:51:56 -0600

Turtle gravatar image

updated 2017-04-21 04:52:32 -0600

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?

edit retag flag offensive close merge delete

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++

mohsen1989m gravatar image mohsen1989m  ( 2017-04-21 05:19:54 -0600 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2017-04-21 05:03:48 -0600

updated 2017-04-21 05:06:07 -0600

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()
edit flag offensive delete link more

Comments

1

Thanks! :)

Turtle gravatar image Turtle  ( 2017-04-21 05:51:07 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-04-21 03:51:56 -0600

Seen: 675 times

Last updated: Apr 21 '17