0
$\begingroup$

Rosanswers logo

I'm learning ROS for Turtlebot3, and am getting an error message that appears to tell me that I missed a compilation or build step. Perhaps I am missing an environment variable. Here are the key steps:

$ catkin_create_pkg wanderbot rospy geometry_msgs sensor_msgs

$ source ~/catkin_ws/devel/setup.bash 
pitosalas@ubuntu:~/catkin_ws/wanderbot/src$ ./redgreen.py 
from: can't read /var/mail/geometry_msgs.msg
./redgreen.py: line 6: syntax error near unexpected token `('
./redgreen.py: line 6: `cmd_vel_pub = rospy.Publisher('cmd_vel', Twist, queue_size=1) #<1>'

And looking for the missing geometry_msgs.msg:

pitosalas@ubuntu:/$ ls -l /opt/ros/kinetic/share/geometry_msgs/
total 12
drwxr-xr-x 2 root root 4096 Jul 23 18:39 cmake
drwxr-xr-x 2 root root 4096 Jul 23 18:39 msg
-rw-r--r-- 1 root root  794 Sep 30  2016 package.xml

And inside you can see the Twist.msg:

ls -l /opt/ros/kinetic/share/geometry_msgs/msg/
total 116
-rw-r--r-- 1 root root 119 Sep 30  2016 Accel.msg
-rw-r--r-- 1 root root  83 Sep 30  2016 AccelStamped.msg
-rw-r--r-- 1 root root 330 Sep 30  2016 AccelWithCovariance.msg
-rw-r--r-- 1 root root 124 Sep 30  2016 AccelWithCovarianceStamped.msg
-rw-r--r-- 1 root root 235 Sep 30  2016 Inertia.msg
-rw-r--r-- 1 root root  30 Sep 30  2016 InertiaStamped.msg
-rw-r--r-- 1 root root 367 Sep 30  2016 Point32.msg
-rw-r--r-- 1 root root  84 Sep 30  2016 Point.msg
-rw-r--r-- 1 root root  98 Sep 30  2016 PointStamped.msg
-rw-r--r-- 1 root root 107 Sep 30  2016 Polygon.msg
-rw-r--r-- 1 root root 104 Sep 30  2016 PolygonStamped.msg
-rw-r--r-- 1 root root  96 Sep 30  2016 Pose2D.msg
-rw-r--r-- 1 root root  85 Sep 30  2016 PoseArray.msg
-rw-r--r-- 1 root root 119 Sep 30  2016 Pose.msg
-rw-r--r-- 1 root root  79 Sep 30  2016 PoseStamped.msg
-rw-r--r-- 1 root root 323 Sep 30  2016 PoseWithCovariance.msg
-rw-r--r-- 1 root root 122 Sep 30  2016 PoseWithCovarianceStamped.msg
-rw-r--r-- 1 root root 108 Sep 30  2016 Quaternion.msg
-rw-r--r-- 1 root root 117 Sep 30  2016 QuaternionStamped.msg
-rw-r--r-- 1 root root 118 Sep 30  2016 Transform.msg
-rw-r--r-- 1 root root 337 Sep 30  2016 TransformStamped.msg
-rw-r--r-- 1 root root 115 Sep 30  2016 Twist.msg
-rw-r--r-- 1 root root  82 Sep 30  2016 TwistStamped.msg
-rw-r--r-- 1 root root 326 Sep 30  2016 TwistWithCovariance.msg
-rw-r--r-- 1 root root 124 Sep 30  2016 TwistWithCovarianceStamped.msg
-rw-r--r-- 1 root root 382 Sep 30  2016 Vector3.msg
-rw-r--r-- 1 root root 103 Sep 30  2016 Vector3Stamped.msg
-rw-r--r-- 1 root root 117 Sep 30  2016 Wrench.msg
-rw-r--r-- 1 root root  85 Sep 30  2016 WrenchStamped.msg
pitosalas@ubuntu:/$ 

