Skip to content

Commit

Permalink
Merge branch 'master' into workflow-improvements-and-code-quality-pas…
Browse files Browse the repository at this point in the history
…sing
  • Loading branch information
glopezdiest committed Apr 26, 2024
2 parents 52a2cf1 + a762135 commit 97f96cd
Show file tree
Hide file tree
Showing 37 changed files with 78 additions and 161 deletions.
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
7 changes: 4 additions & 3 deletions scenario_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,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 @@ -336,7 +335,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 +565,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 +647,4 @@ def main():


if __name__ == "__main__":
sys.exit(main())
sys.exit(main())
57 changes: 0 additions & 57 deletions srunner/osc2/README_zh.md

This file was deleted.

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/environment.py
Empty file.
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
5 changes: 3 additions & 2 deletions srunner/scenariomanager/carla_data_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ def check_attribute_value(blueprint, name, value):
'train': '',
'tram': '',
'pedestrian': 'walker.pedestrian.0001',
'misc': 'static.prop.streetbarrier'
}

# Set the model
Expand Down Expand Up @@ -861,11 +862,11 @@ def request_new_batch_actors(model, amount, spawn_points, autopilot=False,
SetAutopilot(FutureActor, autopilot, CarlaDataProvider._traffic_manager_port)))

actors = CarlaDataProvider.handle_actor_batch(batch, tick)
for actor in actors:
for actor, command in zip(actors, batch):
if actor is None:
continue
CarlaDataProvider._carla_actor_pool[actor.id] = actor
CarlaDataProvider.register_actor(actor, spawn_point)
CarlaDataProvider.register_actor(actor, command.transform)

return actors

Expand Down
2 changes: 0 additions & 2 deletions srunner/scenariomanager/scenarioatomics/atomic_behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1685,12 +1685,10 @@ def update(self):
print(f'finish change speed!! current speed={curr_speed} km/h')
else:
if curr_speed < self._target_velocity:
# 加速
self._control.throttle = 1
self._control.brake = 0
print(f'current speed={curr_speed} km/h, target speed={self._target_velocity} km/h, accelerate!!! ')
else:
# 减速
self._control.throttle = 0
self._control.brake = 1
print('decelerate!!!')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def update(self):

velocity = CarlaDataProvider.get_velocity(self._actor)

if velocity > EPSILON:
if velocity > 0.1:
self._start_time = GameTime.get_time()

if GameTime.get_time() - self._start_time > self._duration:
Expand Down
2 changes: 1 addition & 1 deletion srunner/scenarios/osc2_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ def visit_behavior_invocation(self, node: ast_node.BehaviorInvocation):
# scenario_declaration_node = self.father_ins.scenario_declaration.get(behavior_invocation_name)
scenario_declaration_node_scope = scenario_declaration_node.get_scope()
arguments = self.visit_children(node)
# Stores the value of the argument before the invoked scenario was overwritten, 如a: time=None
# Stores the value of the argument before the invoked scenario was overwritten, a: time=None
# keyword_args = {}
if isinstance(arguments, List):
for arg in arguments:
Expand Down
2 changes: 1 addition & 1 deletion tests/result
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
################################
# 未定义actorName
# undefined actorName
################################

actor Path
Expand Down
2 changes: 0 additions & 2 deletions tests/run_testcase/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ def main(self, input_stream):
listener = ParseTreeWalker()
ast_builder = ASTBuilder()
listener.walk(ast_builder, tree)
# 清空import信息
import_msg.clear_msg()
# 返回收集到的日志信息
return log_msg.get_log_msg()

def testcase(self, str):
Expand Down
Loading

0 comments on commit 97f96cd

Please sign in to comment.