A story of an amateur programmer participating in a contest using Autoware.(Part 1: Building the Autoware environment)


##To begin with.
I have nothing to do with programming at work, but I became interested in AI a few years ago and started studying it on my own.
The commands, reference links, etc. may not be applicable in the latest situation.
This is a summary article of what I learned very much from just building an environment for an amateur.

・[Part 1: Building the Autoware environment](https://qiita.com/penstood/private/aa0328805bb91ad9340f "自動運転AIチャレンジ")　
・[Part 2: Summary of ROS information](https://qiita.com/penstood/private/3e6a734bb2196dd72c9f "A story of an amateur programmer participating in a contest using Autoware.（Part 2: Summary of ROS information）")
・[Part 3: Try using Autoware and the LGSVL simulator](https://qiita.com/penstood/private/b024c6486af18fe620e6 "A story of an amateur programmer participating in a contest using Autoware.（Part 3: Try using Autoware and the LGSVL simulator）")


##0. Why join the contest?
The concept of "software first" and "connected" is about to change the way we manufacture things. I am rarely involved in software in my daily work, but I felt that this was not good enough, so about years ago, I started studying programming, including AI, with a group of volunteers from within the company, separately from my work. I've been studying AI and other programming in addition to my work for about few years now.

##1. Installing Ubuntu
###Ubuntu won't start.（PC will not boot.）
At the time, I had no idea what Ubuntu was. At that time, I had no idea what Ubuntu was. It seems that the NVIDIA GPU is incompatible with the standard Ubuntu graphics driver, so it won't boot properly.

[link](https://qiita.com/k_ikasumipowder/items/5e88ec45f958c35e05ed "Deep Learning 環境の構築")
###Disable nouveau
１． Go into the BIOS menu and set Secure Boot to Disabled.

2． Hover the cursor over`Install Ubuntu` 　Configuring Push `e` to Start Options.

3．You can disable nouveau by rewriting `quiet splash ---`　to　`quiet splash nomodeset ---`.
###unable to nvidia-smi （Installing GPU driver）
[link](https://codechacha.com/ja/install-nvidia-driver-ubuntu/ "Ubuntuの18.04 - NVIDIAドライバをインストールする方法")


```ruby:Install_GPU_Driver
ubuntu-drivers devices
sudo apt update
sudo apt install nvidia-driver-***
```

[If it doesn't work, click here.](https://qiita.com/kawazu191128/items/8a46308be6949f5bda57 "ubuntu18.04にnvidiaドライバを入れるの苦労した")
Find and install the driver in [NVIDIA](https://www.nvidia.co.jp/Download/index.aspx?lang=jp "エヌビディア製品用ドライバを手動検索") 
[If you can't find it, beta version](https://www.nvidia.co.jp/Download/Find.aspx?lang=jp "エヌビディア製品用ドライバのベータ版")

```ruby:Install_GPU_Driver
sudo bash NVIDIA-Linux-x86_64-440.36.run
```

##2. What you need to install
List of nvidia-drivers and CUDA Toolkit for GPUs is [here](https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html "NVIDIA CUDA Toolkit Release Notes")
Make sure you install the corresponding one!


###Install CUDA Toolkit 10.0 
The first step is to install CUDA. In this case, [Autoware recommends](https://github.com/Autoware-AI/autoware.ai/wiki/Source-Build "Autoware.AI Source Build") CUDA10, so we will install that.

```ruby:CUDA_Toolkit_10.0
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
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
sudo add-apt-repository "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /"
sudo apt-get update
sudo apt-get -y install cuda-10.0
# add PATH to bashrc
echo -e "\n## CUDA and cuDNN paths"  >> ~/.bashrc
echo 'export PATH=/usr/local/cuda-10.0/bin:${PATH}' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64:${LD_LIBRARY_PATH}' >> ~/.bashrc
source ~/.bashrc
# reboot PC
sudo reboot
```

###Install docker
[Install Docker Engine on Ubuntu](https://docs.docker.com/engine/install/ubuntu/ "Install Docker Engine on Ubuntu")

```ruby:Install_Docker_Engine_on_Ubuntu
sudo apt-get update

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
# Allowing ordinary users to use docker commands
sudo usermod -aG docker $USER
reboot
```


###Install nvidia-docker and nvidia-docker2
This seems to be the latest.[NVIDIA Docker って今どうなってるの？ (20.09 版)](https://medium.com/nvidiajapan/nvidia-docker-%E3%81%A3%E3%81%A6%E4%BB%8A%E3%81%A9%E3%81%86%E3%81%AA%E3%81%A3%E3%81%A6%E3%82%8B%E3%81%AE-20-09-%E7%89%88-558fae883f44?source=collection_home---6------5-----------------------　"NVIDIA Docker って今どうなってるの？ (20.09 版)")と
Install it by referring to this page. [NVIDIA-DOCKER2の始め方](https://xvideos.hatenablog.com/entry/install-nvidia-docker2 "NVIDIA-DOCKER2の始め方")

```ruby:Install_nvidia-docker2
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | \
  sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/ubuntu16.04/amd64/nvidia-docker.list | \
  sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update

sudo apt-get install nvidia-docker2
sudo pkill -SIGHUP dockerd
```

```ruby:operation_check-nvidia-docker2
sudo docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi
```


Note that if the confirmation command works and does not pull the image, it did not go well.

```ruby:operation_check-nvidia-docker
docker run --runtime nvidia nvidia/cuda:10.0-base nvidia-smi
```


###Installing ROS　 <-　（Not required if you use docker）
RThe supported version of ROS depends on the OS version, and melodic will be installed on Ubuntu 18.04.
[Click here](http://wiki.ros.org/melodic/Installation/Ubuntu "Ubuntu install of ROS Melodic")

```ruby:ROS_melodic_install
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
sudo apt update
sudo apt install ros-melodic-desktop-full
# Add to bashrc so that ROS environment files will be loaded on next boot.
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc

# Install dependencies
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
sudo apt install python-rosdep
sudo rosdep init
rosdep update
```


##3. Building Autoware
There are two types of Autoware: Autoware-docker, which is launched by docker, and the method of building directly on the local PC.
Autoware-docker is recommended.
Even if the ROS environment or Autoware is broken and stops working, docker can quickly restore it.

###Autoware-docker
First, find out the user ID.

```ruby:Check_user_ID
id
```

[Autoware-docker build](https://github.com/Autoware-AI/autoware.ai/wiki/Generic-x86-Docker "Autoware-docker"). In this example, we will build v1.13.0. In this case, we will build v1.13.0, so we will specify the version.



```ruby:Autoware-docker_build
git clone https://github.com/Autoware-AI/docker.git
cd docker/generic
# uid=1000
./run.sh -t 1.13.0
# uid!=1000
./run.sh -s -t 1.13.0
```

####【Add】
Make sure that the image remains even after exiting from docker.
If you don't do this, the image will not remain after you exit from docker, and you will have to start building the package again.
To avoid this, it is easy to change this last part [Autoware-docker/run.sh](https://github.com/Autoware-AI/docker/blob/master/generic/run.sh "id - Autoware-docker/run.sh"). To avoid this, it is easy to change this last part, although it will cause the image to be created every time you `./run.sh `.



```ruby:run.sh

*****

docker run \
    -it\　　　　　　　　　　#<=remove command "--rm"　
    $VOLUMES \
    --env="XAUTHORITY=${XAUTH}" \
    --env="DISPLAY=${DISPLAY}" \
    --env="USER_ID=$USER_ID" \
    --privileged \
    --net=host \
    $RUNTIME \
    $IMAGE
```


###To build from source
[Autoware-docker Source Build](https://github.com/Autoware-AI/autoware.ai/wiki/Generic-x86-Docker "Autoware-docker Source Build")
In my environment, the part where Eigen is built did not work, so I changed it.

```ruby:Autoware_AI_Source_Build
# Install dependencies
sudo apt update
sudo apt install -y python-catkin-pkg python-rosdep ros-$ROS_DISTRO-catkin
sudo apt install -y python3-pip python3-colcon-common-extensions python3-setuptools python3-vcstool
pip3 install -U setuptools
# Install Eigen
cd && wget http://bitbucket.org/eigen/eigen/get/3.3.7.tar.gz 
mkdir eigen && tar --strip-components=1 -xzvf 3.3.7.tar.gz -C eigen
cd eigen && mkdir build && cd build && cmake .. && make
sudo make install #<=Add sudo
```




```ruby:Autoware_AI_Source_Build
mkdir -p autoware.ai/src
cd autoware.ai

#　Specify the version to build v1.13.0
wget -O autoware.ai.repos "https://gitlab.com/autowarefoundation/autoware.ai/autoware/raw/1.13.0/autoware.ai.repos?inline=false"
vcs import src < autoware.ai.repos
sudo rosdep init
rosdep update
rosdep install -y --from-paths src --ignore-src --rosdistro melodic
source /opt/ros/melodic/setup.bash

# WITH CUDA support
AUTOWARE_COMPILE_WITH_CUDA=1 colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release

# WITHOUT CUDA Support
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release
```
If the Autoware Runtime Manager starts, the build is successful.

```ruby:Autoware_runtime_manager
# Loading Autoware environment
source ~/Autoware/install/local_setup.bash
# Launch runtime_manager
roslaunch runtime_manager runtime_manager.launch
```

Thank you for your hard work. No matter how well it goes, it will take a whole day to get this far. (The first time I did it, it took me about four days through trial and error.
So far, I've finally finished setting up the environment to run Autoware. I would like to write again about how to learn ROS and how to use Autoware.

##4. Links
・[自動運転AIチャレンジ](https://www.jsae.or.jp/jaaic/index.html "自動運転AIチャレンジ")
・[ubuntu18.04にnvidiaドライバを入れるの苦労した](https://qiita.com/kawazu191128/items/8a46308be6949f5bda57 "ubuntu18.04にnvidiaドライバを入れるの苦労した")
・[エヌビディア製品用ドライバ](https://www.nvidia.co.jp/Download/index.aspx?lang=jp "エヌビディア製品用ドライバを手動検索")
・[エヌビディア製品用ドライバのベータ版](https://www.nvidia.co.jp/Download/Find.aspx?lang=jp "エヌビディア製品用ドライバのベータ版")
・[Deep Learning 環境の構築](https://qiita.com/k_ikasumipowder/items/5e88ec45f958c35e05ed "Deep Learning 環境の構築")
・[Autoware.AI Source Build](https://github.com/Autoware-AI/autoware.ai/wiki/Source-Build "Autoware.AI Source Build")
・[Ubuntu 18.04へのCUDAインストール方法](https://qiita.com/yukoba/items/4733e8602fa4acabcc35 "Ubuntu 18.04へのCUDAインストール方法")
・[NVIDIA CUDA Installation Guide for Linux](https://docs.nvidia.com/cuda/archive/10.0/cuda-installation-guide-linux/index.html "NVIDIA CUDA Installation Guide for Linux")
・[Install Docker Engine on Ubuntu](https://docs.docker.com/engine/install/ubuntu/ "Install Docker Engine on Ubuntu")
・[NVIDIA Docker って今どうなってるの？ (19.11版)](https://qiita.com/ksasaki/items/b20a785e1a0f610efa08 "NVIDIA Docker って今どうなってるの？ (19.11版)")
・[NVIDIA Docker って今どうなってるの？ (20.09 版)](https://medium.com/nvidiajapan/nvidia-docker-%E3%81%A3%E3%81%A6%E4%BB%8A%E3%81%A9%E3%81%86%E3%81%AA%E3%81%A3%E3%81%A6%E3%82%8B%E3%81%AE-20-09-%E7%89%88-558fae883f44?source=collection_home---6------5-----------------------　"NVIDIA Docker って今どうなってるの？ (20.09 版)")
・[NVIDIA-DOCKER2の始め方](https://xvideos.hatenablog.com/entry/install-nvidia-docker2 "NVIDIA-DOCKER2の始め方")
・[Ubuntu install of ROS Melodic](http://wiki.ros.org/melodic/Installation/Ubuntu "Ubuntu install of ROS Melodic")
・[id - ユーザIDやグループIDを表示する](https://linuxcommand.net/id/ "id - ユーザIDやグループIDを表示する")
・[Autoware-docker build](https://github.com/Autoware-AI/autoware.ai/wiki/Generic-x86-Docker "Autoware-docker")
・[Autoware-docker Source Build](https://github.com/Autoware-AI/autoware.ai/wiki/Generic-x86-Docker "Autoware-docker Source Build")
・[Ubuntu18.04にAutoware.AIをインストール](https://qiita.com/k-koh/items/90647b1cb140b4b75c91 "Ubuntu18.04にAutoware.AIをインストール")
・[Ubuntuの18.04 - NVIDIAドライバをインストールする方法](https://codechacha.com/ja/install-nvidia-driver-ubuntu/ "Ubuntuの18.04 - NVIDIAドライバをインストールする方法")
・[NVIDIA CUDA Toolkit Release Notes](https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html "NVIDIA CUDA Toolkit Release Notes")