前言:由CJ大哥以官方文档,对Carla Scenario Runner的探索,通过ros-bridge搭起的;如果不走ros-bridge可以尝试leaderboard那边。但其实如果真的做商业的算法测试,建议使用商业仿真的平台,以小钱钱能够搞定的事,就别 人继续探索了,Carla我觉得还是适合个人学习使用,采采数据 用用ground truth做初步验证,没有实车的时候 开开车啥的。
Scenario Runner是Carla仿真器里自带的一些场景测试,主要用来测试自身的算法,可以进行单元测试,也可以进行整体的测试等,以下为参考官方的文档,CJ大哥探索后写的中文版
1. 安装
1.1 下载:注意需要下载对应carla版本的Scenario Runner (SR)
Releases · carla-simulator/scenario_runner
1.2 安装依赖: 建议使用conda环境
cd xxx/scenario_runner-0.9.11
#Python 2.x
sudo apt remove python-networkx #if installed, remove old version of networkx
pip2 install --user -r requirements.txt
#Python 3.x
sudo apt remove python3-networkx #if installed, remove old version of networkx
pip3 install --user -r requirements.txt
1.3 添加环境变量
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
export SCENARIO_RUNNER_PATH=<path_to_scenario_runner>
2. 运行 SR example
./CarlaUE4.sh
python scenario_runner.py --scenario FollowLeadingVehicle_1 --reloadWorld
python manual_control.py
这只是相当于生成了world环境,车辆控制还需要运行自己的程序调用carla pythonAPI 进行控制
python scenario_runner.py --list
可以看到所有的场景
也可以通过Group:运行一类场景。命令如下;
python scenario_runner.py --scenario group:FollowLeadingVehicle
下面是所有场景类型
-
List of scenarios
FollowLeadingVehicle
The scenario realizes a common driving behavior, in which the user-controlled ego vehicle follows a leading car driving down a given road in Town01. At some point the leading car slows down and finally stops. The ego vehicle has to react accordingly to avoid a collision. The scenario ends either via a timeout, or if the ego vehicle stopped close enough to the leading vehicleFollowLeadingVehicleWithObstacle
This scenario is very similar to ‘FollowLeadingVehicle’. The only difference is, that in front of the leading vehicle is a (hidden) obstacle that blocks the way.VehicleTurningRight
In this scenario the ego vehicle takes a right turn from an intersection where a cyclist suddenly drives into the way of the ego vehicle,which has to stop accordingly. After some time, the cyclist clears the road, such that ego vehicle can continue driving.VehicleTurningLeft
This scenario is similar to ‘VehicleTurningRight’. The difference is that the ego vehicle takes a left turn from an intersection.OppositeVehicleRunningRedLight
In this scenario an illegal behavior at an intersection is tested. An other vehicle waits at an intersection, but illegally runs a red traffic light. The approaching ego vehicle has to handle this situation correctly, i.e. despite of a green traffic light, it has to stop and wait until the intersection is clear again. Afterwards, it should continue driving.StationaryObjectCrossing
In this scenario a cyclist is stationary waiting in the middle of the road and blocking the way for the ego vehicle. Hence, the ego vehicle has to stop in front of the cyclist.DynamicObjectCrossing
This is similar to ‘StationaryObjectCrossing’, but with the difference that the cyclist is dynamic. It suddenly drives into the way of the ego vehicle, which has to stop accordingly. After some time, the cyclist will clear the road, such that the ego vehicle can continue driving.NoSignalJunctionCrossing
This scenario tests negotiation between two vehicles crossing cross each other through a junction without signal. The ego vehicle is passing through a junction without traffic lights And encounters another vehicle passing across the junction. The ego vehicle has to avoid collision and navigate across the junction to succeed.ControlLoss
In this scenario control loss of a vehicle is tested due to bad road conditions, etc and it checks whether the vehicle is regained its control and corrected its course.ManeuverOppositeDirection
In this scenario vehicle is passing another vehicle in a rural area, in daylight, under clear weather conditions, at a non-junction and encroaches into another vehicle traveling in the opposite direction.OtherLeadingVehicle
The scenario realizes a common driving behavior, in which the user-controlled ego vehicle follows a leading car driving down a given road. At some point the leading car has to decelerate. The ego vehicle has to react accordingly by changing lane to avoid a collision and follow the leading car in other lane. The scenario ends via timeout, or if the ego vehicle drives certain distance.SignalizedJunctionRightTurn
In this scenario right turn of hero actor without collision at signalized intersection is tested. Hero Vehicle is turning right in an urban area, at a signalized intersection and turns into the same direction of another vehicle crossing straight initially from a lateral direction.SignalizedJunctionLeftTurn
In this scenario hero vehicle is turning left in an urban area, at a signalized intersection and cuts across the path of another vehicle coming straight crossing from an opposite direction.
此外,在运行时可以对运行情况进行录制,并在Carla中回放
python scenario_runner.py --scenario <scenario_name> --record <path/to/save/the/recorder/file>
在python脚本中通过
client.replay_file("recording01.log", start, duration, camera)
进行回放
3. 场景设置
SR 有两种模式,一种是继承基类自己写脚本,还没试过,详见官方doc
Create a new scenario - CARLA ScenarioRunner
另一种是直接加载OpenSCENARIO的xosc文件
OpenSCENARIO support - CARLA ScenarioRunner
4. 使用carla ros_bridge启动 SR
建议使用master版本的ros-bridge,旧版本都有很多bug
运行demo (跟车场景)
roslaunch carla_ad_demo carla_ad_demo_with_scenario.launch
点击左下角的 Excute 就会开始场景
不想用carla的demo agent的话可以参考上面的launch文件,将agent改成自己的程序
5. 已知问题
-
ros_bridge里通过process在新进程里启动SR,导致新进程貌似不会自动activate conda的环境,我是自己在系统python里也装了依赖才能正常启动,更好的解决方法有待探索
update: 好像发现了原因, 但是还需看看怎么添加conda的环境变量
-
unicode错误,已在master分支解决,旧版本需要自己改一下
-
xosc文件里 ScenarioObject的name需要和carla设置的一致, 比如你是ego_vehicle 就需要改成ego_vehicle
-
ros_bridge目前貌似只支持了OpenSCENARIO的文件格式,python方式有待日后更新