Test_while issue

well, I was a bit lazy to change, and create a new name for a file, so i wrote this program as test_if.py

from robot_control_class import RobotControl

rc = RobotControl()

a = rc.get_laser(360) 

while a > 1.0:

    rc.move_straight()

    a = rc.get_laser(360) 

    print(rc.get_laser(360))

rc.stop_robot()

the output:
user:~/catkin_ws/src/robot_control$ python test_if.py
[INFO] [1621110856.458113, 0.000000]: Robot Turtlebot…
[INFO] [1621110856.459138, 0.000000]: Checking Laser…
[INFO] [1621110856.493895, 1582.505000]: Checking Laser…DONE
1.5578563213348389
0.5408013463020325
0.20212474465370178

that is it kept banging into the wall,
but if I ran the solution program, it runs perfectly, can someone explain the error I may have committed

Hi @18kev99 ,

Welcome to our community.

Ideally you should call rc.move_straight() after checking the value returned by rc.get_laser(360), instead of move first and only then check the value returned.

Also, for printing the value returned by the laser, it would be better to print (a) instead of print(rc.get_laser(360))

So, to summarize, please do something like:

a = rc.get_laser(360) 
if a < LIMITE_DISTANCE:
  rc.move_straight()