carla-运行openscenario场景

前言

根据carla官方描述,carla运行时分为server端和client端,通过运行./CarlaUE4.sh来启动server端服务,该服务器端会加载预设场景,并生成world,通过在另一个终端中调用API,可通过固定的端口启动client端与服务器端进行通讯,在client端可以控制server端加载新的carla map。例如官方在carla/PythonAPI/util路径下放置了config.py的脚本,可通过该脚本直接控制srver端重新载入地图。其具体命令为python3 config.py --map Town02,然后可以再回到carla/PythonAPI/examples路径下运行相应的控制脚本来控制server中产生对应的效果。
carla支持openscenario格式场景的直接导入,不过你需要先生成对应的carla map,在server端启动该map之后,再运行对应的xosc格式的文件。
carla中的scenario runner是一系列的python文件,可以在github上直接下载或者 git clone到本地,解压后即可使用。

carla_scenario_runner

网址为https://github.com/carla-simulator/scenario_runner。可以在此找到官方的说明文档。
在运行相应的场景前,你需要先安装以下内容,否则会提示python 模块导入错误。

#Python 2.x
sudo apt remove python-networkx #if installed, remove old version of networkx
pip2 install --user py_trees==0.8.3 networkx==2.2 psutil shapely xmlschema==1.0.18
#Python 3.x
sudo apt remove python3-networkx #if installed, remove old version of networkx
pip3 install --user py_trees==0.8.3 networkx==2.2 psutil shapely xmlschema

因为目前很多库都已不知此python2,所以还是建议使用python3,另外ubuntu 16.04默认的python3为python3.5,ubuntu18.04默认的python3为python3.6,后续关于carla使用的很多python库都要求python3.6及以上版本,所以最好还是使用ubuntu18.04来进行carla的安装和使用。
另外运行官方提供的示例脚本前,你还需要设置以下环境变量:

export CARLA_ROOT=/path/to/your/carla/installation
export PYTHONPATH=$PYTHONPATH:${CARLA_ROOT}/PythonAPI/carla/dist/carla-<VERSION>.egg:${CARLA_ROOT}/PythonAPI/carla/agents:${CARLA_ROOT}/PythonAPI/carla

注意根据自己的实际情况更改其路径!!!
然后你就可以开心的运行场景了。

具体步骤

1.启动carla server。

./CarlaUE4.sh

2.打开另一个终端作为client与server通讯,并运行案例场景。

python scenario_runner.py --scenario FollowLeadingVehicle_1 --reloadWorld

你可以通过运行以下命令来启动carla场景运行器的帮助文档。

python scenario_runner.py --help

3.如果要控制场景内车辆的运行,可以再打开一个终端并运行:

python manual_control.py

运行一个场景类下的所有场景

与前面的例子类似,你可以执行一个场景类下的所有场景,例如"FollowLeadingVehicle"类的所有场景。

python scenario_runner.py --scenario group:FollowLeadingVehicle


## [](https://github.com/carla-simulator/scenario_runner/blob/master/Docs/getting_started.md#running-other-scenarios)

运行openscenario场景

你可以通过以下命令运行openscenario场景。

python scenario_runner.py --openscenario <path/to/xosc-file>

运行基于路线的场景

可以通过如下方式运行基于路线的场景:

python scenario_runner.py --route <path/to/route-file> <path/to/scenario_sample_file> [route id]

例如:

python scenario_runner.py /scenario_runner/srunner/challenge/routes_debug.xml /scenario_runner/srunner/challenge/all_towns_traffic_scenarios1_3_4.json 0

如果没有提供路线,则会自动执行文件夹下的所有路线。
针对基于路线的场景,也可以通过自动驾驶代理来控制ego车辆,在srunner/challenge/autoagents/路径下官方提供了一些案例,可以通过以下方式运行类似的代理:

python scenario_runner.py /scenario_runner/srunner/challenge/routes_debug.xml /scenario_runner/srunner/challenge/all_towns_traffic_scenarios1_3_4.json 0 --agent /scenario_runner/srunner/challenge/autoagents/human_agent.py

更过的具体信息请参看官方的说明文档。

https://github.com/carla-simulator/scenario_runner/blob/master/Docs/getting_started.md

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容