Complete Ubuntu18.04+ROS+PX4+Anaconda+PyTorch+GPU+CUDA+CUDNN+XTdrone configuration intelligent drone development environment construction process

I am doing PX4 development recently, so I will record some processes and will gradually improve it.
At the same time, because the time span of this tutorial is long, I have revised it many times, so some details may appear wrong, such as cuda installation. , the text is version 11.6, because it has been reinstalled later, it will be different, but the content is correct

1. Ubuntu is installed on the mobile hard disk

1. Ubuntu installation

I refer to this blog for installation, but I installed the 18.04 system
plug-and-play-install Ubuntu20.04 on the mobile hard disk.
I bought a SSK 512G hard disk, which has enough space to store things.
Install VMware in Win10, and then create a new one. A virtual machine, you can install Ubuntu 18.04 into the mobile hard disk (be careful to format it in advance)

2. Tool installation

I installed some useful tools
Deepin Terminal, which can open multiple terminals at the same time, making it easier to use

sudo apt install  -y  deepin-terminal

The Ubuntu system does not have the Flash plug-in by default, and the browser cannot open the website video, so it needs to be installed

sudo apt install flashplugin-installer
sudo apt install browser-plugin-freshplayer-pepperflash

3. Other environments

(1)LaTex

sudo apt-get install texlive-full
sudo apt-get install texstudio

The first command here will install the compilation environment, which is the basis of LaTex, and the second one will install the official IDE, which is easier to use personally. This is a graphical environment, and you can see the preview effect while editing. The default
installation The environment is English, you can change it to Chinese first:
Find options–>configure texstudio–>general–>language en in the toolbar
and change it to zh-CN After
insert image description hereinsert image description here
installation, you need to change the compilation engine of TeXstudio to XeLaTeX, as follows:
Options –> Settings –> Build –> Default compiler
to XeLaTeX
insert image description here

Two, ROS installation

There are a lot of tutorials on CSDN here, so I won’t make too many descriptions. In general, it is to replace the domestic source (I am the source of the University of Science and Technology of China), then install ROS, and then use Xiaoyu’s rosdepc to complete the initialization during rosdep. Because
Ubuntu The default software download source (software source) is a foreign website. Generally, the domestic network is difficult to reach or the speed is slow, so it needs to be replaced. The University of Science and Technology of China, Huawei and other institutions have mirror sources. Terminal
input

sudo gedit /etc/apt/sources.list

Enter the password, open the file containing the software source address, delete all the contents, copy and paste the address below, then save and exit

deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

Then terminal input

sudo apt update
sudo apt upgrade

Finish updating software sources

3. PX4+XTdrone environment installation

Use the tutorial installation of Mr. Xiao Kun, and there are some solutions to installation problems in my other blog.
Here I have made some optimizations

1. Dependency installation

pip3 install packaging numpy empy toml pyyaml jinja2 pyargparse -i https://pypi.tuna.tsinghua.edu.cn/simple
pip2 install pandas jinja2 pyserial cerberus pyulog==0.7.0 numpy toml pyquaternion empy pyyaml  -i https://pypi.tuna.tsinghua.edu.cn/simple

This can be done faster than the original tutorial, and it is less likely to report errors

2. MAVROS installation

There is a sh file loading in the original tutorial, this step is very time-consuming, so make some modifications,
directly download the compressed package, decompress it, and then move its subfolder to the directory /usr/share/GeographicLib, and the operation can be completed
link : https://pan.baidu.com/s/1Fw3HWJqGvAz2USomgF9eqA Extraction code: q2pn
above is a compressed package, after decompression, you will get three folders, as shown in the figure insert image description hereand then input in the terminal

cd /usr/share/
sudo mkdir -p GeographicLib
cd GeographicLib

Complete the creation of the folder.
You can see it under the corresponding folder. The folder has been created successfully. The next step is to transfer the decompressed things into it. Because this is under the /usr folder, sudo permission is required

sudo cp -r /home/ncepu/下载/Baidu/geographic-lib/magnetic /usr/share/GeographicLib/
sudo cp -r /home/ncepu/下载/Baidu/geographic-lib/gravity /usr/share/GeographicLib/
sudo cp -r /home/ncepu/下载/Baidu/geographic-lib/geoids /usr/share/GeographicLib/

Everyone remember to change to your own decompression directory

4. Graphics card configuration

1. Disable the original graphics card driver

Because Ubuntu uses an open source graphics card driver, it needs to be disabled first, and probably added to the blacklist.
First, uninstall other Nvidia graphics card drivers.

sudo apt-get --purge remove nvidia*

Then

sudo gedit /etc/modprobe.d/blacklist.conf

Add in the last line to disable, save and exit

blacklist nouveau
options nouveau modeset=0

then update

sudo update-initramfs -u

Then restart the computer
and enter in the terminal

lsmod |grep nouveau

insert image description hereIf it doesn't show anything, it's in effect
If it shows the following, the surface isn't properly disabled
insert image description here

2. Install graphics driver

Because I encountered a situation where the computer turned on a black screen after installing the driver, here is an optimized solution

sudo gedit /etc/default/grub

