Comment on page
This note is trying to answer the following two questions.
- What happens after I type
roslaunchin the terminal?
- How could the Linux know the commands and help me auto-complete it?
We will introduce some basics about environment variables in Linux and the concept of search path.
Three important PATH env in ROS
First of all, no matter what kind of command you type in the terminal, it must exist in one of the directories indicated in the PATH environment variable. This is where the Linux terminal will search first. For example,
catcommands are in
pythoncommand is under directory
To auto-complete, the system must know all possible commands given the existing characters you type in the terminal. This is somehow like to complete a English word given the first X characters, where you can search in a dictionary for all possible solutions. Likewise, Linux can search all executables in the directories listed in PATH env. Once it finds there is a unique solution, it will help you complete it.
To find the exact path for each command you type in, you can use
whichcommand. For example, if you try
which pythonin the terminal, it will return to you the search result of the command
python. You can also do this for the
whichcommand itself. Try it.
user@hostname$ which python
Next, we will talk about how ROS handles the search path.
For all ROS-related commands, in order to run in the terminal, it has to be an Linux executable. This is an universal rule in Linux with no exceptions. Note that the first directory listed in PATH env is
/opt/ros/kinetic/bin. You got it! This is where all the ROS commands exist. Open the folder and you will find python scripts like
Go ahead and open the
roslaunchscript. What? Only two lines of code?
# Software License
Yes, it is.
roslaunchwas installed as a Python 2.7 library in the system.
Then the following question is, how could python know where to import
Check the first directory in the PYTHONPATH env!
Here we go! Open this folder and you will see all the ROS-related python programs.
The third environment variable we would like to talk about is the ROS_PACKAGE_PATH. This is where ROS will search when you are typing a package name right after
roslaunch turtlebot_br [press Tab, then it becomes]
How could ROS know all the possible package names? I believe now you can guess the answer. Yes, it will search all the directories listed in the ROS_PACKAGE_PATH.
That's all for today! Have fun!