0
$\begingroup$

Rosanswers logo

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.


Originally posted by Ahmed_Desoky on ROS Answers with karma: 23 on 2021-01-22

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by Roberto Z. with karma: 500 on 2021-01-22

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by Roberto Z. on 2021-03-15:
@Ahmed_Desoky did this answer your question?

Comment by Ahmed_Desoky on 2022-03-01:
Thanks a lot. This is the answer.

Comment by Ahmed_Desoky on 2022-07-13:
@Roberto Z. Why do not you use the angle_max ? Why do you use only the angle_min?

$\endgroup$

Your Answer

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