Ask Your Question
0

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

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

Hi,

I am using the following package: stage_ros

http://wiki.ros.org/stage_ros

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

http://docs.ros.org/api/sensor_msgs/h...

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

http://www.cim.mcgill.ca/~yiannis/417...

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?

Best,

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

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

Angus gravatar image

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

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

or

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 2,309 times

Last updated: Apr 02 '15