Unit 6: MicroProject - Odometry TurtleBot

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:

  1. Go forward till you find a wall
  2. 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? :slight_smile:

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

So, I achieved to escape the maze just modifying a little bit the code…what I’ve done is looking/turning not at 90º but at 45º degrees, so at every curve needs to process twice to change it direction (45 + 45 degrees).

Anyway, I know that this is not the best solution, so if anyone has any idea of how to improve it please just comment. I will start now the course of “ROS basics in 5 days”, i guess it will help me to find a more coherent solution that takes in to account the odometry of the robot.

Also I do not understand why when i ask the robot to rotate 45º, it turns 315º instead, it’s a little bit silly problem but i don’t know either why it is doing that.

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 chosen path is TURN RIGHT")
            self.rc.rotate(-45)           
        else:
            print ("The chosen path is TURN LEFT")
            self.rc.rotate(45)

counter = 0

while counter < 10:   

    step1 = GetOutofHere()
    step1.go_ahead()

    step2 = GetOutofHere()
    step2.have_a_look()

    counter += 1

Hello @flarribagil,

The problem is actually not with the rotate() function but with the move_straight() function. When moving the robot forward, the robot has a small deviation to the right side, which causes some orientation issues This could be improved by adding and odometry control feedback, but it is out of the scope of this course (which is meant to teach the basic concepts of Python). You will be able to learn more about how to do this when you complete the ROS Basics Course. In any case, we will consider improving this move_straight() function so that it performs some kind of control feedback.

As for the rotation issue (sometimes it rotates 315º degrees instead of 45º), I’ve been doing some tests but couldn’t find a solution yet. Unfortunately, I’ve not been able to reproduce this behavior on a consistent basis in order to fix it properly. I will let you know once I have something.

Best,

I’ve been playing with Unit 6 as well and have noticed some issues with the turns. I was trying to square the robot with the maze by getting a read_laser_full() and then rotating the robot to so the shortest ray is either directly to the left or right of the robot. It seems like read_laser_full() is too noisy of a signal to to this correctly. Running it multiple times in the same positions gives me different readings. Also, sometimes rc.rotate(-90) causes the robot to rotate a counter clockwise 270 degrees instead of clockwise 90 degrees.

Thanks,
-W

Hi @wes.dautremont,

Welcome to our community.

Yes, this is what Alberto mentioned when he says it rotates 315º degrees instead of 45º, but we couldn’t yet reproduce it in a consistent way.

In any case, thanks for reminding us of this.