Ask Your Question
0

[ROS2] Sourcing colcon-generated setup.bash includes ROS1 catkin workspace

asked 2020-06-28 12:26:20 -0500

renangm gravatar image

Hello,

I have experience with ROS1, and now I am learning ROS2. I installed ROS2 eloquent through the debian repos, set up my workspace with colcon following the tutorials, and now I am in the "Writing a simple publisher and subscriber (Python)" tutorial. When running the publisher node, I get the error:

AttributeError: type object 'type' has no attribute '_TYPE_SUPPORT' This might be a ROS 1 message type but it should be a ROS 2 message type. Make sure to source your ROS 2 workspace after your ROS 1 workspace.

According to google, this is due to the PYTHONPATH environment variable. However, I noticed the error only occurs when sourcing the "install/setup.bash" script generated by the "colcon build" command. Investigating the colcon-generated script, I find it is also pointing to my CATKIN workspace (I have ROS melodic installed):

# source chained prefixes
# setting COLCON_CURRENT_PREFIX avoids determining the prefix in the sourced script
COLCON_CURRENT_PREFIX="/opt/ros/melodic"
_colcon_prefix_chain_bash_source_script "$COLCON_CURRENT_PREFIX/local_setup.bash"
# setting COLCON_CURRENT_PREFIX avoids determining the prefix in the sourced script
COLCON_CURRENT_PREFIX="/home/renan/catkin_ws/devel"
_colcon_prefix_chain_bash_source_script "$COLCON_CURRENT_PREFIX/local_setup.bash"
# setting COLCON_CURRENT_PREFIX avoids determining the prefix in the sourced script
COLCON_CURRENT_PREFIX="/opt/ros/eloquent"
_colcon_prefix_chain_bash_source_script "$COLCON_CURRENT_PREFIX/local_setup.bash"

Commenting the " COLCON_CURRENT_PREFIX="/opt/ros/melodic" " and " COLCON_CURRENT_PREFIX="/home/renan/catkin_ws/devel" " lines, and resourcing the install/setup.bash file, the python publisher node runs fine.

What could be the problem here? I don't know if this is typical for ROS2, but it seems to be causing confusion with the message definitions in ROS2.

Thanks in advance.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2020-06-30 15:11:11 -0500

renangm gravatar image

I believe I identified the issue.

First, as gvdhoorn mentioned, the melodic paths are being added by colcon build to the install/setup files. If ROS1 is sourced, then the melodic paths are embedded in the CMAKE_PREFIX_PATH variable. If I unset this variable before cleaning and rebuilding the colcon workspace, only the eloquent path remains in the install/setup files.

Second, sourcing melodic also adds its paths to the PYTHONPATH variable, which produces the AttributeError exception. In my case, this variable is only used by ROS and ROS2, so I can safely unset and reset it by sourcing the eloquent setup scripts. This is also fixed by opening a new terminal.

By resetting these variables, I can keep sourcing ROS1 or ROS2 in .bashrc, commenting the one I don't want to run.

edit flag offensive delete link more
0

answered 2020-06-29 03:32:46 -0500

gvdhoorn gravatar image

Would you happen to "auto-source" your ROS Melodic installation (fi in your .bashrc)?

edit flag offensive delete link more

Comments

The first time I tried to run the nodes yes, melodic was auto-sourced before eloquent in .bashrc. But the problem persisted even after commenting the melodic auto-sourcing.

renangm gravatar image renangm  ( 2020-06-29 20:06:42 -0500 )edit

I reinstalled everything (eloquent and dependency packages) and now weirdly the problem seems to be gone. The colcon-generated install/setup.bash does not index melodic or its environment. Still if possible I would like to understand the problem...

renangm gravatar image renangm  ( 2020-06-29 20:09:56 -0500 )edit

The first time I tried to run the nodes yes, melodic was auto-sourced before eloquent in .bashrc. But the problem persisted even after commenting the melodic auto-sourcing.

commenting is not enough.

The setup.* files in your Colcon workspace cache certain environment variables. The Melodic paths get embedded in them -- as you already found when looking at the install/setup.bash file.

You would have to clean your Colcon workspace (remove the build and install directories), make sure to not auto-source any more, start a new terminal and then do a clean build of your Colcon workspace.

After that, the 'problem' should be gone.

gvdhoorn gravatar image gvdhoorn  ( 2020-06-30 02:06:16 -0500 )edit

I think I identified the issue. Will post as a separate answer, thanks!

renangm gravatar image renangm  ( 2020-06-30 15:10:02 -0500 )edit

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2020-06-28 12:26:20 -0500

Seen: 34 times

Last updated: Jun 30