Real Robot Lab -Robot doesnt move continuously


The turtlebot3 in the real robot lab moves for like 4 seconds and ends the session. When i run the program again, it starts moving/turning from were it stopped and after about 4 secs, the session ends again. I dont know what could be the problem. I would appreciate any help to make the robot move continuously until i press ctrl-c, thank you. My code is as follows;

#! /usr/bin/env python

import rospy

from sensor_msgs.msg import LaserScan

from geometry_msgs.msg import Twist

import time

class robotsquare(object):

    def __init__(self):

        self._laser_sub = rospy.Subscriber('/scan', LaserScan, self.callback)

        self._laser_scan = LaserScan()

        self._cmd_pub = rospy.Publisher('/cmd_vel', Twist, queue_size = 1)

        self._move_twist = Twist()


    def callback(self,msg):

        self._laser_scan = msg

        print('Value at 0 degrees: ')


        print('Value at 90 degrees: ')


        print('Value at 180 degrees: ')


        print('Value at 360 degrees: ')


        print('Value at 719 degrees: ')



        return self._laser_scan

    def laser_scan_move(self):

        if self._laser_scan.ranges[360] > 0.6:

            self._move_twist.linear.x = 0.17

            self._move_twist.angular.z = 0

if self._laser_scan.ranges[360] < 0.5:

            self._move_twist.linear.x = 0

            self._move_twist.angular.z = 0

        if self._laser_scan.ranges[360] < 0.5 and self._laser_scan.ranges[0] < 1.8:

            self._move_twist.linear.x = 0

            self._move_twist.angular.z = 0.45




if __name__ == '__main__':


    robotsquarenode_object = robotsquare()

    rate = rospy.Rate(2)

while not rospy.is_shutdown():                         # Create a loop that will go until someone stops the program execution



Hi Elena,

What do you mean by the session ends? Are you losing connection to the robot? You can check by echoing the scan.

As for the movement, you have to publish the velocities with a high rate, and if you want it to stop by pressing ctrl-c, you have to implement it in your code.

Can you share some screenshots of the issue? Is your program running when your “session ends”?

Hello @roalgoal,

I can’t connect to the robot now to take screenshots. Let me explain the issue differently. When I ran the python program on the simulation, the robot keeps moving along the wall until something stops it or I press control c. Now with the real robot, when I run the python program, the robot would move or turn for a few seconds and then the program ends. In the real environment, I had to run the python program more than 4 times before the robot could move along the walls and form a complete square.

Please I would like to know why the python program ends on its own instead of waiting for me to stop it just like in the simulation. Thank you.

Hi Elena,

I think the difference might be this distinction:

In the simulation, the robot executes a twist message continuously until you publish another one, and would generally not stop once it starts moving unless you publish a stop message.
But in a real robot it executes a twist message then stops. So to keep it moving, you need to keep publishing the message.

That said, if your subscriber is working properly and your logic is correct, there should be some twist message sent to the robot at regular intervals (every time the subscriber “calls” the callback) so it really should not stop.

Also, I don’t understand what you mean by “the program ends on its own”.

  • Did you mean the whole program exits?
  • Do you know for sure that the program exited (what’s the evidence) or is it just that the robot stopped moving?

As far as I can see in your logic, the program should not exit on its own unless there was an error somewhere.

Finally, I find this part of your program unnecessary:

rate = rospy.Rate(2)
while not rospy.is_shutdown():                         # Create a loop that will go until someone stops the program execution



The rospy.spin() you have in your __init__ should do the job.

Thank you so much @bayodesegun

You’re welcome. I have updated the post. Please review it.

thank you so much @bayodesegun

@bayodesegun yes the whole program exits so i would have to run “rosrun” again for it to start moving from where it stopped then it happens again.

@bayodesegun for the evidence, i would have booked a session and sent you a screenshot but i need that session for running the services and actions today. If i can get extra session, then i can book one now and send a screenshot of it. Thank you.

Hi @Yelaina, does your program make the turtlebot in the simulation move continuously?

I’ve given you an extra session.


Hello @roalgoal,

Thank you. I tried logging to my session on the real lab and I have been refreshing it since but its not loading. See the picture below. Please can this be checked and the session restored? Thank you.

Done. Please let me know when you plan on doing your next session and we will do it together to make sure it works.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.