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

How to interpret and use the values of the message type 'sensor_msgs/LaserScan'?

asked 2015-04-01 17:06:15 -0600

updated 2022-03-20 10:16:37 -0600

lucasw gravatar image


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?


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-04-02 09:48:41 -0600

Angus gravatar image

updated 2015-04-02 11:23:41 -0600

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.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-04-01 17:06:15 -0600

Seen: 2,691 times

Last updated: Apr 02 '15