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

How to get obstacle distance and angle by using lidar

asked 2021-01-22 08:38:33 -0500

Ahmed_Desoky gravatar image

updated 2021-01-22 09:23:28 -0500

how to get obstacle distance and angle from mobile robot by using lidar?

I have a small mobile robot with a Lidar A1M8.. I would like to process the data coming from the liar raw data \scan or from gmapping package, to use this data to make a path planning algorithm like "Genetic Algorithm". So, I do not want to use move_base package.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-01-22 10:01:16 -0500

Roberto Z. gravatar image

If you have a ROS driver for the laser scanner on your robot, then you should also have laser scan messages published on a specific topic name. Find out the topic and then look for the message type. Normally planar laser scans are published using the LaserScan message which is defined in the sensor_msgs package. See here:

sensor_msgs/LaserScan Message

You will see that the message does not contain the angle of each measurement, but the start angle of the scan and the angle increment.

Taking everything into account, these are the main steps to get the distance and angle for each ray in a LaserScan message:

  • Create a ros node that subscribes to your laser scanner topic
  • Specify a callback function to run when the subscriber receives a message
  • Upon incoming messages, iterate over all laser rays
  • Skip laser rays with the value 'inf' (rays that didn't hit anything)
  • To have your measurements in polar coordinates (distance and angle w.r.t. your device):

    Use the fields angle_min, the start angle of the scan [rad] and angle_increment, the angular distance between measurements [rad], to get each's ray angle, like this:
    ray_angle = angle_min + (i * angle_increment) , where i is the loop counter that change with each iteration of the loop

    Get the distance of the corresponding ray from the data field ranges[i]

This is how to find the position of a detected obstacle in polar coordinates in the reference frame of your sensor. Most probably you will also want to transform these values to get cartesian coordinates from polar ones. Also consider if you want to transform these into the global frame or not.

edit flag offensive delete link more

Comments

1

@Ahmed_Desoky did this answer your question?

Roberto Z. gravatar image Roberto Z.  ( 2021-03-15 05:11:24 -0500 )edit

Thanks a lot. This is the answer.

Ahmed_Desoky gravatar image Ahmed_Desoky  ( 2022-03-01 04:58:41 -0500 )edit

@Roberto Z. Why do not you use the angle_max ? Why do you use only the angle_min?

Ahmed_Desoky gravatar image Ahmed_Desoky  ( 2022-07-13 05:15:30 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2021-01-22 08:38:33 -0500

Seen: 2,188 times

Last updated: Jan 22 '21