Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
glopezdiest committed May 3, 2024
2 parents 7948291 + 4e780dc commit c034b62
Show file tree
Hide file tree
Showing 46 changed files with 180 additions and 183 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/static_code_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Install Dependencies
run: |
Expand All @@ -35,7 +35,7 @@ jobs:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Install Dependencies
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Static Code Analysis
name: Unit Tests

on:
push:
Expand All @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Install Dependencies
run: |
Expand Down
6 changes: 5 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ mkdocs:

formats: all

build:
os: ubuntu-22.04
tools:
python: "3.7"

python:
version: 3.7
install:
- requirements: Docs/requirements.txt

Expand Down
4 changes: 4 additions & 0 deletions Docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
* [CARLA ScenarioRunner 0.9.5](#carla-scenariorunner-095)
* [CARLA ScenarioRunner 0.9.2](#carla-scenariorunner-092)

## Upcoming
* Improvements to the CarlaDataProvider:
- Added `spawn_actor` for a blueprint based actor creation similar to `World.spawn_actor`

## CARLA ScenarioRunner 0.9.15
### :rocket: New Features
* Add waypoint reached threshold so that the precision of the actor reaching to waypoints can be adjusted based on object types.
Expand Down
33 changes: 25 additions & 8 deletions scenario_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,28 @@
import argparse
from argparse import RawTextHelpFormatter
from datetime import datetime
from distutils.version import LooseVersion
try:
from packaging.version import Version
except ImportError:
from distutils.version import LooseVersion as Version # Python 2 fallback
import importlib
import inspect
import os
import signal
import sys
import time
import json
import pkg_resources

try:
# requires Python 3.8+
from importlib.metadata import metadata
def get_carla_version():
return Version(metadata("carla")["Version"])
except ModuleNotFoundError:
# backport checking for older Python versions; module is deprecated
import pkg_resources
def get_carla_version():
return Version(pkg_resources.get_distribution("carla").version)

import carla

Expand All @@ -46,6 +59,9 @@
# Version of scenario_runner
VERSION = '0.9.13'

# Minimum version of CARLA that is required
MIN_CARLA_VERSION = '0.9.15'


class ScenarioRunner(object):

Expand All @@ -64,7 +80,6 @@ class ScenarioRunner(object):
# Tunable parameters
client_timeout = 10.0 # in seconds
wait_for_world = 20.0 # in seconds
frame_rate = 20.0 # in Hz

# CARLA world and scenario handlers
world = None
Expand Down Expand Up @@ -92,9 +107,9 @@ def __init__(self, args):
# requests in the localhost at port 2000.
self.client = carla.Client(args.host, int(args.port))
self.client.set_timeout(self.client_timeout)
dist = pkg_resources.get_distribution("carla")
if LooseVersion(dist.version) < LooseVersion('0.9.15'):
raise ImportError("CARLA version 0.9.15 or newer required. CARLA version found: {}".format(dist))
carla_version = get_carla_version()
if carla_version < Version(MIN_CARLA_VERSION):
raise ImportError("CARLA version {} or newer required. CARLA version found: {}".format(MIN_CARLA_VERSION, carla_version))

# Load agent if requested via command line args
# If something goes wrong an exception will be thrown by importlib (ok here)
Expand Down Expand Up @@ -336,7 +351,7 @@ def _load_and_wait_for_world(self, town, ego_vehicles=None):
if self._args.sync:
settings = self.world.get_settings()
settings.synchronous_mode = True
settings.fixed_delta_seconds = 1.0 / self.frame_rate
settings.fixed_delta_seconds = 1.0 / self._args.frameRate
self.world.apply_settings(settings)

CarlaDataProvider.set_client(self.client)
Expand Down Expand Up @@ -566,6 +581,8 @@ def main():
parser.add_argument('--sync', action='store_true',
help='Forces the simulation to run synchronously')
parser.add_argument('--list', action="store_true", help='List all supported scenarios and exit')
parser.add_argument('--frameRate', default='20', type=float,
help='Frame rate (Hz) to use in \'sync\' mode (default: 20)')

parser.add_argument(
'--scenario', help='Name of the scenario to be executed. Use the preposition \'group:\' to run all scenarios of one class, e.g. ControlLoss or FollowLeadingVehicle')
Expand Down Expand Up @@ -646,4 +663,4 @@ def main():


if __name__ == "__main__":
sys.exit(main())
sys.exit(main())
4 changes: 2 additions & 2 deletions srunner/metrics/tools/metrics_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ def parse_wheels_control(info):
max_brake_torque=float(info[11]),
max_handbrake_torque=float(info[13]),
position=carla.Vector3D(
x=float(info[17][1:-1]) / 100,
y=float(info[17][:-1]) / 100,
x=float(info[15][1:-1]) / 100,
y=float(info[16][:-1]) / 100,
z=float(info[17][:-1]) / 100)
)
return wheels_control
Expand Down
57 changes: 0 additions & 57 deletions srunner/osc2/README_zh.md

This file was deleted.

File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion srunner/osc2/symbol_manager/scenario_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def __init__(self, QualifiedBehaviorSymbol):

def is_key_found(self, sym):
if isinstance(sym, ScenarioInhertsSymbol):
# 对于继承不做重复性检查,同时停止递归
return False
if sym.name in self.symbols and sym.name:
return True
Expand Down
Empty file removed srunner/osc2_dm/movable_object.py
Empty file.
Empty file removed srunner/osc2_dm/osc_action.py
Empty file.
Empty file removed srunner/osc2_dm/osc_actor.py
Empty file.
Empty file.
60 changes: 25 additions & 35 deletions srunner/scenarioconfigs/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
本文档对config, scenario, data_bridge三个模块的功能及使用方法进行介绍
This document introduces the functions and usage methods of the three modules config, scenario and data bridge

**一、config模块**
**1. config**

概述:
- Code:srunner/scenarioconfigs/osc2_scenario_configuration.py

- 对应代码:srunner/scenarioconfigs/osc2_scenario_configuration.py
- Function: Parses the osc2 scenario description file, generates type objects in the standard library based on the type and constraint parameters, and sets parameters, for example, ego and npc related to vehicles and path related to paths

- 功能:解析osc2场景描述文件,根据类型和约束的参数配置,生成标准库里相关类型对象,并设置参数。例如,描述车辆相关的类型对象ego和npc,描述路径相关的类型对象path
Usage:

使用方法:

(1) 在scenario_runner.py和osc2_scenario.py文件中导入对应文件
(1) Import the corresponding files in the scenario runner.py and osc2 Scenario.py files

```
from srunner.scenarioconfigs.osc2_scenario_configuration import OSC2ScenarioConfiguration
```

(2) 在scenario_runner.py文件的_run_osc2(self)函数中对OSC2ScenarioConfiguration进行初始化
(2) In the scenario runner. Py files run osc2 (self) function to initialize the OSC2ScenarioConfiguration
```
# self._args.osc2表示输入的场景文件名称字符串
# self.client表示与carla模拟器建立连接的客户端
# self._args.osc2: The input scene file name string
# self.client: The client that connects to the carla simulator
config = OSC2ScenarioConfiguration(self._args.osc2, self.client)
```

(3)在scenario_runner.py文件的_load_and_run_scenario(self, config)函数中,config作为输入,对OSC2Scenario进行初始化
(3)OSC2Scenario is initialized in the load and run scenario(self, config) function of the scenario runner.py file with config as input

```
scenario = OSC2Scenario(world=self.world,
Expand All @@ -32,24 +30,22 @@ scenario = OSC2Scenario(world=self.world,
osc2_file=self._args.osc2,
timeout=100000)
```
**二、scenario模块**

概述:
**2. scenario**

- 对应代码:/srunner/scenarios/osc2_scenario.py
- Code:/srunner/scenarios/osc2_scenario.py

- 功能:根据解析osc2场景描述文件所获得的标准库对象,抽象语法树和符号表(后两者来自语法解析阶段),建立osc2场景描述文件所对应的行为树
- Function:The behavior tree corresponding to the osc2 scene description file is created based on the standard library objects obtained by parsing the osc2 scene description file, the abstract syntax tree, and the symbol table (the latter two are from the syntax parsing phase)

使用方法:
Usage:

(1) 在scenario_runner.py文件中导入对应文件
(1) Import the corresponding file in the scenario runner.py file

```
from srunner.scenarios.osc2_scenario import OSC2Scenario
```


(2) 在scenario_runner.py文件的_load_and_run_scenario(self, config)函数中,对OSC2Scenario进行初始化
(2) OSC2Scenario is initialized in the load and run scenario(self, config) functions of scenario runner.py file

```
scenario = OSC2Scenario(world=self.world,
Expand All @@ -60,30 +56,28 @@ scenario = OSC2Scenario(world=self.world,
```


(3) 以osc2_scenario.py所建立的行为树作为输入,在scenario_runner.py文件的_load_and_run_scenario(self, config)函数中,加载执行场景,并记录主车ego的行车轨迹
(3) The behavior tree established by osc2_scenario.py is used as input, and in the _Load_AND_RUN_SCENARIO (interfig) function of the SCENARIO_Runner.py file, loads the execution scene, and records the driving trajectory of the main car EGO

```
# Load scenario and run it
# self.manager是ScenarioManager类的实例化对象,对crala模拟器中场景的运行进行实时调控
# self.manager is an instantiated object of the SCENARIOMANAGER class. In real -time regulation of the operation of the scene in the Crala simulator
self.manager.load_scenario(scenario, self.agent_instance)
self.manager.data_bridge = DataBridge(self.world)
self.manager.run_scenario()
self.manager.data_bridge.end_trace()
```
`from srunner.scenariomanager.scenario_manager import ScenarioManager`

**三、data_bridge模块**
**3. data_bridge**

概述:
- Function:The purpose is to extract the data of each frame when the scene is executed, write it into the trace.json file, and use the trace data file of the main vehicle in the scene as the input of the traffic regulation assertion for judgment

- 功能:旨在提取场景执行时,每一帧的数据,将其写入trace.json文件中。将主车在场景中的轨迹数据文件trace.json作为交规断言的输入,进行判断。
Usage:

使用方法:

(1) 在scenario_runner.py文件中导入DataBridge模块
(1) Import the DataBridge module in the scenario runner.py file
`from data_bridge import DataBridge`

(2) 在scenario_runner.py文件中ScenarioRunner类的_load_and_run_scenario(self, config)函数中进行初始化
(2) Initialization is done in the load and run scenario(self, config) functions of the ScenarioRunner class in the scenario runner.py file

```
# Load scenario and run it
Expand All @@ -92,10 +86,9 @@ self.manager.data_bridge = DataBridge(self.world)
self.manager.run_scenario()
```

(3) 在srunner/scenariomanager/scenario_manager.py文件的run_scenario(self)函数中,
(3) srunner/scenariomanager/scenario_manager.py -> run_scenario(self)

```
# update_ego_vehicle_start()函数根据主车ego提供的数据进行初始化
self.data_bridge.update_ego_vehicle_start(self.ego_vehicles[0])
while self._running:
Expand All @@ -107,14 +100,11 @@ if snapshot:
timestamp = snapshot.timestamp
if timestamp:
self._tick_scenario(timestamp)
# self.data_bridge.update_trace()函数对carla world每个trick所提供的信息进行处理,从而获得交规断言所需要的轨迹数据。
self.data_bridge.update_trace()
```

(4) 在scenario_runner.py文件中ScenarioRunner类的_load_and_run_scenario(self, config)函数中:
(4) scenario_runner.py -> ScenarioRunner -> _load_and_run_scenario(self, config)
```
# end_trace()函数在场景执行结束时,对轨迹数据进行更新并写入到trace.json文件中。
self.manager.data_bridge.end_trace()
```

9 changes: 4 additions & 5 deletions srunner/scenarioconfigs/osc2_scenario_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
from srunner.osc2_dm.physical_object import *
from srunner.osc2_dm.physical_types import Physical, Range

# 标准库
from srunner.osc2_stdlib.path import Path

# pylint: disable=line-too-long
from srunner.scenarioconfigs.scenario_configuration import ScenarioConfiguration
'''
Parses the osc2 scenario description file, generates type objects in the standard
library based on the type and keep constraint parameters, and sets parameters
'''

# pylint: enable=line-too-long
from srunner.scenariomanager.carla_data_provider import CarlaDataProvider
Expand Down Expand Up @@ -57,7 +60,6 @@ def __init__(self, filename, client):
self.unit_dict = {}
self.physical_dict = {}
self.weather = carla.WeatherParameters()
# 默认为白天
self.weather.sun_azimuth_angle = 45
self.weather.sun_altitude_angle = 70

Expand Down Expand Up @@ -102,8 +104,6 @@ def visit_global_parameter_declaration(
vehicle_class = getattr(vehicles, para_type)
v_ins = vehicle_class()

# TODO: 车辆配置参数解析和设置,需要解析keep语句
# 车辆rolename=变量名
v_ins.set_name(para_name)
if para_name == "ego_vehicle":
self.father_ins.add_ego_vehicles(v_ins)
Expand Down Expand Up @@ -139,7 +139,6 @@ def visit_scenario_declaration(self, node: ast_node.ScenarioDeclaration):
self.visit_do_directive(child)

def visit_do_directive(self, node: ast_node.DoDirective):
# 场景设置信息不会出现在场景的行为描述部分
pass

def visit_parameter_declaration(self, node: ast_node.ParameterDeclaration):
Expand Down
Loading

0 comments on commit c034b62

Please sign in to comment.