osrf / rosbook

Example code to accompany the book Programming Robots with ROS
Apache License 2.0
476 stars 237 forks source link

Trouble running red_light_green_light.py #11

Closed wgh210 closed 7 years ago

wgh210 commented 8 years ago

Hello, When I try to run red_light_green_light.py I get a few errors.

line 3: import: command not found from: can't read /var/mail/geometry_msgs.msg /home/william/catkin_ws/src/wanderbot_ws/src/wander/red_light_green_light.py: line 6: syntax error near unexpected token (' /home/william/catkin_ws/src/wanderbot_ws/src/wander/red_light_green_light.py: line 6:cmd_vel_pub = rospy.Publisher('cmd_vel', Twist, queue_size=1) #<1>'

I am trying to learn ROS and any help would be greatly appreciated!

wgh210 commented 8 years ago

Also if I run roswtf I get:

Static checks summary:

Found 1 error(s).

ERROR Not all paths in PYTHONPATH [/home/william/catkin_ws/devel/lib/python2.7/dist-packages:/opt/ros/indigo/lib/python2.7/dist-packages] point to a directory:

gerkey commented 8 years ago

I think that the problem is this first line in that file:

# BEGIN ALL

Can you try removing that line and report back on whether it works? As an alternative, you should be able to run the program with that line intact if you explicitly invoke Python, e.g.:

python red_light_green_light.py

That line is part of the special mark-up used to include the code chunk-by-chunk in the book. Wherever it appears as the first line in a file, we should move it to come after the shebang line that declares the interpreter. For mark-up purposes, we could add a duplicate shebang line after, e.g.:

#!/usr/bin/env python
# BEGIN ALL
#!/usr/bin/env python

It looks a little odd, but should work for both use cases (running the code or including it in the book).

wgh210 commented 8 years ago

Thanks for the reply!

I tried removing the

# BEGIN ALL

and re-ran. I did not encounter an error, but did not see any movement out of the turtlebot.

Same for solutions 2 and 3. As a side note, I am able to teleop the turtlebot.

abeldavid commented 8 years ago

For the turtlebot to move , it has to be given the following cmd : rosrun wanderbot red_light_green_light.py cmd_vel:=cmd_vel_mux/input/teleop

gbiggs commented 8 years ago

Are you reporting a correction or are you having a problem with the example?

abeldavid commented 8 years ago

Reporting a correction to wgh210

**commented on Mar 15

Thanks for the reply!

I tried removing the

BEGIN ALL

and re-ran. I did not encounter an error, but did not see any movement out of the turtlebot.

Same for solutions 2 and 3. As a side note, I am able to teleop the turtlebot.**

codebot commented 7 years ago

Agreed. This was a very unfortunate typo.

On Thu, Oct 6, 2016 at 9:05 PM, mjr419 notifications@github.com wrote:

There is a typo in the book this code comes from. Find the > and switch it to <.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/osrf/rosbook/issues/11#issuecomment-252148425, or mute the thread https://github.com/notifications/unsubscribe-auth/AFBR2nRibH1GIySj4TcZaVgN6mW_8Y_jks5qxcT2gaJpZM4Heh9w .

codebot commented 7 years ago

Corrected in updated text.