0
$\begingroup$

Rosanswers logo

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.


Originally posted by Sentinal_Bias on ROS Answers with karma: 418 on 2013-02-07

Post score: 0

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

Yes, exactly like you said: data.ranges.


Originally posted by dornhege with karma: 31395 on 2013-02-07

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

Rosanswers logo

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]);

} }


Originally posted by ayush_dewan with karma: 1610 on 2013-02-07

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by dornhege on 2013-02-07:
Not really as it looks like he's doing python. Also the ROS_INFO is missing %f and there's an empty float r.

Comment by ayush_dewan on 2013-02-07:
If its for python then its different but for C++ this should work ..

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.