=====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
- When an object is too far from the scanner
- 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