Ask Your Question
0

turtle in turtlebot_gazebo is not moving

asked 2016-09-07 08:41:30 -0500

Cayero gravatar image

updated 2016-09-07 09:08:19 -0500

Hi I'm new in ROS, and I have a problem with turtlebot_gazebo.

Here I got the code which I would like to use to move the robot.

import rospy
from geometry_msgs.msg import Twist

cmd_vel_pub = rospy.Publisher('cmd_vel', Twist, queue_size=1)
rospy.init_node('red_light_green_light')

red_light_twist = Twist()
green_light_twist = Twist()
green_light_twist.linear.x =5

driving_forward = False
light_change_time = rospy.Time.now()
rate = rospy.Rate(10)

while not rospy.is_shutdown():
             if driving_forward:
                        cmd_vel_pub.publish(green_light_twist)
             else:
                        cmd_vel_pub.publish(red_light_twist)
             if light_change_time > rospy.Time.now():
                        driving_forward = not driving_forward
                        light_change_time = rospy.Time.now() + rospy.Duration(3)
             rate.sleep()

This is the code from 'Programming robots with ROS' book.

Then in new terminal I use that command

./red_light_green_light.py cmd_vel:=cmd_vel_mux/input/teleop

and again in new terminal I'm running the code

rosrun wanderbot red_light_green_light.py

after that in the previous terminal i got this

shutdown request: new node registered with the same name
Traceback (most recent call last):
 File "./red_light_green_light.py", line 25, in <module>
 rate.sleep()
     File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/timer.py", line 99, in
    sleep
        sleep(self._remaining(curr_time))
 File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/timer.py", line 157, in 
sleep
        raise rospy.exceptions.ROSInterruptException("ROS shutdown request")
rospy.exceptions.ROSInterruptException: ROS shutdown request

The turtle in gazebo is not moving. Could someone give some advice? I would be really grateful.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-09-03 08:57:30 -0500

in this line :

if light_change_time > rospy.Time.now():
                        driving_forward = not driving_forward

should be: if light_change_time < rospy.Time.now():

By the way, the author fixed the code here:

https://github.com/osrf/rosbook/blob/...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-09-07 06:34:37 -0500

Seen: 337 times

Last updated: Sep 07 '16