ZED2 camera operating environment construction (Ubuntu 20.04 + nvidia-470 drive + CUDA-11.4)

I. installation of calibration tool

1 install Kalibr
Calibration of ZED2 binocular camera using kalibr tool

1) Install dependencies

sudo apt-get install python-setuptools python-rosinstall ipython libeigen3-dev libboost-all-dev doxygen libopencv-dev ros-melodic-vision-opencv ros-melodic-image-transport-plugins ros-melodic-cmake-modules software-properties-common software-properties-common libpoco-dev python-matplotlib python-scipy python-git python-pip ipython libtbb-dev libblas-dev liblapack-dev python-catkin-tools libv4l-dev

2) Install igraph

sudo pip install python-igraph --upgrade

If an error occurs, try again

sudo add-apt-repository ppa:igraph/ppa   
sudo apt-get update                       # update your package database 
sudo apt-get install python-igraph

This method will automatically help you download the dependent packages of igraph. After that, check the directory / usr/lib/python2.7/dist-packages/ to see that Python igraph has been successfully installed

3) Create work interval

mkdir -p ~/kalibr_workspace/src
cd ~/kalibr_workspace
source /opt/ros/melodic/setup.bash
catkin init
catkin config --extend /opt/ros/melodic
catkin config --merge-devel # Necessary for catkin_tools >= 0.4. catkin config --cmake-args -DCMAKE_BUILD_TYPE=Release

4) Download source code

cd ~/kalibr_workspace/src
git clone https://github.com/ethz-asl/Kalibr.git

5) Compile source code

cd ~/kalibr_workspace
catkin build -DCMAKE_BUILD_TYPE=Release -j4

The time is a little long. Wait patiently for it to be completed.

**2 download and compile code_utils,imu_utils **
Use imu_utils calibrate IMU, install and compile code in turn_ utils,imu_utils.

Be careful not to put IMU at the same time_ Utils and code_utils is compiled under src.
Due to imu_utils dependent code_utils, so put the code first_ Utils is placed under src in the workspace and compiled. Then the IMU_ Put utils under src and compile.

~/imu_utils/src$ git clone  https://github.com/gaowenliang/code_utils

Compilation error occurred during compilation, path error

terms of settlement:
Add the include path in CMakeLists.txt: include_directories( “include/code_utils”)

Recompile with
Execute the instruction sudo apt get install libdw dev

Compile again and pass.

~/imu_utils/src$ git clone  https://github.com/gaowenliang/imu_utils
cd ../

The compilation is successful and the process is complete.

Second, install CUDA (jump directly to third, this part is the pit, Wuwuwuwu ~)

CUDA introduction is added here:

The unified computing device architecture (CUDA) is a general parallel computing architecture introduced by NVIDIA. The solution is to use cheaper equipment resources to realize more efficient parallel computing.

cuda was launched by NVIDIA - who is this NVIDIA? I haven't heard of NVIDIA. I should have heard of GPU. Yes, NVIDIA proposed the concept of GPU. Compared with the central processing unit (CPU), graphics processing unit (GPU) is the core chip of the graphics card. cuda exposes the programming interface of GPU developed by NVIDIA.

Almost all programming languages can only implement CPU programming without using a specific framework - std::thread also opens threads in the CPU. Unlike the CPU programming that every programmer has been exposed to, GPU Programming can use more stream processors and more threads.

1 download
There is a corresponding cuda version in the download link page. Here I choose cuda 10.2 and ZED SDK for Ubuntu 18.
ZED2 SDK official website: https://www.stereolabs.com/developers/release/
CUDA10.2 download link: https://developer.nvidia.com/cuda-10.2-download-archive?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1804&target_type=deblocal

2 install Nvidia drive
Quick installation, open software and update - > Add driver, automatically search the graphics card driver and select one of the driver versions; Click Apply change, wait for the installation to complete, and then restart; (as shown below)
3 installation of CUDA
1) Install according to the command line of the download interface.

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda-repo-ubuntu1804-10-2-local-10.2.89-440.33.01_1.0-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1804-10-2-local-10.2.89-440.33.01_1.0-1_amd64.deb
sudo apt-key add /var/cuda-repo-10-2-local-10.2.89-440.33.01/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda

In the last step of installation, if the interface is the same after pressing enter, you can try copying and pasting or entering sudo gedit /etc/apt/sources.list, and then press enter. The problem is solved because the installation process and progress appear.

The E: sub process / usr / bin / dpkg returned an error code (1) problem is encountered when installing the software package with apt get. The solution is as follows:

1 cd /var/lib/dpkg/
2 sudo mv info/ info_bak          # Now rename the info folder
3 sudo mkdir info                 # Create a new info folder
4 sudo apt-get update             # to update
5 sudo apt-get -f install         # repair
6 sudo mv info/* info_bak/        # After performing the previous step, some files will be generated in the new info folder. Now move all these files to info_bak folder
7 sudo rm -rf info                # Delete your new info folder
8 sudo mv info_bak info           # Change the previous info folder back to

2) Configuring CUDA environment variables

sudo gedit ~/.bashrc
 stay.bashrc Add two lines of environment variables at the end
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64
 Save and exit; And execute
source ~/.bashrc

4 restart the computer and test CUDA

cd /usr/local/cuda-10.2/samples/1_Utilities/deviceQuery 
sudo make

Display failed

./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

cudaGetDeviceCount returned 100
-> no CUDA-capable device is detected
Result = FAIL

The reason is that the Nvidia driver was not installed successfully. The problem of installing the Nvidia driver in Ubuntu 18.04 has been tossed for a long time. Many pits have been buried and still can not be solved. Finally, in order to let go of yourself, I chose to change the system to continue. See the blog for specific reasons and solutions Ubuntu 18.04 sad (failed) experience of installing NVIDIA driver and solutions (successful system replacement)

After the Nvidia driver is successfully installed, it can be seen from the above figure that my graphics card can support cuda11.4 at most. Repeat the above CUDA installation process:

Download cuda: https://developer.nvidia.com/cuda-toolkit-archive

CUDA+SDK version correspondence:
When installing cuda11.0 (a pit ~), be sure to select the corresponding version 11.4

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget http://developer.download.nvidia.com/compute/cuda/11.0.2/local_installers/cuda-repo-ubuntu2004-11-0-local_11.0.2-450.51.05-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2004-11-0-local_11.0.2-450.51.05-1_amd64.deb
sudo apt-key add /var/cuda-repo-ubuntu2004-11-0-local/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda


nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Thu_Jun_11_22:26:38_PDT_2020
Cuda compilation tools, release 11.0, V11.0.194
Build cuda_11.0_bu.TC445_37.28540450_0

Restart the nvidia driver and it won't be displayed. Ah ~

NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver

After investigation, it is suspected that the CUDA version is inconsistent with the NVIDIA driver version. I thought of the previous steps, so I obediently reinstalled CUDA11.4.

3, Correct posture of CUDA installation

Find the cuda version you need and select it as follows. The download and command will be given in the dotted box at the bottom Download CUDA

wget https://developer.download.nvidia.com/compute/cuda/11.4.0/local_installers/cuda_11.4.0_470.42.01_linux.run
sudo sh cuda_11.4.0_470.42.01_linux.run

(I didn't encounter this problem, so I suggest changing the network test.) when the first statement is downloaded to 99%, it may report an error "S segment error". After searching for a long time, it was said that the downloaded trunk size is too small, and it hasn't been solved. Later, it was speculated that the error was reported directly wget because the file is too large. At this time, we use another method to download
Use axel to download. axel is a multi-threaded download tool. Please Baidu for details

sudo apt install axel
# Download cuda
# -n 50 means that 50 threads are used for downloading
axel -n 50 http://developer.download.nvidia.com/compute/cuda/11.0.2/local_installers/cuda_11.0.2_450.51.05_linux.run

After downloading, install cuda
cd to the directory where cuda is downloaded and execute the second statement

Possible error reporting solutions
1) If the following error message is reported, it is because the cuda downloaded is wrong. Just download and install it again.
Extraction failed.
Ensure there is enough space in /tmp and that the installation package is not corrupt Signal caught, cleaning up

2) Solution to prompt / tmp insufficient space when installing cuda under Ubuntu 20.04 LTS
After checking the information on the Internet, a blog said there were two reasons:

1. The installation package is not complete. During the process of downloading this. run file, I did encounter the situation of suddenly reporting an error after downloading 99% (it's too pit, and the whole person split at the moment of seeing the error). There is no special solution to this point, that is, try several more times, and finally download successfully. Make sure that the installation error comes from the second case.

2 is that the disk space on tmp is not enough. A blog said to create a new folder and point to it with a soft connection. I tried and failed. Here is my solution:
1. Create a new folder TMP under / home. Command: sudo mkdir /home/tmp
2. The installation command given on the official website is: sudo sh cuda_11.4.0_470.42.01_linux.run. Here, you need to modify the installation command to read:

 sudo sh cuda_11.4.0_470.42.01_linux.run --tmpdir=/home/tmp/

Wait dozens of seconds, success.
Under normal installation, the following display will appear:
This is the software protocol. It is the same as that of ordinary software installation. At this time, enter: accept

Click enter at the Driver and choose not to install the Driver because the Driver has been installed before. This is because each cuda comes with a set of drivers that meet the minimum requirements of the current version of cuda. If you select the installed Driver here, the previously installed Driver will be overwritten during installation on Windows, but an error may occur if you overwrite the installation on linux, I haven't tried it. If you want to try, you can test it yourself. We use the Driver we downloaded before.

Then press the direction key to select the last Install and press enter to start the installation. After a while, the following will be displayed:
If it is displayed as shown in the figure above, it indicates that the installation is completed. At this time, the installation is not successful. According to the above prompt, you need to configure the environment variables as follows:

# Open the. bashrc file
gedit ~/.bashrc

Enter the following at the end of the file and save to exit.

# Replace the following 11.4 with your cuda version. Everything else remains the same. If you don't know which version you installed, go to the / usr/local / folder
export PATH=/usr/local/cuda-11.4/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.4/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

When finished, execute the following command to update the variable to make it effective

source ~/.bashrc

Input at terminal

nvcc -V

If displayed

At this point, the installation of cuda is complete.

It's time to turn off and restart
Finally succeeded!!!

Tags: Linux Ubuntu slam CUDA nvidia

Posted on Thu, 04 Nov 2021 17:53:58 -0400 by naboth_abaho