Prerequisite handbook for GAAS: Linux tutorial

Here are the prerequisite knowledges of using Linux operating system, this handbook only includes the skills used in the tutorial of GAAS

We suggest developers to install GAAS mirror to use the project:

The Linux shell tutorial

It's necessary to be able to use the Linux shell proficiently since the PX4 and ROS are based on Linux operating system. Here is the terminal interface of the Linux shell:

Similar as Windows, the file system of Linux is organized as a directory tree, a typical structure of Linux file system is shown as follows:

/ is the entry point of the Linux file system,there will be many other files and folders under /:

With the authority of the Linux file system, by defalut every user can only own the full access of their own Home folder, the path of a user's Home folder is /home/user

For example, the Home folder path of the user gi is/home/gi, it can be replaced with ~, which means/home/gi/GAAS can be replaced with ~/GAAS

./ represents the current directory. If you would like to execute a binary file in the current folder, the path should start with ./ . For example, there is a binary file helloin the current folder, it will be executed with the following command:

./hello

Similarly,../ represents the parent folder.

Here is a list of useful commands:

man shows the user manual,you can use man command to show the manual of a command

ls lists the contents of your current working directory, usels -l to show them as a list;

cd changes the current working directory to another directory, use cd .. to change to the parent directory;

mkdir makes a directory;

cp copys a file or a folder , usage is cp source target, to copy a directory you need the parameter -r ;

mv moves a file or a folder , the usage is similar with cp, but you needn't use -r to move a directory;

cat shows the content of a text file;

clear cleans up the contents in current terminal;

touch creates a new blank text file;

You can press Ctrl+C to stop a running process.

For more information about the Linux shell, you can visit this site:

The ownership and access authority of Linux

Use ls -l to see the details of files in a list:

At the directory of /, using ls -l you can find that most of the files are owned by the system (owner is root),modifying these files will be rejected with permission denied . If the current user owns the root privilege, you can use sudo to launch a command with root privilege. For example, to make a blank file in / with the name text.txt, you can use sudo touch text.txt

A password will be required, notice that the characters you input will not be displayed:

Here is a list of useful commands:(Remember to use sudo):

chown changes the owner of a file or folder, you can use it with sudo to change a file's owner from root to the current user.

chmod changes the permission of a file, usechmod +x to add the permission of executable to a file (e.g. a shell script).

Linux variables

1、Introduction to the variables:

Variables are a way of passing information from the shell to programs when you run them. Programs look "in the environment" for particular variables and if they are found will use the values stored. Some are set by the system, others by you, yet others by the shell, or any program that loads another program.

Standard UNIX variables are split into two categories, environment variables and shell variables. In broad terms, shell variables apply only to the current instance of the shell and are used to set short-term working conditions; environment variables have a farther reaching significance, and those set at login are valid for the duration of the session.

For example, the command ls is actually a executable binary file located in the /bin directory——use the command which to find the actual path of a command:

Note: please check the variable first if an error like "xxx not found" occurs, here "xxx" is a component that has already been installed on your system.

2、bashrc script

Each time you login to a UNIX host, the system looks in your home directory for initialisation files. Information in these files is used to set up your working environment. The Ubuntu is using the bash shell, and the bash shell uses the script of bashrc. This script is located in the home folder and its a hidden file (filename starts with . ), with the actual path ~/.bashrc .

You can add new variables in this file to make the variables taking efforts. Notice that when the bashrc is modified, you need to reopen a new terminal to apply the changes or use the following command:

source ~/.bashrc

For example, when you have already installed the ROS with apt-get, you will be unable to launch roscore without setting the variables:

You need to add the following script to bashrcand run source

source /opt/ros/melodic/setup.bash

When the script is applied, you can use the command which to find the actual path of roscore

The Linux shell is actually a kind of programming language, the echo command is to output contents on the screen, similar as the print function in python. This command is usually used to print descriptions to the screen when programming a shell script, or show the content of a variable. For example, use the following command to show the variable GAZEBO_MODEL_PATH:

Notice that the name of a variable starts with $ . This variable will tell Gazebo where to find the model files.

echo $环境变量名

The usage of Package manager

1、Ubuntu package manager

The Linux operating system uses the package manager to download and install softwares precompiled. Ubuntu uses apt as the package manager. The basic usage:

sudo apt-get install package-name

2、Sources of package manager

Some of the packages such as ROS is not included in the official package sources, you can add the sources manually to install the third party packages with the package manager.

Here is the instruction of installing ROS on Ubuntu:

http://wiki.ros.org/melodic/Installation/Ubuntu

Notice that you must set up the keys before using the sources of ROS.

You must use the following command to apply the sources modified

sudo apt-get update

3、Python package manager

The Python intepreter also includes a package manager for installing third party Python library. Since the ROS is partly based on Python, some Python packages are required to install.

The package manager of Python is pip, and should be installed through the following command:

sudo apt-get install python-pip

Usage:

pip install package-name

When a "permission denied" error occurs, use the parameter --user

pip install package-name --user

Notice that you had better not run pip with sudo!

Compile from source

1、software distribution

The developers can distribute the software in two kinds of forms: source code distribution and binary distribution. Many open-source softwares are distributed in the form of source code, and the users should compile the source code by themselves. Some components of the GAAS are also released with source codes and should be compiled into executable binary files to use e.g. the SLAM component.

2、cmake and makefile

Many open-source softwares are built with C/C++ programming language, and the source code files should be compiled and linked in the sequence of dependency. The UNIX-compatible systems (e.g. Linux) are using makefile to define compiling rules and dependencies. Use the command make to launch a makefile and compile the codes in sequence, and the files which have already been built will be skipped.

The C++ compiling toolchains of Ubuntu should be installed with the command:

sudo apt-get install build-essential

Use make to execute a makefile:

make target

Here the "target" is defined by the makefile. For example, the following command can build the PX4 firmware and Gazebo simulator:

make posix_sitl_default gazebo

For most software, you can use a blank "target" directly:

make

Use the parameter -j to compile in parallel with a number of subprocesses:

make -j4

The parameter can take advantage of multi-core CPU, but the number of subprocesses cannot be more than actual CPU cores, or it may cause issues.

Cmake is used to detect the current platform, toolchains and shared libraries, configure and generate a makefile automatically. You can use apt-get to install cmake in Ubuntu.

3、Build and install open-source softwares

You can use the following steps to install most of the open-source softwares.

(1) Get the source code, you can use git to clone a repository on GitHub

git clone (the git address of the repository)

(2) Make a building directory. Since CMake do not provide the function of cleaning, the best practise is to make a building directory for CMake to generate temporary files. Usually the folder is named as build .

cd (directory of the repository)

mkdir build

cd build

(3) Generate makefile with CMake:

cmake ..

Here the current directory is the build directory, and cmake will find the configuration file CMakeLists.txt. This file is provided by the software developer, and usually the file is located in the directory of the software repository, which is the parent directory ofbuild . For most software, you can use the default parameters of CMake.

(4) Compile and install:

make

(Optional) sudo make install

For the shared library, install can install the compiled binary files into the system library for other programs to use.

Support us on Patreon

Last updated