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

What does environment set up do

asked 2016-08-10 20:47:02 -0600

alienmon gravatar image

updated 2016-08-10 20:48:33 -0600

(This is a basic quest. I'm new to ROS.)

I know that environment set up is setting up the environment, but what environment? What is actually set up there? Any example?...(1)

From this ros tutorial page:

If roscd says similar to roscd: No such package/stack 'beginner_tutorials' , you will need to source the environment setup file like you did at the end of the create_a_workspace tutorial:

$ cd ~/catkin_ws $ source devel/setup.bash $ roscd beginner_tutorials

Why do I have to setup again if previously I have set it up?...(2)

Before setup , roscd beginner_tutorials can't be executed, but after set up, it can. What does set up actually do here?...(3)

Lastly, when installing ROS according to this Ros installation page ,we set up the environment for ros. My quests are: Again, what environment is set up/what is actually being set up here?...(4)

Why for this one we don't need to set up the ros env everytime open a new session, unlike the previous one where we have to set up again eventhough we once set it up?...(5)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
7

answered 2016-08-11 01:51:43 -0600

Felix Duvallet gravatar image

updated 2016-08-11 06:34:32 -0600

The primary thing that happens when you source your catkin workspace's devel/setup.bash file is that you are setting environment variables.

For example, you'll notice a difference in many environment variables before & after sourcing the setup file:

  • ROS_PACKAGE_PATH: This tells ROS where to find packages, so that rosrun <pkg> <node> actually works.
  • CMAKE_PREFIX_PATH: This tells the compiler a bunch of stuff, including where to find the libraries defined in your package.
  • LD_LIBRARY_PATH: This is used at execution time to dynamically load shared libraries.
  • PYTHONPATH: This tells python where to look for any python modules defined in your package.

(There are others, there are just the important ones).

As an example, this is my ROS_PACKAGE_PATH before and after sourcing the setup file in some random catkin workspace:

$ cd /path/to/my/catkin_ws
$ echo $ROS_PACKAGE_PATH 
/opt/ros/indigo/share:/opt/ros/indigo/stacks
$ source devel/setup.bash
$ echo $ROS_PACKAGE_PATH
/path/to/my/catkin_ws/src:/opt/ros/indigo/share:/opt/ros/indigo/stacks

Note the addition of my catkin workspace's src/ directory to the ROS_PACKAGE_PATH. This enables me to run any nodes I have defined in my workspace, otherwise only the system-installed packages are available. (Side note: /opt/ros/<distro>/ basically acts as one big catkin workspace too.)

Normally, you always source the global /opt/ros/<distro>/setup.bash every time you open a terminal because it's in your .bashrc file. However, since new terminal sessions don't carry over environment variables, you need to source your workspace's setup file again each time you open a new session.

If you do not want to have to source the workspace setup file yourself each time you open a new terminal, you can always add it to your .bashrc file:

echo "source /path/to/your/workspace/devel/setup.bash" >> ~/.bashrc

Obviously this only works if you have a single catkin workspace.

edit flag offensive delete link more

Comments

1

Very helpful answer! Technically the LD_LIBRARY_PATH is not for any compiler, it's for used by ld.so at execution time to dynamically load shared libraries. Without it, you could have a piece of code that compiles but doesn't run.

jarvisschultz gravatar image jarvisschultz  ( 2016-08-11 06:06:32 -0600 )edit

That situation would depend on things like ldconfig and /etc/ld.so.cache, and the -rpath flag of gcc/g++ (see this tutorial, step 4). The CMAKE_PREFIX_PATH is like what you described.

jarvisschultz gravatar image jarvisschultz  ( 2016-08-11 06:11:41 -0600 )edit

It is important for catkin/CMake to be able to find ROS libraries, and it is controlled by the setup.bash scripts.

jarvisschultz gravatar image jarvisschultz  ( 2016-08-11 06:12:22 -0600 )edit
1

Thanks for the comment, you're absolutely right. I've updated the answer. I think the link to the shared libraries tutorial is still helpful as a comment.

Felix Duvallet gravatar image Felix Duvallet  ( 2016-08-11 06:35:13 -0600 )edit

So everytime a new terminal is opened, it automatically source what's in bashrc file. And /opt/ros/<distro>/setup.bash is in bashrc file, that's why I don't have to source it everytime i open terminal. While source devel/setup.bash is not, and that's why I have to source evertytime i open new term.

alienmon gravatar image alienmon  ( 2016-08-14 20:26:34 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2016-08-10 20:47:02 -0600

Seen: 2,464 times

Last updated: Aug 11 '16