ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
8

Sourcing from multiple workspaces

asked 2015-03-26 09:24:59 -0500

Karnivaurus gravatar image

I am just running through the ROS tutorials for Indigo (running on Ubuntu 14.04). In my .bashrc file, I have added the line source ~/catkin_ws/devel/setup.bash, to source the setup file. If I then run echo $ROS_PACKAGE_PATH, it gives me /home/karnivaurus/catkin_ws/src:/opt/ros/indigo/share:/opt/ros/indigo/stacks.

However, I also have downloaded another package, located in ~/ROS/src. I now want to source the setup file for this new package, so that ROS knows to search there if I reference this package. Therefore, I add another line to .bashrc, source ~/ROS/devel/setup.bash.

The problem is that if I now run echo $ROS_PACKAGE_PATH again, it gives me /home/karnivaurus/ROS/src:/opt/ros/indigo/share:/opt/ros/indigo/stacks. So, it seems that the second of the two lines in .bashrc overrides the first, and the package created in the tutorial can no longer be found by ROS.

So the only solution I have come up with is to have all my packages in the same workspace. But this means that I cannot run the tutorial whilst also playing around with some other packages I've downloaded. Is it normal to just have one workspace which contains all packages you have built / downloaded (i.e. other than the ones that come with ROS by default)? Or is there another solution to this?

I have inspected the setup.bash files for both these workspace, and they are identical:

#!/usr/bin/env bash
# generated from catkin/cmake/templates/setup.bash.in

CATKIN_SHELL=bash

# source setup.sh from same directory as this file
_CATKIN_SETUP_DIR=$(builtin cd "`dirname "${BASH_SOURCE[0]}"`" > /dev/null && pwd)
. "$_CATKIN_SETUP_DIR/setup.sh"
edit retag flag offensive close merge delete

Comments

2

@jarvisschultz's answer is correct, but you can also pass the --extend argument to the setup.bash file and it will only add to the environment rather than set the environment. This can be dangerous though, and I highly recommend you do proper workspace chaining.

William gravatar image William  ( 2015-03-26 13:24:48 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
9

answered 2015-03-26 11:28:03 -0500

When you first run catkin_make in the root of a workspace, the devel directory gets created and the setup.bash file inside of that dir is designed to "overlay" the workspace on top of all other workspaces that have already been sourced. It is quite common to have many "active" workspaces at a single time. In your case, I'd do the following:

  1. In a new terminal run source ~/catkin_ws/devel/setup.bash
  2. cd into ~/ROS/ and run rm -r devel/ to remove the devel directory
  3. run catkin_make from the ~/ROS/ directory (this will re-create devel/)
  4. Then source ~/ROS/devel/setup.bash

Your environment should now have the ~/ROS/ workspace overlayed on the ~/catkin_ws/ workspace. Read more here: http://wiki.ros.org/catkin/Tutorials/...

edit flag offensive delete link more

Comments

I also need to remove the build folder. Under step 2: rm -r build

raarenst gravatar image raarenst  ( 2015-10-19 05:36:22 -0500 )edit

But isn't that dangerous? For example if two different workspaces have similar packages. How does ROS know from which workspace it should run a launchfile?

Behsad Ghanei gravatar image Behsad Ghanei  ( 2016-05-25 07:56:24 -0500 )edit

You need to be careful to source devel/setup.bash for the correct workspace.

joq gravatar image joq  ( 2016-05-25 10:38:52 -0500 )edit
3

Will this work if I have one workspace that I built with catkin_make and the other one (the ~/ROS/ one) with catkin build?

Alex_Nitsch gravatar image Alex_Nitsch  ( 2017-02-21 04:45:02 -0500 )edit

It seems not to, I did it with a source installation of moveit, and it does not work.

Danfoa gravatar image Danfoa  ( 2019-01-08 07:23:49 -0500 )edit

I attempted to use this method with "build" and "make" to no avail. When I did both with "build" it worked like a charm.

JackB gravatar image JackB  ( 2020-10-01 11:47:04 -0500 )edit

Question Tools

3 followers

Stats

Asked: 2015-03-26 09:24:59 -0500

Seen: 17,403 times

Last updated: Mar 26 '15