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

reading message once subscribed to a topic

asked 2013-02-06 23:47:49 -0600

Sentinal_Bias gravatar image

updated 2013-02-07 00:37:19 -0600

Hi i am new to ROS, i have done the tutorials. But i am a bit unsure on how to read messages (in code)

If i have a ros node which has subscribed to a topic /LaserScan see bellow std_msgs/Header header float32 angle_min float32 angle_max float32 angle_increment float32 time_increment float32 scan_time float32 range_min float32 range_max float32[] ranges float32[] intensities

And I am in my call back function, def callback_lidar(data):

how do i access an individual variables, like the list ranges

would i do array = data.ranges?

I cant create the node an test it out since the lidar node requires a connected lidar.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2013-02-07 00:17:52 -0600

dornhege gravatar image

Yes, exactly like you said: data.ranges.

edit flag offensive delete link more
1

answered 2013-02-07 00:18:16 -0600

updated 2013-02-07 00:41:34 -0600

This sample could should work.

void mapper_direct::laserCallback(const sensor_msgs::LaserScan::ConstPtr& msg) { float theta = msg -> angle_min; for(int i = 0; i < (int)(msg -> ranges.size()); i++) { // ROS_INFO("Treating %dth laser from scan with value", i,msg->range[i]);

} }

edit flag offensive delete link more

Comments

1

Not really as it looks like he's doing python. Also the ROS_INFO is missing %f and there's an empty float r.

dornhege gravatar image dornhege  ( 2013-02-07 00:32:01 -0600 )edit

If its for python then its different but for C++ this should work ..

ayush_dewan gravatar image ayush_dewan  ( 2013-02-07 00:43:06 -0600 )edit

Question Tools

Stats

Asked: 2013-02-06 23:47:49 -0600

Seen: 1,974 times

Last updated: Feb 07 '13