roslaunch
Last updated
Last updated
This note is trying to answer the following two questions.
What happens after I type roslaunch
in 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.
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, ls
cat
commands are in /bin
directory; python
command is under directory/usr/bin
.
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 which
command. For example, if you trywhich python
in the terminal, it will return to you the search result of the command python
. You can also do this for the which
command itself. Try it.
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 roslaunch
, rqt_graph
, etc.
Go ahead and open the roslaunch
script. What? Only two lines of code?
Yes, it is. roslaunch
was installed as a Python 2.7 library in the system.
Then the following question is, how could python know where to import roslaunch
?
Check the first directory in the PYTHONPATH env!
/home/hteng/catkin_ws/devel/lib/python2.7/dist-packages
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
and rosrun
.
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!