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

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

Hi,

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
9

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;

scanSub=nh.subscribe<sensor_msgs::LaserScan>("/scan",10,&AutoExp::processLaserScan,this);

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

Comments

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 image umut  ( 2019-02-16 14:03:55 -0500 )edit
0

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

Comments

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

Sanat gravatar image Sanat  ( 2019-03-01 07:35:45 -0500 )edit

Question Tools

1 follower

Stats

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

Seen: 15,827 times

Last updated: Apr 09 '13