Skip to content

Commit

Permalink
fix: removed empty files and translated Chinese to English (#1063)
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoFei9704 committed Apr 12, 2024
1 parent 61101a0 commit 7d119a5
Show file tree
Hide file tree
Showing 33 changed files with 70 additions and 154 deletions.
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()
```

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

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

<<<<<<< HEAD
# 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
>>>>>>> fd07c11... fix: removed empty files and translated Chinese to English

# pylint: enable=line-too-long
from srunner.scenariomanager.carla_data_provider import CarlaDataProvider
Expand Down Expand Up @@ -57,7 +62,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 +106,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 +141,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 All @@ -162,7 +163,10 @@ def visit_parameter_declaration(self, node: ast_node.ParameterDeclaration):
vehicle_class = getattr(vehicles, para_type)
v_ins = vehicle_class()

<<<<<<< HEAD
# TODO: Analyzing and setting vehicle configuration parameters requires parsing the keep statement
=======
>>>>>>> fd07c11... fix: removed empty files and translated Chinese to English
v_ins.set_name(para_name)
if para_name == OSC2Helper.ego_name:
self.father_ins.add_ego_vehicles(v_ins)
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
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
12 changes: 5 additions & 7 deletions tests/test-ast-listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@

import graphviz

# node:入参,树的节点
# nodes:入参,按遍历的顺序给节点编号,用编号给节点连线
# pindex:父节点的编号
# g:graphviz的图对象
# node:node of the tree
# nodes:number the nodes in traversal order and line them with numbers
# pindex:id of the parent node
# g:graphviz
def render_ast(node, nodes, pindex, g):
if not isinstance(node, Tuple):
name = str(node)
Expand All @@ -39,7 +39,7 @@ def render_ast(node, nodes, pindex, g):
g.node(str(index), name)
if index != pindex:
# g.edge(str(index), str(pindex))
g.edge(str(pindex), str(index)) # 边是从父到子,要不会出现倒立的树
g.edge(str(pindex), str(index))
if isinstance(node, ast_node.AST):
for i in range(0, node.get_child_count()):
render_ast(node.get_child(i), nodes, index, g)
Expand Down Expand Up @@ -143,7 +143,6 @@ def main(input_stream):

if __name__ == '__main__':
error_file_list = []
# 如果测试的为文件夹
if os.path.isdir(sys.argv[1]):
filepath = sys.argv[1]
files = os.listdir(filepath)
Expand All @@ -161,7 +160,6 @@ def main(input_stream):
for error_file in error_file_list:
LOG_INFO(error_file)

# 如果测试的为单个文件
elif os.path.isfile(sys.argv[1]):
new_file, import_msg = Preprocess(sys.argv[1]).import_process()
input_stream = FileStream(new_file, encoding='utf-8')
Expand Down
17 changes: 6 additions & 11 deletions tests/test-ast-visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
from srunner.osc2.osc_preprocess.pre_process import ImportFile, Preprocess
import graphviz

# node:入参,树的节点
# nodes:入参,按遍历的顺序给节点编号,用编号给节点连线
# pindex:父节点的编号
# g:graphviz的图对象
# node:node of the tree
# nodes:number the nodes in traversal order and line them with numbers
# pindex:id of the parent node
# g:graphviz
def render_ast(node, nodes, pindex, g):
if not isinstance(node, Tuple):
name = str(node)
Expand All @@ -38,7 +38,7 @@ def render_ast(node, nodes, pindex, g):
g.node(str(index), name)
if index != pindex:
# g.edge(str(index), str(pindex))
g.edge(str(pindex), str(index)) # 边是从父到子,要不会出现倒立的树
g.edge(str(pindex), str(index))
if isinstance(node, ast_node.AST):
for i in range(0, node.get_child_count()):
render_ast(node.get_child(i), nodes, index, g)
Expand Down Expand Up @@ -162,11 +162,9 @@ def main(input_stream):


if __name__ == '__main__':
print("执行预处理")
error_file_list = []
# 如果测试的为文件夹
if not os.path.exists(sys.argv[1]):
print("文件路径错误!")
print("File path error")
if os.path.isdir(sys.argv[1]):
filepath = sys.argv[1]
files = os.listdir(filepath)
Expand All @@ -184,10 +182,7 @@ def main(input_stream):
for error_file in error_file_list:
LOG_INFO(error_file)

# 如果测试的为单个文件
elif os.path.isfile(sys.argv[1]):
print("执行预处理")
# 预处理,展开import,返回file类型对象和存储预处理信息的对象
new_file, import_msg = Preprocess(sys.argv[1]).import_process()
input_stream = FileStream(new_file, encoding='utf-8')
if main(input_stream)>0:
Expand Down
Loading

0 comments on commit 7d119a5

Please sign in to comment.