ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A
Ask Your Question

How to extract and use laser data from /scan topic in ROS using C++?

asked 2013-04-08 08:17:35 -0500

hesh8 gravatar image


How do I subscribe to the /scan topic so that I can store laser scan data in a data structure? We are trying to get the data to use for control loops.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2013-04-08 23:35:52 -0500

yigit gravatar image

updated 2013-04-08 23:42:29 -0500

Here is an example:

ros::NodeHandle nh;
ros::Subscriber scanSub;


You can implement the callback function however you like

void AutoExp::processLaserScan(const sensor_msgs::LaserScan::ConstPtr& scan){
     //scan->ranges[] are laser readings

Whenever a new laser reading is published to the "/scan" topic, your callback function is called, assuming that nothing goes wrong.

You can always use commands like

rostopic info /scan
rosmsg show sensor_msgs/LaserScan

to have a detailed information about the topic and the message type.

If you read the documentation of the message type, it helps a lot. Here is the link to sensor_msgs/LaserScan Message

edit flag offensive delete link more


Sorry but I'm struggling with same problem and when I try to compile i recive error: ‘AutoExp’ has not been declared. So which library should i include or which line(s) should i write to declare "AutoExp" ?

Heartfelt thanks.

umut gravatar imageumut ( 2019-02-16 14:03:55 -0500 )edit

answered 2013-04-09 06:34:54 -0500

hesh8 gravatar image

Thanks. I figured it out yesterday. Exactly how you explained it!

edit flag offensive delete link more


could you please share how did you figure that out? what headers did you added? Thanks

Sanat gravatar imageSanat ( 2019-03-01 07:35:45 -0500 )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


Asked: 2013-04-08 08:17:35 -0500

Seen: 10,884 times

Last updated: Apr 09 '13