How to Use Laser Data
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.
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
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.
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.
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="">
You instantiate a empty LaserScan message and try to access element 50 of the ranges vector, which does not exist.
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...
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.
Thanks Dear Stefan, I had not read that tutorial... I'm was Stupid... sorry for my silly question. ;-)
You would subscribe to the LaserScan message at /scan
and then do what you want to do with it.
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?
Asked: 2014-03-10 01:54:19 -0600
Seen: 3,403 times
Last updated: Mar 10 '14