Handle inf valve from LaserScan -- Wall Following ROSject

=====I have found solution, but posting in case anyone else runs into same issue=======

I am having an issue handling the case where the LaserScan returns the value inf

As I understand it, there are two instances when the LaserScan will return inf

  1. When an object is too far from the scanner
  2. When an object is too close to the scanner

The second case is what I am running into. When my robot touches the wall (typically form not turning quickly enough when faced with a new wall) the LaserScan value on the right side becomes inf

This results in unexpected behavior. When it recieves inf, my wall following logic determines that it is too far (makes sense infinity is greater than 0.3). This results in a negative feedback loop that drives the robot closer to the wall that it is already touching.

What I want is a way to logically determine if the scan result is inf. If I knew the range of the scanner, I could check for larger values, but I would prefer a more general approach.

Attempts like if (scanRight == inf) result in syntax error

======== Solution =================
How I got to it
I used rosmsg show LaserScan

  • This showed me the data type of ranges was float32
    So I googled “python float32 inf”
  • From here I found learned that the value can be accessed by casting ‘inf’ to float

Final solution:
if(scanRight == float('inf'):
# logic here

1 Like

Hi, welcome to the community, and thank you for this great explanation!

I agree, this can happen if the robot is practically against the wall, it will return an inf value.

One question, did you find this inf situation in the simulation, or the real robot?

@roalgoal Thanks!
In answer to your question, I encountered this in the simulation. I am still tweaking my code before running on the real robot. I assume the real robot’s sensor will behave similarly. (If not then the robustness won’t hurt me)

1 Like