How to know real position of /scan ranges

for better understand of my question I am adding Image:

I put one obstacle in front of turtlebot3. I see rviz, and output of rostopic echo /scan . I also know there is ranges array with numbers they represent if obstales are there.

But, how I can know, where is position, for example, ranges[14] and ranges [48] ?
Another question is: If I have multiple robots with multiple sensors how I get informations about that sensors like range or angle ? (without internet browsing type of laser … )

Hello @PieterT-CODES,

The laser scanner data that you see in this course is produced by a planar laser scanner and is published using the LaserScan message which is defined in the sensor_msgs package. See here:

sensor_msgs/LaserScan Message

Take a moment to familiarize yourself with the elements contained in this message. You already know that this messages contains distance information as ranges. To know where each of the obstacles is you also need to know the angle of each of those range measurements, right? The tricky part is that the LaserScan message does not contain the angle of each measurement, but the start angle of the whole scan and a parameter named angle increment. This angle increment is key to calculate the angle for each range measurement.

With these parameters you can get each ray’s angle like this:
ray_angle = angle_min + (i * angle_increment)

Where i is the same index counter that you would use to dereference a specific measurement from the ranges array like so: ranges[i] .

This is how to find the position of a detected obstacle in polar coordinates in the reference frame of the laser scanner sensor.



Great answer Roberto. Thanks for your detailed explanation but after try i am still missunderstand. As you can see on the picture I got values 0.0069 - 0.0071 of angle ray is that value in radians ? and why that values are different if obstacles and robot doesn’t move? If its radian 0.006×180°/π = 0.34377467708° and angle is 0.34°, how to know where angle start ? (If i am looking on simulated turtlebot3 i need visualize where is 0° and where 34…)

The length (len) of the range is how many distance measurements have been taken. If the len is 360 then there is one measurement per degree.

The middle (range[len(range)/2]) is often zero degrees, but you can check further.

The minimum and maximum angles show where the measurements start and finish.

If it’s a full circle then the starting point is minus pi radians and the end point is plus pi radians. Converted into degrees it is -180 to +180

The following may help you convert degrees() and radians() in Python - GeeksforGeeks

1 Like

Just spotted this which also may help How to find the front position of a LaserScan

1 Like

This topic was automatically closed after 2 days. New replies are no longer allowed.