Ask Your Question
0

How to Use Laser Data

asked 2014-03-10 01:54:19 -0600

programmer gravatar image

updated 2016-10-24 09:01:52 -0600

ngrennan gravatar image

I want to use laser data in my program(I want C++ code) , I can see ranges data of laser scanner with #rostopic echo /scan/ranges but how can i use it in my codes.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
4

answered 2014-03-10 03:47:55 -0600

The "ranges" member of a LaserScan message is represented by a std::vector<float> and can be used just like any other std::vector of floats.

It might help to have a look at the laser callbacks in slam_gmapping, AMCL and hector_mapping. For the latter, an example of accessing range data is the rosLaserScanToDataContainer function.

edit flag offensive delete link more

Comments

Thanks Dear Stefan for your time... I want to read for example ranges[50], I do it by bellow code but it caused error: `Segmentation fault (core dumped)` "sensor_msgs:: LaserScan scan; std::cout<<scan.ranges[20]<<std::endl;" what's="" my="" problem?<="" p="">

programmer gravatar imageprogrammer ( 2014-03-10 04:51:06 -0600 )edit
1

You instantiate a empty LaserScan message and try to access element 50 of the ranges vector, which does not exist.

Stefan Kohlbrecher gravatar imageStefan Kohlbrecher ( 2014-03-10 05:02:25 -0600 )edit

What i must to do Stefan to read for example ranges[20] ?? when i use "rostopic echo /scan/ranges" it print a lots of ranges, i think it was more than 200s...

programmer gravatar imageprogrammer ( 2014-03-10 05:08:22 -0600 )edit
1

Sorry to be blunt, but you will have to do some basic studying of C++ and the C++ ROS API. The code piece you posted just creates a empty message and tries to access (the non-existing) 20th or 50th range of it. You have to actually subscribe to the topic and use a callback to get the data coming in on a topic. See http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber(c%2B%2B) to get a basic understanding of how subscribing to topics works.

Stefan Kohlbrecher gravatar imageStefan Kohlbrecher ( 2014-03-10 21:53:02 -0600 )edit

Thanks Dear Stefan, I had not read that tutorial... I'm was Stupid... sorry for my silly question. ;-)

programmer gravatar imageprogrammer ( 2014-03-10 23:45:09 -0600 )edit
1

answered 2014-03-10 02:12:04 -0600

dornhege gravatar image

updated 2014-03-10 02:12:20 -0600

You would subscribe to the LaserScan message at /scan and then do what you want to do with it.

edit flag offensive delete link more

Comments

Thanks Dornhege for your response, i want to use some data on scan/ranges for example: ranges[1], ranges[40],ranges[100],... to process them. How can i do that?

programmer gravatar imageprogrammer ( 2014-03-10 02:43:32 -0600 )edit
1

Basically exactly like you've written here. Check out Stefan's answer for more detail.

dornhege gravatar imagedornhege ( 2014-03-10 04:29:57 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-03-10 01:54:19 -0600

Seen: 2,117 times

Last updated: Mar 10 '14