Rosrun working but no simulation

I got the above result with no simulation result. Could anyone enlighten me as to why i see no rosrun error and no simulation result?

Hi @tesfayewakessa,

I’m been trying to reproduce the error, but I couldn’t. In my case, it is working as expected.

If the problem persists, could you copy the content from the notebook and paste it in the again?

The content is the following:

#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
import time
import math

class MoveBB8():
    def __init__(self):
        self.bb8_vel_publisher = rospy.Publisher('/cmd_vel', Twist, queue_size=1)
        self.cmd = Twist()
        self.ctrl_c = False
        self.rate = rospy.Rate(10)
    def publish_once_in_cmd_vel(self):
        This is because publishing in topics sometimes fails the first time you publish.
        In continuous publishing systems, this is no big deal, but in systems that publish only
        once, it IS very important.
        while not self.ctrl_c:
            connections = self.bb8_vel_publisher.get_num_connections()
            if connections > 0:
                rospy.loginfo("Cmd Published")
    def shutdownhook(self):
        # works better than the rospy.is_shut_down()
        self.ctrl_c = True

    def stop_bb8(self):
        rospy.loginfo("shutdown time! Stop the robot")
        self.cmd.linear.x = 0.0
        self.cmd.angular.z = 0.0

    def move_x_time(self, moving_time, linear_speed=0.2, angular_speed=0.2):
        self.cmd.linear.x = linear_speed
        self.cmd.angular.z = angular_speed
    def move_square(self):
        i = 0
        while not self.ctrl_c and i < 4:
            # Move Forward
            self.move_x_time(moving_time=4.0, linear_speed=0.2, angular_speed=0.0)
            # Turn, the turning is not affected by the length of the side we want
            self.move_x_time(moving_time=4.0, linear_speed=0.0, angular_speed=0.2)
            i += 1
        rospy.loginfo("######## Finished Moving in a Square")
if __name__ == '__main__':
    rospy.init_node('move_bb8_test', anonymous=True)
    movebb8_object = MoveBB8()
    except rospy.ROSInterruptException:

Please let me know in case the problem persists.


Hello The construct,

First of all, thank you for this excellent content. I am facing trouble that the simulation is not running when I execute rosrun move_bb8_pkg, I got the following error msg. I will appreciate if anyone can help me regarding this

Hello @Aminul,

It seems to be a syntax error in your code.
It says “line 9”

Do you mind to share it with us? So we can check it together


Thank you, arruda.
I was able to figure out the mistake I did, now it is working.
Thanks again for the great content.

1 Like

Hey @tesfayewakessa
Could you pls share what you did to fix this problem. I’m having exactly the same issue.


Hi @Cobra711 ,

it seems the problem is that you have to add the following content, known as shebang, as the first line of your script:

#! /usr/bin/env python