自駕車模擬環境 CARLA - 簡介 & 安裝


Posted by Po-Jen on 2020-09-27

前言

今天想要跟大家介紹一個很酷的自駕車模擬環境 - CARLA,而且可以用 Amazon AWS 來建立環境,所以就算是沒有 Ubuntu 的朋友,也可以很方便地上手。如果你想試試看 Windows 版本也行,CARLA 有 Windows 版本。

CARLA 簡介

CARLA (Car Learning to Act) 是一個為了方便 developer 發展自駕車所開發的模擬器,而且 CARLA 是使用 Unreal Engine 4 開發的,畫面非常的漂亮,可以模擬各種場景、天氣,也有不錯的物理引擎,讓測試環境盡可能逼真。

CARLA 更讚的地方是,他完全開源,如果你有自己的特殊需求,也改得動程式碼的話,你可以直接外帶一份 source code 開始修改。

CARLA 有很多很棒的 feature,講幾個我覺得特別讚的:

  1. 支援 Multi-client:也就是說可以有多個程式連到 server,操控模擬環境中不同的 actor。所以如果我想測試多種版本的自駕系統,我可以讓這多個版本同時連上 CARLA,每個版本都是一台車
  2. 應該盡有的 sensor 支援:自駕車常用到的 camera、lidar、radar、IMU、GNSS 等等都有
  3. 可以更快速地模擬 planning & control:如果只想看 planning 跟 control 的表現,就可以把 rendering 關掉,減少資源消耗
  4. 可以控制環境中的交通狀況:CARLA 提供很大的客製化空間,甚至連有多少 % 的車會不遵守紅綠燈都可以設置

CARLA 環境

簡介完之後,想必大家都躍躍欲試,我是用 AWS 來跑 CARLA,基本的安裝方法可以參考這個網頁:

https://github.com/jbnunn/CARLADesktop

要連上機器,可以參考一下這個頁面:

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connection-prereqs.html#connection-prereqs-get-info-about-instance

用 ssh 連上機器的指令是:

ssh -i /path/my-key-pair.pem(local path) my-instance-user-name@my-instance-public-dns-name

如果是 Ubuntu,my-instance-user-name 就是 ubuntu。另外要記得 chmod 400 /path/my-key-pair.pem 不然會因為權限問題無法連上。

安裝 CARLA 後遇到的問題

我照著上面的步驟安裝完之後,會啟動失敗,原因是找不到某個 symbol file - "/opt/carla-simulator/CarlaUE4/Binaries/Linux/CarlaUE4-Linux-Shipping.sym":

ubuntu@ip-172-31-31-121:/opt/carla-simulator/bin$ SDL_VIDEODRIVER=offscreen ./CarlaUE4.sh
4.22.3-0+++UE4+Release-4.22 517 0
Disabling core dumps.
Signal 11 caught.
Malloc Size=65538 LargeMemoryPoolOffset=65554 
CommonUnixCrashHandler: Signal=11
Malloc Size=65535 LargeMemoryPoolOffset=131119 
Malloc Size=120416 LargeMemoryPoolOffset=251552 
Failed to find symbol file, expected location:
"/opt/carla-simulator/CarlaUE4/Binaries/Linux/CarlaUE4-Linux-Shipping.sym"
Engine crash handling finished; re-raising signal 11 for the default handler. Good bye.
Signal 11 caught.
Malloc Size=65538 LargeMemoryPoolOffset=65554 
CommonUnixCrashHandler: Signal=11
Malloc Size=65535 LargeMemoryPoolOffset=131119 
Malloc Size=120416 LargeMemoryPoolOffset=251552 
Failed to find symbol file, expected location:
"/opt/carla-simulator/CarlaUE4/Binaries/Linux/CarlaUE4-Linux-Shipping.sym"
Engine crash handling finished; re-raising signal 11 for the default handler. Good bye.
ubuntu@ip-172-31-31-121:/opt/carla-simulator/bin$ DISPLAY= ./CarlaUE4.sh -opengl -carla-port=2000
4.22.3-0+++UE4+Release-4.22 517 0
Disabling core dumps.
Signal 11 caught.
Malloc Size=65538 LargeMemoryPoolOffset=65554 
CommonUnixCrashHandler: Signal=11
Malloc Size=65535 LargeMemoryPoolOffset=131119 
Malloc Size=107920 LargeMemoryPoolOffset=239056 
Failed to find symbol file, expected location:
"/opt/carla-simulator/CarlaUE4/Binaries/Linux/CarlaUE4-Linux-Shipping.sym"
Engine crash handling finished; re-raising signal 11 for the default handler. Good bye.
Segmentation fault (core dumped)

不知道為啥出錯,這時候就要來首歌,放鬆一下:

Wanna Balling

解決方法

弄了一下還是無法成功,一氣之下直接 用 docker

安裝 command:docker pull carlasim/carla:0.9.8
執行 command:docker run -p 2000-2002:2000-2002 --runtime=nvidia --gpus all carlasim/carla:0.9.8

測試是否能跑,開一個新分頁,:

cd /opt/carla-simulator/PythonAPI/examples
conda activate carla
python manual_control.py

跑起來應該就會看到模擬的場景囉。

然後就可以用 WASD 來玩你的車車啦!Manual mode 裡面的各種按鍵,可以參考這個 cheat sheet(一定要按按看 Backspace,還可以變出腳踏車,笑死了)。

也許你開一開會覺得孤單,怎麼連在 CARLA 裡面都被隔離,可以用先產生出一些 NPC,多一點假的朋友:

cd /opt/carla-simulator/PythonAPI/examples
conda activate carla
python3 spawn_npc.py

再用下面的 example code 讓天氣變化,看看不同的風景!

cd /opt/carla-simulator/PythonAPI/examples
conda activate carla
python3 spawn_npc.py

simulation env

關掉 simulator:

docker ps # look up container name
docker stop <container_name>

總結

今天介紹了一個很簡單的玩 CARLA 方法,就算你沒有環境,對 Linux 不熟,用 AWS + docker 就可以跑起模擬環境,非常 user-friendly,之後有機會再介紹一些 CARLA 的進階功能!

延伸閱讀

  1. Controlling the Car and getting Camera Sensor Data - Self-driving cars with Carla and Python p.2
  2. CARLA Documentation
  3. CARLA: An Open Urban Driving Simulator

#Self-Driving Car #Simulation #Carla









Related Posts

[09] JavaScript 入門 - 原型、polyfilling、transpiling、array-like

[09] JavaScript 入門 - 原型、polyfilling、transpiling、array-like

array 類型的內建函式

array 類型的內建函式

F2E合作社|按鈕群組元件|Bootstrap 5網頁框架開發入門

F2E合作社|按鈕群組元件|Bootstrap 5網頁框架開發入門




Newsletter




Comments