Python Course: Infinite Loop of Turtlebot after stop 1 meter from the wall - Labyrinth - Maze

Hello guys I am facing a problem in the code I developed for the turtlebot get out the maze: When it stops 1 meter in front of the first wall and need to turn 90 degrees to keep following. It stops and entry in an infinite loop without keep the next forward move. So how can I fix this issue. My code is below:

from robot_control_class import RobotControl

import time

robotcontrol = RobotControl()

class MoveRobot:
    def __init__(self, motion, clockwise, speed, time):
        self.robot = RobotControl()
        self.motion = motion
        self.clockwise = clockwise
        self.speed = speed
        self.time = time
        self.time_turn = 2
        self.full_laser = self.robot.get_laser_full()
        self.laser = self.robot.get_laser(360)

    def out_maze(self):

        corner = 0

        while (corner < 2):
            while (self.laser > 1):
                self.laser = self.robot.get_laser(360)
                print("Current distance to  this wall is %f meters" % self.laser)


    def door_maze(self):

        door = 0
        while (self.laser > 1):
            self.laser = self.robot.get_laser(360)
            print("Current distance to wall is %f meters" % self.laser)

    def move_x_seconds(self):


    def move_straight_time(self):
        self.robot.move_straight_time(self.motion, self.speed, self.time)
    def move_straight(self):
    def turn(self):
        self.robot.turn(self.clockwise, self.speed, self.time_turn)
    def stop_robot(self):

move_inside = MoveRobot('forward', 'clockwise', 0.75, 2)

move_outside = MoveRobot('forward', 'counterclockwise', 0.5, 2)

move_horizon = MoveRobot()
1 Like

Hello @marcusvini178,

Could you please send me your code so that I can test it? This way it will be easier to debug possible issues in your code. Please send it to


I have tested your code and found that you are basically moving without using the data from the laser. You have to use the laser to detect in which direction there is the largest ray, and then move the robot towards that direction. Try to implement the following thing:

  1. Create a loop where
  2. At each step get the laser data
  3. Then identify at which angle you have the largest distance
  4. Then turn the robot towards that direction (with a small amount of going forward)

Let me know which result you get

Hi @marcusvini178,

Iā€™ve just answered your e-mail.

1 Like

Thanks very much @albertoezquerro on friday I tried again and again with my friendā€¦he is an mechatronic enginner and he helped me. Together we developed a code for the robot get out he maze. It lasted sometimes to turn and went near the wall instead always go straight sometimesā€¦then we really worked hard to make it get out this kind of trapā€¦successfully. But I will see your solution code in order to compare and improve our code.
My friend also developed a good code if you want to see for a class that need to pass the argument for the robot turn (I think in linux course module). Because in your solution code there was a kind of error if the user did not pass the argument. If you want I can send youā€¦
Wellā€¦I also am having another issue in The class 4: Understanding ROS topics: subscriber.
My code is right I think because I compared to yoursā€¦in solutionā€¦the code which makes the publishes the age for the robot. The launch works, however when I try to listen that topic with echo function it returns me the following message of error:
the rosdep view is empty: call ā€˜sudo rosdep initā€™ and ā€˜rosdep updateā€™
ERROR: Cannot load message class for [agerobotpublisher/Age]. Are your messages built?
Well could I send in your email my WS for you try to find what is wrong. I really tried all day long but I could not repair by myself to listen the Age.msg: years, months and days arguments.
Thanks in advance

Hi @marcusvini178,

You need to source your workspace in every shell so that they can detect the new message. Remember the command to source your workspace is:

source ~/catkin_ws/devel/setup.bash

You have probably compiled your custom message and launched your script in one shell with success because you have sourced the workspace. But then, when you try to do the rostopic echo from a different shell, you also need source your workspace there so that it can detect your new message. Otherwise you will get an error like the one you mention.


1 Like