insert image description hereReplace quite-splash with text, as shown in the above picture, then save and exit
, then open the software and update, open the additional driver bar, select the Nvidia driver, and then apply the modification, wait for the download to complete, then
insert image description hererestart the computer, and you can find that the driver is installed successfully , and there is no abnormality, it seems that the computer starts a little slower
insert image description here

3. Install CUDA

wget https://developer.download.nvidia.com/compute/cuda/11.3.0/local_installers/cuda_11.3.0_465.19.01_linux.run
sudo sh cuda_11.3.0_465.19.01_linux.run

Of course, you can also go to the nvidia official website to download and install
the nvidia official website
insert image description here . Note that the driver should not be installed.
insert image description hereThe installation was successful before
and then the import path

sudo gedit ~/.bashrc

After opening the file, add at the end

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.6/lib64
export PATH=$PATH:/usr/local/cuda-11.6/bin
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda-11.6

Here we use cuda- instead of cuda, so you have to use your own version number to replace it. I am cuda
11-6 here, so the path is cuda-11.6. Please pay attention to modifying here.
I installed cuda11.6, so the path In this way, everyone can check their own
insert image description hereand update

source ~/.bashrc

Then terminal input

nvcc -V

Note that the V here is capitalized
insert image description hereto indicate that the installation is successful

4. Install cudnn

We first go to the
cudnn download website of NVIDIA
insert image description here
on the official website to choose the appropriate cudnn version according to our CUDA version. I choose 8.5.0 here. It is recommended to download the compressed package in Tar format.
insert image description here
My computer is an Intel chip, so it is an X86_64 architecture. Select Then download the corresponding version, open and decompress it with Ubuntu’s built-in compression manager after downloading (right-click the file), and use two folders in the decompressed folder. We open the terminal under this
insert image description here
folder

sudo cp lib/* /usr/local/cuda-11.6/lib64/
sudo cp include/* /usr/local/cuda-11.6/include/

Transfer the contents of the lib and include folders to the cuda folder, here you modify your path accordingly,
and then you can use this command to check whether cudnn is installed successfully

cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2

insert image description here
If the installation is successful, the version number of cudnn will be displayed

5. Anaconda+ROS environment (PyTorch 1.11)

1. Anaconda installation + VScode compiler modification

There are many anaconda installation tutorials, so I won’t describe them too much here. I will give a tutorial for reference. This is a more detailed
Anaconda installation tutorial
. I downloaded the 2021.11 version on the Tsinghua mirror and installed it using the bash command. The default installation parameters are: After completion, create a new virtual environment named pytorch, and the python version is 3.8
and enter it in the terminal

conda create -n pytorch python=3.8

Activate the created virtual conda environment named pytorch

conda activate pytorch

After the activation is complete, select the compiler in vscode, Ctrl+Shift+P, select the pytorch compiler in the conda environment, then declare the compiler at the beginning, and then compile and run it. Later, we will use this virtual named Pytorch Install PyTorch and other libraries in the environment
The situation after using Ctrl+Shift+Pand then click the "Python: Select Compiler" option, the following situation will be displayed. Select pytorch under conda as the py file under the
choose compilercompiler configuration function package and execute catkin_make (note that it is already in other terminals roscore)
insert image description here, and then rosrun runs the file, the result is compatible with PyTorch and ROS (both packages are installed below, here is just to show the effect)

2. Install the GPU version of the PyTorch framework in Anaconda

First determine the cuda version. CUDA has two APIs, the runtime API and the driver API, the so-called Runtime API and Driver API. The result of nvidia-smi is the model of CUDA Driver API, and the result of nvcc -V corresponds to CUDA Runtime API, and the version of nvcc -V should be used when installing pytorch.
Here I recommend a tutorial for other big guys to install. The installation is fast and stable.
Install pytorch (don't remove -c pytorch, the lesson after installing n times).
I choose PyTorch corresponding to cuda version 11.6 here.

# CUDA 11.6
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.6 -c pytorch -c conda-forge

insert image description here

3. ROS package installation in Anaconda

After installing anaconda and creating the pytorch environment, execute it in the PyTorch environment

pip install rospkg

This is the installation of rospy and other ros packages in the environment
as shown in the figure. I use torch and rospy in a py file at the same time. Compilation and operation can be done. At the same time, please note that the terminal can only be completed in the pytorch environment (the /home/ros at the beginning Here ros is my username)
insert image description here

4. Anaconda installs OpenCV4

I chose the 4.5.1 version of OpenCV, which is not too backward or too advanced to cause instability. I still
run it in the pytorch environment of conda

pip install opencv-python==4.5.1.48 -i https://pypi.tuna.tsinghua.edu.cn/simple/
#这里4.5.1.48代表我选择4.5.1版本,注意一下是双等号,后面代表我选择清华源安装,很快就可以安装好

insert image description hereThen use python in the terminal, run the opencv package, successfully

6. Construction of other environments in the direction of SLAM

1. MeshLab installation

This is a software for viewing point clouds

sudo apt-get install meshlab

2. PCL installation

pip install cython -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install python-pcl -i https://pypi.tuna.tsinghua.edu.cn/simple

Guess you like

Origin blog.csdn.net/qq_46202265/article/details/124891543