I add my answer and also I would like to know how can improve my code, hoping to get some feedback from the community.
Also I would like to leave a question.
is there any code where for navigation use use some kind of control system like PID??
from robot_control_class import RobotControl
robotControl = RobotControl()
def move_robot():
right = robotControl.get_laser(10)
front = robotControl.get_laser(360)
left = robotControl.get_laser(709)
print ("distance from right {}", right)
print ("distance from front {}", front)
print ("distance from left {}", left)
diff_distance_right_left = right-left
if front == float("inf") and right == float("inf") and left == float("inf"):
robotControl.stop_robot()
print ("I'm free")
return False
elif front <= 1.2 and diff_distance_right_left >= 0.5:
robotControl.stop_robot()
print ("Roatating 45 degrees")
robotControl.rotate(45)
elif front <= 1.2 and diff_distance_right_left <= 0.5:
robotControl.stop_robot()
print ("Roatating -45 degrees")
robotControl.rotate(-45)
elif front > 1.2:
robotControl.move_straight()
elif diff_distance_right_left >= 0: # this is when it get stuck
robotControl.stop_robot()
print ("Roatating 15 degrees")
robotControl.rotate(15)
elif diff_distance_right_left <= 0: # this is when it get stuck
robotControl.stop_robot()
print ("Roatating -30 degrees")
robotControl.rotate(-30)
return True
while move_robot():
print("I just want to get out of here")
robotControl.stop_robot()