Rosanswers logo


I am using the following package: stage_ros


and the node stageros. I want to understand the topic published 'base_scan' that has a message type of 'sensor_msgs/LaserScan'


That message has a field 'float32[] ranges' but it doesn't specify the length of the array. I found the following pdf


which demostrates how to iterate the array, calculating the following indexes:

unsigned int minIndex = ceil((MIN_SCAN_ANGLE_RAD - msg->angle_min) / msg->angle_increment);
unsigned int maxIndex = ceil((MAX_SCAN_ANGLE_RAD - msg->angle_min) / msg->angle_increment);

They are using the angle_min and the angle_increment to calculate the indexes that later they will use to iterate over the array. I don't understand what those operations are doing but the final values are: minIndex = 501 and maxIndex = 580 which I think are the values that are in front of the robot.

Can someone explain this to me please?


Originally posted by andrestoga on ROS Answers with karma: 188 on 2015-04-01

Post score: 0


1 Answer 1


Rosanswers logo

In C++, variable-length ROS message types are implemented as std::vector (source). So you should be able to do

for (int i = 0; i < msg->ranges.size(); i++)
  float r = msg->ranges[i]; 


for (std::vector<float>::iterator it = msg->ranges.begin(); it != ms->ranges.end(); ++it)
  float r = *it;

Disclaimer: I haven't actually tried running this exact code.

Originally posted by Angus with karma: 438 on 2015-04-02

This answer was ACCEPTED on the original site

Post score: 4


Your Answer

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