Environment Setup¶
Automated Environment Setup¶
We have set up a number of scripts to assist you in setting up your computer, after you have installed ROS. Here is a link to the scripts folder Scripts and use the following credentials
username= "relative_nav"
password= "hex"
cd ~
sudo apt update
mkdir scripts
cd Downloads
ls
mv scripts.git<rest of file name>.zip ../scripts
cd ../scripts
unzip scripts.git<rest of file name>
cd installation
./toplevel
- N, you are not a cave computer
- Y, you want to copy the bashrc file
- your ROS_MASTER_URI is local (no quotes)
- your magicc username is firstname_lastname (your actual first name and last name)
This script installs git, vim, a whole bunch of environment customizations, ROS, all the ROS packages needed to run the relative nav stack, Google Chrome, Sublime, QtCreator, Spotify, and the Numix Custom theme. It can take more than hour, depending mainly on your internet connection, because it downloads several gigabytes of data over the course of installation.
Then to apply the changes you just made to your environment,
cd ~
source ~/.bashrc
Environment Variables¶
One of the things that can often go wrong in getting programs to work properly is the "environment variables." These variables are sort of like global variables in scope of the entire operating system, that tell it where to find different libraries, how commands in the terminal get interpreted, the name of your system, and so on. Windows and Mac both actually have environment variables as well, but it's not often that you have to manage them.
Let's look at our environment variables, just for fun. Open up a terminal and type
printenv
printenv | grep ROS
To change environment variables (which shouldn't be done on a regular basis, except for perhaps ROS_MASTER_URI and ROS_IP), type
export <VARIABLE>=<new_value>
export ROS_MASTER_URI=http://localhost:11311
The .bashrc file¶
Every time you open a terminal window, it runs a special script called your "bashrc" This script often calls other scripts such as the rosrc file we use in the lab
Let's look at our bashrc
vim ~/.bashrc
It's sort of confusing to read the file, but there are a few key words you should know.
alias <command>='<replacement command>'
alias grep='grep --color=auto'
Another keyword you should probably know is
source <external script file.sh>
It's important to note that the .bashrc file is loaded when a new terminal window is opened. That means that if you make changes to the bashrc, then you either need to open a new terminal to see the changes, or type
source ~/.bashrc
The full version of the bashrc we start with in the MAGICC Lab can be found here: Link. Don't be afraid if you don't understand everything that is going on.
Colors in the terminal¶
Also, if you want to change your command prompt to something other than the default, look into changing line 117 on the linked file. The PS1 variable defines the prompt color. The actual colors are defined by the code in brackets. For example
\[\033[01;32m\] -> Means that whatever follows is bold green
\[\033[01;34m\] -> is bold blue and
\[\033[00;33m\] -> is normal yellow
The "01;" defines bold or not, and the "3*m" defines the actual color. So, if we look at line 117
117. export PS1='\[\033[01;32m\]\u\[\033[01;34m\] \w\[\033[00;33m\]$(__git_ps1)\[\033[01;32m\] \$\[\033[00m\] '
Let's work through it.
export PS1= -> means we are setting the PS1 variable.
'\[\033[01;32m\]\u -> sets the username in the bash prompt to be bold green
\[\033[01;34m\]\w -> sets the current path to be bold blue
\[\033[00;33m\]$(__git_ps1) -> means that the git status variable (set when inside a git directory) is yellow
[\033[01;32m\]\$ -> means that the dollar sign (or # when acting as root) is green
\[\033[00m\]' -> means the text you type will be the default text color.
```
Here are the color definitions for reference.
```bash
[00;30m] = normal black [01;30m] = bold black
[00;31m] = normal red [01;31m] = bold red
[00;32m] = normal green [01;32m] = bold green
[00;33m] = normal yellow [01;33m] = bold yellow
[00;34m] = normal blue [01;34m] = bold blue
[00;35m] = normal purple [01;35m] = bold purple
[00;36m] = normal cyan [01;36m] = bold cyan
[00;37m] = normal white [01;37m] = bold white
Other Environment Files¶
There are other files we use in the MAGICC lab that function similarly to the .bashrc. These files all live in the home directory, right next to the bashrc and are also run every time the terminal window is opened.
.rosrc¶
We noticed that we were often changing ROS variables, such as the workspace, ROS_IP and ROS_MASTER_URI. As a result, we created our own file, called .rosrc, and added a line to the .bashrc that just sources the .rosrc file. This helped to separate the ROS environment from the rest of the operating system environment.
The .rosrc file looks as follows:
1. source set_ros_master local
2. export ROSLAUNCH_SSH_UNKNOWN=1
3.
4. # ROS_WORKSPACE
5. source /opt/ros/indigo/setup.bash
6. #source ~/rel_nav_ws/devel/setup.bash
The second line is necessary for remote launching of ROS nodes. Not something you need to worry about now.
Lines 4-6 define the workspace. By default, the toplevel ROS workspace sourced. Whenever you make a new workspace, you need to come in and "source" it so ROS can find the packages you've put in it. For example, if I were to make a new workspace called "obstacle" I would have an additional line in my .rosrc that looked like this.
6. source ~/obstacle/devel/setup.bash
source ~/.bashrc
sbashrc
.rosalias¶
This is a file that I sometimes have on my systems where I have programmed several aliases specific to ROS. I usually reference it from my .rosrc file. Here is a copy of my ~/.rosalias file
1. alias fixCMake="rm CMakeLists.txt && cp /opt/ros/indigo/share/catkin/cmake/toplevel.cmake CMakeLists.txt"
2.
3. alias printROS="printenv | grep ROS"
The second prints out all the ROS-related environment variables
.vimrc¶
One last file is the .vimrc file. Whenever vim opens, it first goes through the .vimrc file, and loads a couple of defaults, such as syntax highlighting for files, tab and space defaults, etc...
Here is a copy of my ~/.vimrc file
"Convenient tab settings
set tabstop=4
set shiftwidth=2
set softtabstop=2
set expandtab
"Sets proper syntax highlighting for .launch, .rosrc, and .rosalias files
au BufRead,BufNewFile *.launch set filetype=xml
au BufRead,BufNewFile *.rosrc set filetype=sh
au BufRead,BufNewFile *.rosalias set filetype=sh