Ubuntu菜鳥快速上手用於強化學習的TORCS无人驾驶训练开发环境
TORCS是一个开源的赛车仿真模拟器,可使用synaptic安装。
Gym-TORCS是一个模仿Open-AI接口的TORCS的python封装,用于在TORCS上测试增强学习算法。
一、安装pip:
sudo apt-get install python-pip
sudo pip install --upgrade pip
二、安装python 3
三、安装xautomation:
sudo apt-get install xautomation
四、安装OpenAI-Gym:https://github.com/openai/gym
1、为了便于管理,需要先装anaconda. 具体下载和安装步骤如下:
Step1. 下载anaconda安装包 .推荐利用清华镜像来下载,下载地址为:
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive 。
Step2. 安装anaconda。下载完成anaconda后,安装包会在Dowloads文件夹下,在终Ctrl+Alt+T打开终端)键入cd Downloads, 然后键入 bash Anaconda3_4.3.0-Linux-x86_64.sh(小技巧,键入bash an然后按Tab键,linux系统会自动补全后面的名字)
Step3. 安装过程会询问你是否将路径安装到环境变量中,键入yes, 至此Anaconda安装完成。你会在目录/home/你的用户名文件夹下面看到anaconda3。关掉终端,再开一个,这样环境变量才起作用。
2、利用anaconda建一个虚拟环境。
Anaconda创建虚拟环境的格式为:conda create –-name 你要创建的名字 python=版本号。比如我创建的虚拟环境名字为gymlab(你可以用自己的环境名), 用的python版本号为3.5,可这样写:
conda create –-name gymlab python=3.5
操作完此步之后,会在anaconda3/envs文件夹下多一个gymlab。Python3.5就在gymlab下得lib文件夹中。
3、安裝 gym
Step1:将gym克隆到计算机上:
git clone https://github.com/openai/gym.git
如果你的电脑没有安装git,那么键入
sudo apt install git
Step2:进入gym文件夹
cd gym
Step3:安装一些依赖项
apt-get install -y python-numpy python-dev cmake zlib1g-dev libjpeg-dev xvfb libav-tools xorg-dev python-opengl libboost-all-dev libsdl2-dev swig
Step4:进行完全安装
pip install -e
五、安装Gym-TORCS:https://github.com/ugo-nama-kun/gym_torcs
git clone https://github.com/ugo-nama-kun/gym_torcs.git
先要安装gym_torcs目录下的vtorcs-RL-color,進入到vtorcs-RL-color下打開命令窗口:
cd gym_torcs
cd vtorcs-RL-color
sudo apt-get install libglib2.0-dev libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev libplib-dev libopenal-dev libalut-dev libxi-dev libxmu-dev libxrender-dev libxrandr-dev libpng12-dev
./configure
make
sudo make install
sudo make datainstall
然后即可开始运行了:
sudo torcs
点击Race --> Practice --> Configure Race配置参数,点击Race --> Practice --> New Race启动服务器。
另开命令窗口:
cd ~/gym_torcs
python snakeoil3_gym.py开始自动跑车,按F2切换到第一人称视角。画面中右下方有个十字,表示右转左转油门刹车。
以上參考鏈接:
https://blog.csdn.net/wgbarry/article/details/82827981
https://zhuanlan.zhihu.com/p/26985029
https://blog.csdn.net/lingyun_csdn/article/details/79212415
https://blog.csdn.net/ss910/article/details/77618425
備注:How to display the car in the video screen
鏈接:https://github.com/ugo-nama-kun/gym_torcs/issues/7
you can recover the car body by modifying 280th line of grscreen.cpp
for (i = 0; i < s->_ncars; i++) {
grDrawCar(cars[i], curCar, dispCam->getDrawCurrent(), dispCam->getDrawDriver(), s->currentTime, dispCam);
}
You should modify i =1 to i = 0. After the compile, you will be able to see the car body.
i=0 represent the first car, that is the agent. And other numbers are opponent cars.
For car mirrors, you should uncomment 361-366 lines in grscreen.cpp
/* MIRROR */
if (mirrorFlag && curCam->isMirrorAllowed ()) {
mirrorCam->display ();
glViewport (scrx, scry, scrw, scrh);
}
To show the map, tachometers etc. I remember that we should uncomment appropriate methods in 841-845 lines of cGrBoard::refreshBoard in grboard.cpp.
void cGrBoard::refreshBoard(tSituation *s, float Fps, int forceArcade, tCarElt *curr)
{
if (arcadeFlag || forceArcade) {
grDispArcade(curr, s);
} else {
if (debugFlag) grDispDebug(Fps, curr);
if (GFlag) grDispGGraph(curr);
if (boardFlag) grDispCarBoard(curr, s);
if (leaderFlag) grDispLeaderBoard(curr, s);
if (counterFlag) grDispCounterBoard2(curr);
}
//trackMap->display(curr, s, Winx, Winy, Winw, Winh);
}
修改完成之後要編譯:
cd gym_torcs
cd vtorcs-RL-color
make
sudo make install
sudo make datainstall
這樣就會出現車啦