🐕

AIChallenge 2025の活動記(準備・環境構築編)

に公開

今年も自動運転AIチャレンジの時期がやってまいりました。ということで、実際何をすればいいのか?どのように環境を構築すればいいのか?を自分なりにまとめてみました。何回か経験しているという方は、こんなことやっていたな、と思い出しながら見ていただけると助かります。

環境構築

基本はドキュメント通りに環境を構築していきましょう。いくつか、公式手順と異なっているところがあるので、ドキュメントを確認しながら進めてください。

動作環境

まず推奨マシンが何かを確認します。今回は描画ありAWSIMのみですので下記のようになります。

Category Type
OS Ubuntu 22.04
CPU Intel Corei7 (8 cores) or higher
GPU NVIDIA Geforce VRAM 8 GB
Memory 16 GB or more
Storage SSD 60 GB or higher

また、Linuxがlocal環境にないという方がいらっしゃると思うので、参考にしてください。

Ubuntu 22.04のインストール(推奨)

WSLを活用した開発

プロジェクトのクローン

次にソースコードを実際にクローンしましょう。

# 必要なパッケージのダウンロード
sudo apt update & sudo apt upgrade
sudo apt install -y git

# ホームフォルダに移動(任意の場所で構いません)
cd ~

# プロジェクトのクローン
git clone https://github.com/AutomotiveAIChallenge/aichallenge-2025.git

仮想環境(docker)のインストール

必要なライブラリをインストールします。

sudo apt update
sudo apt install -y python3-pip ca-certificates curl gnupg libvulkan1

次にdockerのインストールを行います。

sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo usermod -aG docker $USER
newgrp docker
docker run hello-world

次にrockerをインストールします。docker環境内のGUIアプリケーション(Rviz, rqt, plot juggler)を使用するために使用します。

# rockerのinstall
pip install rocker

# pathの登録
echo export PATH='$HOME/.local/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

続いて、GPUを使用するためのdockerを整えます。まずローカルpcで、GPUが使用できることを確認します。

nvidia-smi

# 以下のようなものが出る場合やそもそもない場合は下記を実行
# NVIDIA-SMI has failed because it couldn’t communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.

# No devices were found

# リポジトリの追加
sudo add-apt-repository ppa:graphics-drivers/ppa

# パッケージリストの更新
sudo apt update

# インストール
sudo ubuntu-drivers install

# 再起動
reboot

# 再起動の後、インストールできていることを確認
nvidia-smi

続いて、NVIDIA Container Toolkitをインストールします。

# インストールの下準備
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
      && curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
      && curl -s -L https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list | \
            sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
            sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list

# インストール
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

Autoware環境のDockerイメージ取得

dockerイメージのダウンロード(有線LANがおすすめ)

docker pull ghcr.io/automotiveaichallenge/autoware-universe:humble-latest

さらにここからdocker imageを再構築します。

cd ~/aichallenge-2025/

./docker_build.sh dev

最後の仕上げ

最後にAWSIMの準備をしていきます。まずこちらからAWSIM.zipをダウンロードしましょう。

そして、AWSIM.zipを/aichallenge/simulatorに配置し,展開します。

mv ~/Downloads/AWSIM.zip ~/Aichallenge-2025/aichallenge/simulator/

unzip ~/Aichallenge-2025/aichallenge/simulator/AWSIM.zip 
# 権限の付与
sudo chmod +x ~/Aichallenge-2025/aichallenge/simulator/AWSIM/AWSIM.x86_64

次に、便利に使用するためにaichallenge-2025/aichllenegeに,run_all.bashを作成しておきます。

# 任意のエディタを使用してください(gedit, code, vim, nano)
vi ~/Aichallenge-2025/aichallenge/run_all.sh
run_all.bash
run_all.bash
#!/bin/bash

# Create a temporary file to store process IDs
PID_FILE=$(mktemp)
echo "Process ID file: $PID_FILE"

# recursively get child processes
get_child_pids() {
    local parent_pid=$1
    local child_pids

    child_pids=$(pgrep -P "$parent_pid")
    for pid in $child_pids; do
        echo "$pid" >>"$PID_FILE"
        get_child_pids "$pid"
    done
}

# update process list
update_process_list() {
    local main_pids=("$PID_AWSIM" "$PID_AUTOWARE" "$PID_ROSBAG")

    # clear the PID file
    : >"$PID_FILE"

    # record main process PIDs
    for pid in "${main_pids[@]}"; do
        if [[ -n $pid ]] && kill -0 "$pid" 2>/dev/null; then
            echo "$pid" >>"$PID_FILE"
            get_child_pids "$pid"
        fi
    done

    # get child processes of main processes
    for pattern in "ros2" "autoware" "web_server" "rviz"; do
        pgrep -f "$pattern" | while read -r pid; do
            # check if the PID is already in the file
            if ! grep -q "^$pid$" "$PID_FILE"; then
                echo "$pid" >>"$PID_FILE"
            fi
        done
    done
}

# shutdown function
graceful_shutdown() {
    local pid=$1
    local timeout=${2:-30} # timeout in seconds, default is 30 seconds

    if [[ -n $pid ]] && kill -0 "$pid" 2>/dev/null; then
        echo "Sending SIGTERM to PID $pid"
        kill "$pid"

        # wait for the process to terminate
        local count=0
        while kill -0 "$pid" 2>/dev/null && [ $count -lt $((timeout * 10)) ]; do
            sleep 0.1
            ((count++))
        done

        # if the process is still running after timeout, force kill
        if kill -0 "$pid" 2>/dev/null; then
            echo "Process $pid did not terminate gracefully after $timeout seconds, forcing kill"
            kill -9 "$pid"
            sleep 0.1
        fi
    fi
}