Here's the full source of red green.py:

#example 1
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist

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

red_light_twist = Twist() #<2>
green_light_twist = Twist()
green_light_twist.linear.x = 0.5 #<3>

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) #<4>
  else:
    cmd_vel_pub.publish(red_light_twist)
  # BEGIN PART_1
  if rospy.Time.now() > light_change_time: #<5>
    driving_forward = not driving_forward
    light_change_time = rospy.Time.now() + rospy.Duration(3)
  # END PART_1
  rate.sleep() #<6>
# END ALL

And here's the environment (updated, moved wanderbot under src as @gvdhoorn said)

pitosalas@ubuntu:~/catkin_ws$ tree .
.
├── build
│   ├── beginner_tutorials
│   │   ├── catkin_generated
│   │   │   ├── installspace
│   │   │   │   ├── beginner_tutorialsConfig.cmake
│   │   │   │   ├── beginner_tutorialsConfig-version.cmake
│   │   │   │   └── beginner_tutorials.pc
│   │   │   ├── ordered_paths.cmake
│   │   │   ├── package.cmake
│   │   │   ├── pkg.develspace.context.pc.py
│   │   │   ├── pkg.installspace.context.pc.py
│   │   │   └── stamps
│   │   │       └── beginner_tutorials
│   │   │           ├── package.xml.stamp
│   │   │           └── pkg.pc.em.stamp
│   │   ├── CMakeFiles
│   │   │   ├── CMakeDirectoryInformation.cmake
│   │   │   ├── progress.marks
│   │   │   ├── roscpp_generate_messages_cpp.dir
│   │   │   │   ├── build.make
│   │   │   │   ├── cmake_clean.cmake
│   │   │   │   ├── DependInfo.cmake
│   │   │   │   └── progress.make
│   │   │   ├── roscpp_generate_messages_eus.dir
│   │   │   │   ├── build.make
│   │   │   │   ├── cmake_clean.cmake
│   │   │   │   ├── DependInfo.cmake
│   │   │   │   └── progress.make
│   │   │   ├── roscpp_generate_messages_lisp.dir
│   │   │   │   ├── build.make
│   │   │   │   ├── cmake_clean.cmake
│   │   │   │   ├── DependInfo.cmake
│   │   │   │   └── progress.make
│   │   │   ├── roscpp_generate_messages_nodejs.dir
│   │   │   │   ├── build.make
│   │   │   │   ├── cmake_clean.cmake
│   │   │   │   ├── DependInfo.cmake
│   │   │   │   └── progress.make
│   │   │   ├── roscpp_generate_messages_py.dir
│   │   │   │   ├── build.make
│   │   │   │   ├── cmake_clean.cmake
│   │   │   │   ├── DependInfo.cmake
│   │   │   │   └── progress.make
│   │   │   ├── rosgraph_msgs_generate_messages_cpp.dir
│   │   │   │   ├── build.make
│   │   │   │   ├── cmake_clean.cmake
│   │   │   │   ├── DependInfo.cmake
│   │   │   │   └── progress.make
│   │   │   ├── rosgraph_msgs_generate_messages_eus.dir
│   │   │   │   ├── build.make
│   │   │   │   ├── cmake_clean.cmake
│   │   │   │   ├── DependInfo.cmake
│   │   │   │   └── progress.make
│   │   │   ├── rosgraph_msgs_generate_messages_lisp.dir
│   │   │   │   ├── build.make
│   │   │   │   ├── cmake_clean.cmake
│   │   │   │   ├── DependInfo.cmake
│   │   │   │   └── progress.make
│   │   │   ├── rosgraph_msgs_generate_messages_nodejs.dir
│   │   │   │   ├── build.make
│   │   │   │   ├── cmake_clean.cmake
│   │   │   │   ├── DependInfo.cmake
│   │   │   │   └── progress.make
│   │   │   ├── rosgraph_msgs_generate_messages_py.dir
│   │   │   │   ├── build.make
│   │   │   │   ├── cmake_clean.cmake
│   │   │   │   ├── DependInfo.cmake
│   │   │   │   └── progress.make
│   │   │   ├── std_msgs_generate_messages_cpp.dir
│   │   │   │   ├── build.make
│   │   │   │   ├── cmake_clean.cmake
│   │   │   │   ├── DependInfo.cmake
│   │   │   │   └── progress.make
│   │   │   ├── std_msgs_generate_messages_eus.dir
│   │   │   │   ├── build.make
│   │   │   │   ├── cmake_clean.cmake
│   │   │   │   ├── DependInfo.cmake
│   │   │   │   └── progress.make
│   │   │   ├── std_msgs_generate_messages_lisp.dir
│   │   │   │   ├── build.make
│   │   │   │   ├── cmake_clean.cmake
│   │   │   │   ├── DependInfo.cmake
│   │   │   │   └── progress.make
│   │   │   ├── std_msgs_generate_messages_nodejs.dir
│   │   │   │   ├── build.make
│   │   │   │   ├── cmake_clean.cmake
│   │   │   │   ├── DependInfo.cmake
│   │   │   │   └── progress.make
│   │   │   └── std_msgs_generate_messages_py.dir
│   │   │       ├── build.make
│   │   │       ├── cmake_clean.cmake
│   │   │       ├── DependInfo.cmake
│   │   │       └── progress.make
│   │   ├── cmake_install.cmake
│   │   ├── CTestTestfile.cmake
│   │   └── Makefile
│   ├── catkin
│   │   └── catkin_generated
│   │       └── version
│   │           └── package.cmake
│   ├── catkin_generated
│   │   ├── env_cached.sh
│   │   ├── generate_cached_setup.py
│   │   ├── installspace
│   │   │   ├── env.sh
│   │   │   ├── setup.bash
│   │   │   ├── setup.sh
│   │   │   ├── _setup_util.py
│   │   │   └── setup.zsh
│   │   ├── order_packages.cmake
│   │   ├── order_packages.py
│   │   ├── setup_cached.sh
│   │   └── stamps
│   │       └── Project
│   │           ├── interrogate_setup_dot_py.py.stamp
│   │           ├── order_packages.cmake.em.stamp
│   │           ├── package.xml.stamp
│   │           └── _setup_util.py.stamp
│   ├── CATKIN_IGNORE
│   ├── catkin_make.cache
│   ├── CMakeCache.txt
│   ├── CMakeFiles
│   │   ├── 3.5.1
│   │   │   ├── CMakeCCompiler.cmake
│   │   │   ├── CMakeCXXCompiler.cmake
│   │   │   ├── CMakeDetermineCompilerABI_C.bin
│   │   │   ├── CMakeDetermineCompilerABI_CXX.bin
│   │   │   ├── CMakeSystem.cmake
│   │   │   ├── CompilerIdC
│   │   │   │   ├── a.out
│   │   │   │   └── CMakeCCompilerId.c
│   │   │   └── CompilerIdCXX
│   │   │       ├── a.out
│   │   │       └── CMakeCXXCompilerId.cpp
│   │   ├── clean_test_results.dir
│   │   │   ├── build.make
│   │   │   ├── cmake_clean.cmake
│   │   │   ├── DependInfo.cmake
│   │   │   └── progress.make
│   │   ├── cmake.check_cache
│   │   ├── CMakeDirectoryInformation.cmake
│   │   ├── CMakeError.log
│   │   ├── CMakeOutput.log
│   │   ├── CMakeRuleHashes.txt
│   │   ├── CMakeTmp
│   │   ├── download_extra_data.dir
│   │   │   ├── build.make
│   │   │   ├── cmake_clean.cmake
│   │   │   ├── DependInfo.cmake
│   │   │   └── progress.make
│   │   ├── doxygen.dir
│   │   │   ├── build.make
│   │   │   ├── cmake_clean.cmake
│   │   │   ├── DependInfo.cmake
│   │   │   └── progress.make
│   │   ├── feature_tests.bin
│   │   ├── feature_tests.c
│   │   ├── feature_tests.cxx
│   │   ├── Makefile2
│   │   ├── Makefile.cmake
│   │   ├── progress.marks
│   │   ├── run_tests.dir
│   │   │   ├── build.make
│   │   │   ├── cmake_clean.cmake
│   │   │   ├── DependInfo.cmake
│   │   │   └── progress.make
│   │   ├── TargetDirectories.txt
│   │   └── tests.dir
│   │       ├── build.make
│   │       ├── cmake_clean.cmake
│   │       ├── DependInfo.cmake
│   │       └── progress.make
│   ├── cmake_install.cmake
│   ├── CTestTestfile.cmake
│   ├── gtest
│   │   ├── CMakeFiles
│   │   │   ├── CMakeDirectoryInformation.cmake
│   │   │   ├── gtest.dir
│   │   │   │   ├── build.make
│   │   │   │   ├── cmake_clean.cmake
│   │   │   │   ├── DependInfo.cmake
│   │   │   │   ├── depend.make
│   │   │   │   ├── flags.make
│   │   │   │   ├── link.txt
│   │   │   │   ├── progress.make
│   │   │   │   └── src
│   │   │   ├── gtest_main.dir
│   │   │   │   ├── build.make
│   │   │   │   ├── cmake_clean.cmake
│   │   │   │   ├── DependInfo.cmake
│   │   │   │   ├── depend.make
│   │   │   │   ├── flags.make
│   │   │   │   ├── link.txt
│   │   │   │   ├── progress.make
│   │   │   │   └── src
│   │   │   └── progress.marks
│   │   ├── cmake_install.cmake
│   │   ├── CTestTestfile.cmake
│   │   └── Makefile
│   ├── Makefile
│   ├── test_results
│   └── wanderbot
│       ├── catkin_generated
│       │   ├── installspace
│       │   │   ├── wanderbotConfig.cmake
│       │   │   ├── wanderbotConfig-version.cmake
│       │   │   └── wanderbot.pc
│       │   ├── ordered_paths.cmake
│       │   ├── package.cmake
│       │   ├── pkg.develspace.context.pc.py
│       │   ├── pkg.installspace.context.pc.py
│       │   └── stamps
│       │       └── wanderbot
│       │           ├── package.xml.stamp
│       │           └── pkg.pc.em.stamp
│       ├── CMakeFiles
│       │   ├── CMakeDirectoryInformation.cmake
│       │   ├── geometry_msgs_generate_messages_cpp.dir
│       │   │   ├── build.make
│       │   │   ├── cmake_clean.cmake
│       │   │   ├── DependInfo.cmake
│       │   │   └── progress.make
│       │   ├── geometry_msgs_generate_messages_eus.dir
│       │   │   ├── build.make
│       │   │   ├── cmake_clean.cmake
│       │   │   ├── DependInfo.cmake
│       │   │   └── progress.make
│       │   ├── geometry_msgs_generate_messages_lisp.dir
│       │   │   ├── build.make
│       │   │   ├── cmake_clean.cmake
│       │   │   ├── DependInfo.cmake
│       │   │   └── progress.make
│       │   ├── geometry_msgs_generate_messages_nodejs.dir
│       │   │   ├── build.make
│       │   │   ├── cmake_clean.cmake
│       │   │   ├── DependInfo.cmake
│       │   │   └── progress.make
│       │   ├── geometry_msgs_generate_messages_py.dir
│       │   │   ├── build.make
│       │   │   ├── cmake_clean.cmake
│       │   │   ├── DependInfo.cmake
│       │   │   └── progress.make
│       │   ├── progress.marks
│       │   ├── sensor_msgs_generate_messages_cpp.dir
│       │   │   ├── build.make
│       │   │   ├── cmake_clean.cmake
│       │   │   ├── DependInfo.cmake
│       │   │   └── progress.make
│       │   ├── sensor_msgs_generate_messages_eus.dir
│       │   │   ├── build.make
│       │   │   ├── cmake_clean.cmake
│       │   │   ├── DependInfo.cmake
│       │   │   └── progress.make
│       │   ├── sensor_msgs_generate_messages_lisp.dir
│       │   │   ├── build.make
│       │   │   ├── cmake_clean.cmake
│       │   │   ├── DependInfo.cmake
│       │   │   └── progress.make
│       │   ├── sensor_msgs_generate_messages_nodejs.dir
│       │   │   ├── build.make
│       │   │   ├── cmake_clean.cmake
│       │   │   ├── DependInfo.cmake
│       │   │   └── progress.make
│       │   └── sensor_msgs_generate_messages_py.dir
│       │       ├── build.make
│       │       ├── cmake_clean.cmake
│       │       ├── DependInfo.cmake
│       │       └── progress.make
│       ├── cmake_install.cmake
│       ├── CTestTestfile.cmake
│       └── Makefile
├── devel
│   ├── env.sh
│   ├── lib
│   │   └── pkgconfig
│   │       ├── beginner_tutorials.pc
│   │       └── wanderbot.pc
│   ├── setup.bash
│   ├── setup.sh
│   ├── _setup_util.py
│   ├── setup.zsh
│   └── share
│       ├── beginner_tutorials
│       │   └── cmake
│       │       ├── beginner_tutorialsConfig.cmake
│       │       └── beginner_tutorialsConfig-version.cmake
│       └── wanderbot
│           └── cmake
│               ├── wanderbotConfig.cmake
│               └── wanderbotConfig-version.cmake
└── src
    ├── beginner_tutorials
    │   ├── CMakeLists.txt
    │   ├── include
    │   │   └── beginner_tutorials
    │   ├── package.xml
    │   └── src
    ├── CMakeLists.txt -> /opt/ros/kinetic/share/catkin/cmake/toplevel.cmake
    └── wanderbot
        ├── CMakeLists.txt
        ├── package.xml
        └── src
            ├── redgreen.py
            └── rospy

