What is the difference between two setup.bash files ?
In both wiki-ros tutorials and some ros programming textbooks, the first step is to add environment variables of ROS. To do this, we execute the following command: source /opt/ros/indigo/setup.bash
.
After that, we create a workspace, initialize this workspace, and create devel
and build
folders. After completion of these steps, we execute this command: source ~/catkin_ws/devel/setup.bash
.
I investigated these two setup.bash files. Both of them defines two environment variables CATKIN_SHELL
and _CATKIN_SETUP_DIR
. First one is to store the linux command bash
. The main purpose is to specify shell of catkin build tool. The second one is store directory of the file setup.sh
. Namely, it references to this file because all environment variables and hooks and some configuration operations are performed by sourcing this file, which is setup.sh
. Then, I decided to investigate setup.sh
files. They are also same.
In other words, these files contain same shell commands:
/opt/ros/indigo/setup.bash
~/catkin_ws/devel/setup.bash
/opt/ros/indigo/setup.sh
~/catkin_ws/devel/setup.sh
In this case, why do we source the files under the directory devel
?
Asked by gktg1514 on 2019-01-20 13:45:38 UTC
Answers
The purpose of the setup files is to provide a means to add workspaces to the environment so the packages and tools they contain are available for use.
The setup file contained in /opt/ros/$DISTRO
is associated to the corresponding ROS distro (in your case, Indigo Igloo). By sourcing it, the tools and packages included in the distro become available in the current environment and you can, for example:
-> Call any ROS tool included in the distro directly ("rostopic", for example) -> You can know build packages not included in your base distro because all the build tools and variables are part of the environment -> Any ROS tool you want to use (like rostopic) now can be used -> Some of the variables set are required for your node executables to work, including the essential "roscore"
The additional setup files are exactly the same, but each one is associated to its own workspace, which can contain any packages you want. This means that, after sourcing your base distro, you can then decide to add more workspaces to your current environment: if you source the setup.bash
inside your catkin_ws
directory, all packages contained in it become available in the current environment on top of any other you had before.
Asked by jotator on 2019-01-21 03:00:44 UTC
Comments
I don't know what is different about those files, but as for your last question (maybe the most relevant one):
This sets up your environment. You can have multiple workspaces with the same packages, with different changes
Asked by mgruhler on 2019-01-21 02:20:26 UTC
Depending on which
setup.bash
you sourced, ROS picks up packages from one or the other workspace. You can also overlay/chain workspaces, and you take the packages from the first workspace in the chain, where they are found. This is what done in the end with/opt/ros
(bottom) andcatkin_ws
(topAsked by mgruhler on 2019-01-21 02:22:12 UTC