Hi everyone! I’ve just started learning programming with the course of Python 3 for Robotics.
Currently i am working with the “Unit 6: MicroProject”, trying that the TurtleBot escapes of the maze.
For that, i’ve thought in the next logic scheme:
- Go forward till you find a wall
- Look left / right and orientate the robot to the higher distance
And repeat the process till the robot is outside the maze.
The program compiles without getting any error, but the robot does not rotate 90 degrees every time but a little bit more, so that at the end the robot doesn’t move in an orthogonal way.
Does anyone knows an easy way to correct that for a noob like me?
I write here my spaghetti code, please feel free to correct me, any comment is appreciated!
from robot_control_class import RobotControl class GetOutofHere: def __init__(self): self.rc = RobotControl() def go_ahead(self): laserFront = self.rc.get_laser(360) while laserFront > 1: self.rc.move_straight() laserFront = self.rc.get_laser(360) self.rc.stop_robot() print ("Measured distance to wall:", laserFront) def have_a_look(self): laserLeft = self.rc.get_laser(180) print ("The distance measured in the left side is: ", laserLeft) laserRight = self.rc.get_laser(540) print ("The distance measured in the right side is: ", laserRight) if laserLeft > laserRight: print ("The choosen path is TURN RIGHT") self.rc.rotate(270) else: print ("The choosen path is TURN LEFT") self.rc.rotate(90) counter = 0 while counter < 5: step1 = GetOutofHere() step1.go_ahead() step2 = GetOutofHere() step2.have_a_look() counter += 1