I am an IT admin learning python/ROS and when i hit this script I came up with the following:
from robot_control_class import RobotControl
rc = RobotControl()
laserlist = rc.get_laser_full()
biggest = float(0)
spud = laserlist[0]
for laser in laserlist:
if laser != spud:
distance = float(laser)
if biggest < distance:
biggest = distance
print("new longer distance is: " + str(biggest))
else:
print(str(laser) + "Was less than existing distance: " + str(biggest))
else:
print("no distance found")
print("The biggest distance found was: "+ str(biggest))
I couldnât figure out how to test for âINFâ without finding a potato or âspudâ laser with a bad value and using that as a !=.
When I looked further on an saw the MUCH simpler result I ran the example code feeling very silly⌠and it came back as â('The higher value in the list is: ', inf)â which, while mechanically true is not useful.
I reset my environment to default and got"The biggest distance found was: 2.92194676399" on my own test and got an inf from the provided code.
Did i miss something about putting the bot in a box of walls?
Youâre right, you need to consider the inf value, which represents points where the laser sensor is not seeing anything beyond 30 meters (the range of the sensor). Actually the biggest technically.
However, the biggest âusefulâ concrete distance is actually the biggest number that is not an inf, like you said.
Thanks Bayodesegun. I am considering subscribing to the Robot Ignite materials and so far so good!
I figured out thats where the value was coming from,'that is why I made the spud value. The problem I had was how do exclude this as a valid value without finding a known version first? float(laser) = Ănf didnt seem to do anything.
Even the example code has the same problem of returning the biggest inf result, which as described above is correct, but not the desired information for this part of the course.
HI, going further on that, I want just to get the distance value which is not infiniteâŚ
from robot_control_class import RobotControl
ob1 = RobotControl()
distances = ob1.get_laser_full()
max_value = 0
for ite in distances:
if (ite > max_value) and (ite != inf) :
max_value = ite
print (max_value)
I got an error :slight_smile:
Traceback (most recent call last):
File "test_for.py", line 10, in <module>
if (ite > max_value) and (ite != inf) :
NameError: name 'inf' is not defined