0
$\begingroup$

Rosanswers logo

the last few times I have done anything w ROS while doing beginning tutorials, I just say 'roscore' and it seems to all run fine, but now im watching a video and it seems like he's saying I need to do the setup.bash steps every time I want to use ros.

  1. is it necessary to do the setup.bash steps every time? 2.if so, why have I been able to use turtlesim and other things just running roscore?

edit: I went into .bashrc and added source ~/catkin_ws/devel/setup.bash thinking that was what I was missing but then realized the one I was thinking of was already there, called 'source /opt/ros/kinetic/setup.bash'

  1. is that the one I need to run every time or should I also add the catkin setup to run every time as well?
  2. also, do I still now need to roscd everytime to enter the workspace?

Originally posted by moonspacedancer on ROS Answers with karma: 123 on 2017-08-28

Post score: 0


Original comments

Comment by billy on 2017-08-28:
I can provide my experience. I also used to think that it wasn't needed and it worked for a awhile. Then I made some change and it stopped working. But I lost two days before answers.ros helped me find out what I was doing wrong. I still break rule by putting it in ~/.bashrc instead of typing it.

Comment by moonspacedancer on 2017-08-28:
Hmm, interesting. I added it in my ~/.bashrc now but still interested in the logic. like is it because the setup.bash is connected w catkin and and roscore is a seperate entity? that's my guess rn

Comment by jayess on 2017-08-28:
What setup.bash are you referring to? The one that's in your /opt/ros/<distro> folder, the one in your catkin workspace devel folder, or both?

Comment by moonspacedancer on 2017-08-28:
@jayess, I just edited my question to include that.

Comment by jayess on 2017-08-28:
I deleted my answer so that I don't add to the noise and confusion with overlaying and setting of the env vars with setup.bash

Comment by jayess on 2017-08-28:
This may be helpful: https://answers.ros.org/question/188309/what-does-source-command-actually-do/?answer=188313#post-id-188313

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

You need to source the setup.bash for the workspace you're using every time you open a new shell. It sets up the environment variables that ROS needs to find packages, nodes, and launch files.

This can be manual or automatic, and what you choose to do depends on your workflow and your personal preferences.

If you only have a single workspace ( ie catkin_ws folder ), adding source ~/catkin_ws/devel/setup.bash to your bashrc will automatically source the setup for that workspace every time you open a new terminal.

If the environment variables that ROS uses conflict with some other software that you use, if you delete your workspace, or if you switch between multiple workspaces frequently, you probably don't want to source the setup.bash automatically. Some users in this situation just source the setup.bash manually, but I've seen a lot of users create some kind of shell function or alias to make sourcing their setup.bash quicker.

For example, in my bashrc I have defined several functions:

# personal robot project
function dagny {
    source ~/dagny/devel/setup.bash
    cd ~/dagny
}

# job-related ROS workspace
function junior {
    source ~/junior/devel/setup.bash
}

# dedicated workspace for diagnostics development
function diagnostics {
    source ~/diagnostics/devel/setup.bash
}

Now when I open a new terminal, there's no ROS environment loaded, but I can quickly load one by typing dagny, junior or diagnostics instead of typing the full path to the setup file.

shell functions are quite powerful and you can have them run basically any shell command you want. There's a lot more that you can do with shell functions in general, but that's a bit beyond the scope of this forum.


Originally posted by ahendrix with karma: 47576 on 2017-08-28

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by moonspacedancer on 2017-08-30:
Thank you, great answer @ahendrix. Just still unsure about the difference between the workspace setup and the ROS setup.

Comment by ahendrix on 2017-08-30:
/opt/ros/<distro> is a workspace too! It just happens that it only has the packages installed through apt-get.

$\endgroup$

Your Answer

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