无人驾驶—Scenario 场景
Carla 觉得还是适合个人去研究无人驾驶,今天介绍的 Scenario 可以帮助
内容简介
- 首先介绍什么是 Scenario 以及如何运行 Scenario
- Scenario 大致的结构,场景的创建和代理创建
- 局限性和未来的工作方向
Scenario 的定义
scenario 可以完成复杂编排出一些特征的驾驶场景,也就是设计出一个特定驾驶场景让我们控制的车辆(角色)做出反应采取措施,在图中就给出了一个这样场景,一只鹿正在穿过道路,一辆车辆需要刹车避免与它相撞。
Scenario 提供许多场景用于选择,这些场景大致分为 4 个类别分别为车辆的控制、变道行驶、障碍物检测以及各种十字路口出现场景等。
安装
因此,scenario Runner 是基于Carla的引擎,可以用来执行这些类型的情况,它是用Python开发的,并利用Carla的Python API。
运行 Scenario
运行 scenario 有 3 种方式
- 直接运行 scenario
python scenario_runner.py --scenario <ScenarioName>
- 在 routes 下运行 scenario
python scenario_runner.py --scenario <ScenarioName> --additionalScenario
还可以使用 OpenSCENARIO 文件去运行 scenario
我们先看第一种运行 scenario 的方式,python scenario_runner.py --scenario <ScenarioName>
这里 ScenarioName
对应配置文件中 scenario 对象的 name 属性,
python scenario_runner.py --scenario OppositeVehicleRunningRedLight_1 --config RunningRedLight.xml
<?xml version="1.0"?>
<scenarios>
<scenario name="OppositeVehicleRunningRedLight_1" type="OppositeVehicleRunningRedLight" town="Town03">
<ego_vehicle x="-2.8" y="-184" z="1" yaw="90" model="vehicle.lincoln.mkz_2017" />
</scenario>
这里 --config
指定读取的配置 xml 文件,而 --scenario
指定的是读取是 xml 中的哪一个场景,还可以通过 --additionalScenario
来添加额外的 screnaio 文件
<?xml version="1.0"?>
<scenarios>
<scenario name="ChangeLane_1" type="ChangeLane" town="Town04">
<ego_vehicle x="284.4" y="16.4" z="2.5" yaw="-173" model="vehicle.lincoln.mkz_2017" />
<!-- spawn actors-->
<other_actor x="264.4" y="16.3" z="-500" yaw="-179" model="vehicle.tesla.model3" />
<other_actor x="184.4" y="14.9" z="-500" yaw="-176" model="vehicle.volkswagen.t2" />
<weather cloudiness="0" precipitation="0" precipitation_deposits="0" wind_intensity="0" sun_azimuth_angle="0" sun_altitude_angle="75" />
</scenario>
<scenario name="ChangeLane_2" type="ChangeLane" town="Town01">
<ego_vehicle x="107" y="133.5" z="0.5" yaw="0" model="vehicle.lincoln.mkz_2017" />
</scenario>
</scenarios>
对于 scenario 对象
- name 属性: 场景名称
- type 属性: 场景的类型
- town 属性: 场景地图
python scenario_runner.py --scenario ChangeLane_1
python manual_control.py
运行 Scenario 命令行参数解释
- 可以
weather
设置天气,可以通过参数控制天气状况,以便查看天气对驾驶影响程度
<scenarios>
<scenario name="FollowLeadingVehicle_1" type="FollowLeadingVehicle" town="Town01">
<ego_vehicle x="107" y="133" z="0.5" yaw="0" model="vehicle.lincoln.mkz_2017" />
<weather cloudiness="0" precipitation="0" precipitation_deposits="0" wind_intensity="0" sun_azimuth_angle="0" sun_altitude_angle="75" />
</scenario>
- 通过一系列配置可将输出文件用于后期分析
parser.add_argument('--output', action="store_true", help='Provide results on stdout')
parser.add_argument('--file', action="store_true", help='Write results into a txt file')
parser.add_argument('--junit', action="store_true", help='Write results into a junit file')
parser.add_argument('--json', action="store_true", help='Write results into a JSON file')
parser.add_argument('--outputDir', default='', help='Directory for output files (default: this directory)')
- 开启调试模式,会输出调试信息帮助定位错误
parser.add_argument('--debug', action="store_true", help='Run with debug output')
- 在 scenario 中,也可以指定运行路径
parser.add_argument(
'--route', help='Run a route as a scenario (input: (route_file,scenario_file,[route id]))', nargs='+', type=str)
<?xml version="1.0"?>
<routes>
<route id="0" town="Town02">
<waypoint x="-3.6973562240600586" y="179.0623321533203" z="0.0" pitch="0.0" roll="0.0" yaw="-90.06791687011719" />
<waypoint x="-3.74371337890625" y="139.95481872558594" z="0.0" pitch="0.0" roll="0.0" yaw="-90.06791687011719" />
<waypoint x="11.363693237304688" y="109.63178253173828" z="0.0" pitch="360.0" roll="0.0" yaw="0.0161895751953125" />
<waypoint x="94.48065185546875" y="109.6552963256836" z="0.0" pitch="360.0" roll="0.0" yaw="0.0162200927734375" />
<waypoint x="141.0159149169922" y="109.66847229003906" z="0.0" pitch="360.0" roll="0.0" yaw="0.016265869140625" />
parser.add_argument('--configFile', default='', help='Provide an additional scenario configuration file (*.xml)')
parser.add_argument('--additionalScenario', default='', help='Provide additional scenario implementations (*.py)')
- 可以通过
--repetitions
指定行为要重复次数,默认是运行 1 次
parser.add_argument('--repetitions', default=1, type=int, help='Number of scenario executions')
Scenario
我们来看这张 Scenario 的结构图
首先通过运行 Scenario 的命令行传入的命令收集配置文件,并调用对应解析器对文件进行解析,解析这些配置文件后拿到 world 和 scenario 的配置信息后进行初始化,然后进入主循环开始模拟场景,场景结束后进行清理工作,然后检查是否还有其他场景,如果就继续进入下一次循环知道没有任何遗漏的场景后变退出程序
转载自:https://juejin.cn/post/7132485892706402318