# Function to handle Ctrl+C and normal termination
cleanup() {
    echo "Termination signal received. Cleaning up..."

    # get the latest process list
    update_process_list

    # Stop recording rosbag
    echo "Stop rosbag"
    if [[ -n $PID_ROSBAG ]] && kill -0 "$PID_ROSBAG" 2>/dev/null; then
        graceful_shutdown "$PID_ROSBAG" 3
    fi

    # shutdown ROS2 nodes
    echo "Shutting down ROS2 nodes gracefully..."
    ros2 node list 2>/dev/null | while read -r node; do
        echo "Shutting down node: $node"
        ros2 lifecycle set "$node" shutdown 2>/dev/null || true
        ros2 node kill "$node" 2>/dev/null || true
    done

    # Stop Autoware
    echo "Stop Autoware"
    if [[ -n $PID_AUTOWARE ]] && kill -0 "$PID_AUTOWARE" 2>/dev/null; then
        graceful_shutdown "$PID_AUTOWARE" 3
    fi

    # Stop AWSIM
    echo "Stop AWSIM"
    if [[ -n $PID_AWSIM ]] && kill -0 "$PID_AWSIM" 2>/dev/null; then
        graceful_shutdown "$PID_AWSIM" 3
    fi

    # check for remaining processes
    echo "Checking for remaining processes..."
    if [[ -f $PID_FILE ]]; then
        while read -r pid; do
            if kill -0 "$pid" 2>/dev/null; then
                echo "Attempting graceful shutdown of remaining PID $pid"
                graceful_shutdown "$pid" 3
            fi
        done <"$PID_FILE"
        rm "$PID_FILE"
    fi

    echo "Cleanup complete."
    # Stop ros2 daemon
    ros2 daemon stop
    exit 0
}
# Trap Ctrl+C (SIGINT) and normal termination (EXIT)
trap cleanup SIGINT SIGTERM EXIT

# Move working directory
OUTPUT_DIRECTORY=$(date +%Y%m%d-%H%M%S)
cd /output || exit
mkdir "$OUTPUT_DIRECTORY"
ln -nfs "$OUTPUT_DIRECTORY" latest
cd "$OUTPUT_DIRECTORY" || exit

# shellcheck disable=SC1091
source /aichallenge/workspace/install/setup.bash
sudo ip link set multicast on lo
sudo sysctl -w net.core.rmem_max=2147483647 >/dev/null

# Start AWSIM with nohup
echo "Start AWSIM"
nohup /aichallenge/run_simulator.bash >/dev/null &
PID_AWSIM=$!
echo "AWSIM PID: $PID_AWSIM"
echo "$PID_AWSIM" >"$PID_FILE"
# recursively get child processes
get_child_pids "$PID_AWSIM"
sleep 1

# Start Autoware with nohup
echo "Start Autoware"
nohup /aichallenge/run_autoware.bash awsim >autoware.log 2>&1 &
PID_AUTOWARE=$!
echo "Autoware PID: $PID_AUTOWARE"
echo "$PID_AUTOWARE" >>"$PID_FILE"
# recursively get child processes
get_child_pids "$PID_AUTOWARE"
sleep 1

# run updater
(
    while true; do
        sleep 5

        # update if the main process is still running
        if [[ -n $PID_AWSIM ]] && kill -0 "$PID_AWSIM" 2>/dev/null; then
            update_process_list
        else
            # if the main process is not running, exit the loop
            break
        fi
    done
) &
PID_UPDATER=$!
echo "$PID_UPDATER" >>"$PID_FILE"

# Move windows
wmctrl -a "RViz" && wmctrl -r "RViz" -e 0,0,0,1920,1043
wmctrl -a "AWSIM" && wmctrl -r "AWSIM" -e 0,0,0,900,1043

sleep 5
bash /aichallenge/publish.bash initial
bash /aichallenge/publish.bash control


# Wait for AWSIM to finish (this is the main process we're waiting for)
wait "$PID_AWSIM"



# If AWSIM finished naturally, we'll proceed with the rest of the cleanup
cleanup

以上で環境構築が終了です!

環境の実行

それでは、環境を動かしてみましょう。

local pc
cd ~/aichallenge-2025

./docker_run.sh dev

そうしたら、/aichallengeにいると思うので、以下を実行してAutowareをビルドします。

docker内
./build_autoware.bash 

無事にビルドできたら実際に動かしてみましょう。まずは ./run_evaluation.bashを実行してみましょう。実行したら自動で動き始めると思います。

docker内
 ./run_evaluation.bash

./run_evaluation.bashは,rosbagや画面キャプチャなど様々な機能が含まれていますが、検証向きではないように感じます。そのため、./run_all.bashでは、Autowareとawsimのみ動かすようにしました。ぜひ活用してみてください。

最後に

今回は、環境構築を中心に記事を書かせていただきました。次回は、開発をどのようすすめるか?と昨年使用しましたTrajectory editorの開設をできたらと考えています。

また,slackの#iaslのへやでは、進捗を随時共有したり交流したいと考えてますのでよろしくお願いします!!

岐阜大学アレックス研究室

Discussion