最近研究了一下自动驾驶的模拟器Airsim和CARLA,准备搭建一个学习环境来学习自动驾驶的相关知识。
Airsim最初是微软推出的一个模拟飞行的平台,之后增加了模拟驾驶的内容,这个平台据网上的资料是微软的一个较小的开源项目,因此也没有得到太大的重视,我看了一下平台好像也好久没有更新了,平台上的问题也没有什么人解答。我在Linux环境上下载的City Environment始终解压有问题,看到平台上也没有人答复,因此暂时放弃。
CARLA是Intel和西班牙的一个实验室的合作项目,也是目前比较出名的一个开源的模拟驾驶平台,因此我目前是选择了这个项目来搭建我的模拟驾驶平台。我的环境是由一台Linux PC(装配了1个GTX1070Ti和1个GTX2080Ti显卡,没有配置显示器),另外一台Windows PC远程接入进行控制。CARLA在Linux的安装可以直接在https://github.com/carla-simulator/carla上下载编译好的文件,也可以自己下载源代码进行编译,下面介绍一下这两种方式。
推荐这种方式。把下载好的文件解压缩到CARLA文件夹后,即可直接运行CarlaUE4.sh来启动CARLA服务器。因为我的Linux PC没有接显示器,因此我需要把图形输出定向到我的Windows PC,以下是配置过程:
# nvidia-xconfig: X configuration file generated by nvidia-xconfig
# nvidia-xconfig: version 410.48
Section "ServerLayout"
Identifier "Layout0"
Screen 0 "Screen0"
Screen 1 "Screen1" RightOf "Screen0"
InputDevice "Keyboard0" "CoreKeyboard"
InputDevice "Mouse0" "CorePointer"
EndSection
Section "Files"
EndSection
Section "InputDevice"
# generated from default
Identifier "Mouse0"
Driver "mouse"
Option "Protocol" "auto"
Option "Device" "/dev/psaux"
Option "Emulate3Buttons" "no"
Option "ZAxisMapping" "4 5"
EndSection
Section "InputDevice"
# generated from default
Identifier "Keyboard0"
Driver "kbd"
EndSection
Section "Monitor"
Identifier "Monitor0"
VendorName "Unknown"
ModelName "Unknown"
HorizSync 28.0 - 33.0
VertRefresh 43.0 - 72.0
Option "DPMS"
EndSection
Section "Monitor"
Identifier "Monitor1"
VendorName "Unknown"
ModelName "Unknown"
HorizSync 28.0 - 33.0
VertRefresh 43.0 - 72.0
Option "DPMS"
EndSection
Section "Device"
Identifier "Device0"
Driver "nvidia"
VendorName "NVIDIA Corporation"
BoardName "GeForce GTX 1070 Ti"
BusID "PCI:1:0:0"
Option "ConnectedMonitor" "DFP"
Option "CustomEDID" "DFP-0:/etc/X11/edid.bin"
EndSection
Section "Device"
Identifier "Device1"
Driver "nvidia"
VendorName "NVIDIA Corporation"
BoardName "GeForce RTX 2080 Ti"
BusID "PCI:38:0:0"
Option "ConnectedMonitor" "DFP"
Option "CustomEDID" "DFP-0:/etc/X11/edid.bin"
EndSection
Section "Screen"
Identifier "Screen0"
Device "Device0"
Monitor "Monitor0"
DefaultDepth 24
Option "Coolbits" "12"
Option "ConnectedMonitor" "DFP-0"
Option "CustomEDID" "DFP-0:/etc/X11/edid.bin"
Option "RegistryDwords" "PerfLevelSrc=0x2222"
SubSection "Display"
Depth 24
EndSubSection
EndSection
Section "Screen"
Identifier "Screen1"
Device "Device1"
Monitor "Monitor1"
DefaultDepth 24
Option "Coolbits" "12"
Option "ConnectedMonitor" "DFP-0"
Option "CustomEDID" "DFP-0:/etc/X11/edid.bin"
Option "RegistryDwords" "PerfLevelSrc=0x2222"
SubSection "Display"
Depth 24
EndSubSection
EndSection
export DISPLAY=:0
xhost +
nvidia-settings -a "[gpu]/GPUFanControlState=1" -a "[fan]/GPUTargetFanSpeed=90"
参考官网的这个文档:
https://carla.readthedocs.io/en/latest/how_to_build_on_linux/
Unreal Engine 4.22的安装
这个按照官网的步骤安装即可,没有遇到问题。需要注意的是,要从UE4的Github上面把代码克隆下来,但是Github实在是太慢了,可以在码云gitee.com上面来复制一个仓库,这样就快很多。
CARLA的安装
首先是克隆CARLA的Github仓库,同理可以在gitee.com上面复制一份。执行./Update.sh,这个操作会下载CARLA的UE4资源,大概有6个多G,建议下载完后把这个Content目录保存一下,以后重装的时候直接用回这个目录的数据即可,不用再运行./Update.sh
然后执行make launch,这里我就遇到了pyconfig.h无法找到的问题。我用的是Anaconda的python 3.7的环境,因为CARLA建议的是python 3.5,因此创建一个3.5的环境,执行conda create --name carla python=3.5, conda activate carla
环境创建完成后,还要再输入命令export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:path/to/your/Anaconda3/include/python3.5m
之后再执行make launch即可
然后是make PythonAPI, 这里会出现问题说在PythonAPI/carla/dependicies/lib里面找不到libboost_python35.a文件,看了Github的 issues里面提到了可以把libboost_python27.a拷贝一份为libboost_python35.a,但是我试过了虽然可以make成功,但是之后执行Python,import carla就会报错, Pystring_type not define。我研究了一下Util/BuildTools/Setup.sh文件,在其中和boost相关的部分我们可以看到对于python3的安装,有以下语句:
./b2 toolset="${BOOST_TOOLSET}" cxxflags="${BOOST_CFLAGS}" --prefix="../${BOOST_BASENAME}-install" -j
在这一句里面增加
--with-python include="path/to/your/anaconda3/envs/carla/include/python3.5m/"
然后再编译即可。
注意如果之前采用拷贝libboost_python27.a为libboost_python35.a的方式编译过,那么需要把path/to/your/anaconda3/envs/carla/lib/python3.5/site-packages里面的carlaXXX.egg文件删掉,把easy-install.pth里面相应的那行也删掉。
最后编译make package,应该就没有遇到什么问题了。可以增加-j10的参数(10表示用10个CPU核心来make,加快速度,根据你的环境来设置)