77 directories, 227 files

I won't give all the steps to get there to save space, unless I need to to further clarify.


Originally posted by pitosalas on ROS Answers with karma: 628 on 2017-07-26

Post score: 0


Original comments

Comment by gvdhoorn on 2017-07-26:
Why is the wanderbot package outside your src space? That won't work (well it can, but let's not complicate things).

Put it in catkin_ws/src, run catkin_make (or catkin build), source your devel/setup.bash and try again.

Also, check what you have on line 6 of redgreen.py.

Comment by pitosalas on 2017-07-26:
Thanks @gvdhoorn... I made the suggested corrections, and updated the original question above. Then run it with cd ~./catkin_ws/src/wanderbot/src; ./redgreen.py and got the same error. Any other suggestion would be appreciated!

Comment by jayess on 2017-07-26:
It looks like you're not finding geometry_msgs in /var/mail (from: can't read /var/mail/geometry_msgs.msg). Where is it installed on your system? I'm on Ubuntu 14.04 and using Indigo, and it's installed at /opt/ros/indigo/share/geometry_msgs.

Comment by pitosalas on 2017-07-26:
@jayess, thanks, it seems to be there. Also I've updated the original question with that detail and some more. Thanks for sticking with me!

Comment by jayess on 2017-07-27:
Make sure to post the entire contents of your source. I ran the previous edit of your code and didn't get any errors. I ran the current version and got your errorl

Comment by pitosalas on 2017-07-27:
yes. I guess I was trying to unclutter the question before I had any idea that that comment was the culprit!

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I think I found the problem: the first line of the .py file was a #comment... before the shebang line. I think thats what messed everything up!


Originally posted by pitosalas with karma: 628 on 2017-07-27

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by jayess on 2017-07-27:
If this solved your question you should mark it as correct.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.