lasvsim-openapi 0.1.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lasvsim-openapi-0.1.8/PKG-INFO +154 -0
- lasvsim-openapi-0.1.8/README.md +131 -0
- lasvsim-openapi-0.1.8/lasvsim_openapi/__init__.py +2 -0
- lasvsim-openapi-0.1.8/lasvsim_openapi/client.py +32 -0
- lasvsim-openapi-0.1.8/lasvsim_openapi/http_client.py +58 -0
- lasvsim-openapi-0.1.8/lasvsim_openapi/main.py +418 -0
- lasvsim-openapi-0.1.8/lasvsim_openapi/process_task.py +43 -0
- lasvsim-openapi-0.1.8/lasvsim_openapi/process_task_model.py +39 -0
- lasvsim-openapi-0.1.8/lasvsim_openapi/qxmap_model.py +728 -0
- lasvsim-openapi-0.1.8/lasvsim_openapi/request_model.py +25 -0
- lasvsim-openapi-0.1.8/lasvsim_openapi/resources.py +20 -0
- lasvsim-openapi-0.1.8/lasvsim_openapi/response_model.py +971 -0
- lasvsim-openapi-0.1.8/lasvsim_openapi/sim_record.py +63 -0
- lasvsim-openapi-0.1.8/lasvsim_openapi/sim_record_model.py +282 -0
- lasvsim-openapi-0.1.8/lasvsim_openapi/simulator.py +439 -0
- lasvsim-openapi-0.1.8/lasvsim_openapi/train_task.py +26 -0
- lasvsim-openapi-0.1.8/lasvsim_openapi.egg-info/PKG-INFO +154 -0
- lasvsim-openapi-0.1.8/lasvsim_openapi.egg-info/SOURCES.txt +21 -0
- lasvsim-openapi-0.1.8/lasvsim_openapi.egg-info/dependency_links.txt +1 -0
- lasvsim-openapi-0.1.8/lasvsim_openapi.egg-info/requires.txt +1 -0
- lasvsim-openapi-0.1.8/lasvsim_openapi.egg-info/top_level.txt +1 -0
- lasvsim-openapi-0.1.8/setup.cfg +4 -0
- lasvsim-openapi-0.1.8/setup.py +48 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: lasvsim-openapi
|
|
3
|
+
Version: 0.1.8
|
|
4
|
+
Summary: Lasvsim OpenAPI SDK for Python - A client library for accessing Lasvsim's simulation platform
|
|
5
|
+
Home-page: https://github.com/rl-lasvsim/openapi-sdk-python
|
|
6
|
+
Author: Zhihong Luo
|
|
7
|
+
Author-email: luozhihong@risenlighten.com
|
|
8
|
+
Project-URL: Source, https://github.com/rl-lasvsim/openapi-sdk-python
|
|
9
|
+
Project-URL: Bug Reports, https://github.com/rl-lasvsim/openapi-sdk-python/issues
|
|
10
|
+
Keywords: Qianxing,Lasvsim,自动驾驶,OpenAPI,Simulation,Autonomous Driving
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.0
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
Requires-Dist: requests>=2.25.0
|
|
23
|
+
|
|
24
|
+
# Lasvsim OpenAPI SDK for Python
|
|
25
|
+
|
|
26
|
+
千行仿真平台的Python SDK。提供了一种简单直观的方式来控制和获取自动驾驶场景的仿真。
|
|
27
|
+
|
|
28
|
+
## 安装
|
|
29
|
+
|
|
30
|
+
您可以直接从PyPI安装该软件包:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install lasvsim-openapi
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## 快速开始
|
|
37
|
+
|
|
38
|
+
以下是SDK使用的简单示例:
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from lasvsim.client import Client
|
|
42
|
+
from lasvsim.http_client import HttpConfig
|
|
43
|
+
from lasvsim.simulator import SimulatorConfig
|
|
44
|
+
from lasvsim.request_model import Point
|
|
45
|
+
|
|
46
|
+
# 初始化客户端
|
|
47
|
+
client = Client(
|
|
48
|
+
HttpConfig(
|
|
49
|
+
token="your_token_here",
|
|
50
|
+
endpoint="your_endpoint_here"
|
|
51
|
+
)
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
# 从训练任务中获取可用场景
|
|
55
|
+
res = client.train_task.get_scene_id_list(task_id)
|
|
56
|
+
print(f"可用场景: {res}")
|
|
57
|
+
|
|
58
|
+
# 创建仿真器实例
|
|
59
|
+
simulator = client.init_simulator_from_config(
|
|
60
|
+
SimulatorConfig(
|
|
61
|
+
scenario_id=res.scene_id_list[0],
|
|
62
|
+
scenario_version=res.scene_version_list[0]
|
|
63
|
+
)
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
# 运行仿真步骤
|
|
67
|
+
for i in range(10):
|
|
68
|
+
step_res = simulator.step()
|
|
69
|
+
print(f"第 {i} 步结果: {step_res}")
|
|
70
|
+
# 获取车辆信息
|
|
71
|
+
vehicle_ids = simulator.get_vehicle_id_list()
|
|
72
|
+
print(f"车辆ID列表: {vehicle_ids}")
|
|
73
|
+
|
|
74
|
+
# 控制车辆运动
|
|
75
|
+
simulator.set_vehicle_control_info(
|
|
76
|
+
vehicle_id="test_vehicle_1",
|
|
77
|
+
ste_wheel=1.2,
|
|
78
|
+
lon_acc=1.1
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
# 设置车辆位置
|
|
82
|
+
simulator.set_vehicle_position(
|
|
83
|
+
vehicle_id="test_vehicle_1",
|
|
84
|
+
point=Point(x=-8.75, y=-537.0316, z=0)
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
# 停止仿真
|
|
88
|
+
simulator.stop()
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## 可用API
|
|
92
|
+
|
|
93
|
+
### 仿真器API
|
|
94
|
+
|
|
95
|
+
#### 仿真控制
|
|
96
|
+
- `init_from_config(sim_config)`: 从配置初始化仿真器
|
|
97
|
+
- `init_from_sim(simulation_id, addr)`: 从现有仿真初始化仿真器
|
|
98
|
+
- `step()`: 仿真前进一步
|
|
99
|
+
- `stop()`: 停止仿真
|
|
100
|
+
- `reset(reset_traffic_flow)`: 重置仿真器到初始状态,可选择是否重置交通流
|
|
101
|
+
|
|
102
|
+
#### 车辆API
|
|
103
|
+
- `get_vehicle_id_list()`: 获取所有车辆ID
|
|
104
|
+
- `get_test_vehicle_id_list()`: 获取测试车辆ID
|
|
105
|
+
- `get_vehicle_base_info(id_list)`: 获取车辆基本信息
|
|
106
|
+
- `get_vehicle_position(id_list)`: 获取车辆位置
|
|
107
|
+
- `get_vehicle_moving_info(id_list)`: 获取车辆运动信息
|
|
108
|
+
- `get_vehicle_control_info(id_list)`: 获取车辆控制参数
|
|
109
|
+
- `get_vehicle_perception_info(vehicle_id)`: 获取车辆感知信息
|
|
110
|
+
- `get_vehicle_reference_lines(vehicle_id)`: 获取可用参考线
|
|
111
|
+
- `get_vehicle_planning_info(vehicle_id)`: 获取车辆规划信息
|
|
112
|
+
- `get_vehicle_navigation_info(vehicle_id)`: 获取车辆导航信息
|
|
113
|
+
- `get_vehicle_collision_status(vehicle_id)`: 检查车辆碰撞状态
|
|
114
|
+
- `get_vehicle_target_speed(vehicle_id)`: 获取车辆目标速度
|
|
115
|
+
- `set_vehicle_position(vehicle_id, point, phi)`: 设置车辆位置和航向角
|
|
116
|
+
- `set_vehicle_control_info(vehicle_id, ste_wheel, lon_acc)`: 设置车辆控制参数
|
|
117
|
+
- `set_vehicle_planning_info(vehicle_id, planning_path)`: 设置车辆规划路径
|
|
118
|
+
- `set_vehicle_moving_info(vehicle_id, u, v, w, u_acc, v_acc, w_acc)`: 设置车辆运动参数
|
|
119
|
+
- `set_vehicle_base_info(vehicle_id, base_info)`: 设置车辆基本信息
|
|
120
|
+
- `set_vehicle_link_nav(vehicle_id, link_nav)`: 设置车辆链接导航信息
|
|
121
|
+
- `set_vehicle_destination(vehicle_id, destination)`: 设置车辆目标点
|
|
122
|
+
|
|
123
|
+
#### 交通信号灯API
|
|
124
|
+
- `get_current_stage(junction_id)`: 获取当前交通信号灯阶段
|
|
125
|
+
- `get_movement_signal(movement_id)`: 获取转向信号灯颜色
|
|
126
|
+
- `get_signal_plan(junction_id)`: 获取交通信号灯配时方案
|
|
127
|
+
- `get_movement_list(junction_id)`: 获取路口转向列表
|
|
128
|
+
|
|
129
|
+
#### 行人API
|
|
130
|
+
- `get_ped_id_list()`: 获取所有行人ID
|
|
131
|
+
- `get_ped_base_info(ped_id_list)`: 获取行人基本信息
|
|
132
|
+
- `set_ped_position(ped_id, point, phi)`: 设置行人位置和航向角
|
|
133
|
+
|
|
134
|
+
#### 非机动车API
|
|
135
|
+
- `get_nmv_id_list()`: 获取所有非机动车ID
|
|
136
|
+
- `get_nmv_base_info(nmv_id_list)`: 获取非机动车基本信息
|
|
137
|
+
- `set_nmv_position(nmv_id, point, phi)`: 设置非机动车位置和航向角
|
|
138
|
+
|
|
139
|
+
### 训练任务API
|
|
140
|
+
- `get_scene_id_list(task_id)`: 获取训练任务可用场景列表
|
|
141
|
+
|
|
142
|
+
### 资源API
|
|
143
|
+
- `get_map(asset_id, asset_version)`: 获取特定资源的地图数据
|
|
144
|
+
|
|
145
|
+
## 系统要求
|
|
146
|
+
|
|
147
|
+
- Python >= 3.0
|
|
148
|
+
- requests >= 2.25.0
|
|
149
|
+
|
|
150
|
+
## 许可证
|
|
151
|
+
|
|
152
|
+
## 支持
|
|
153
|
+
|
|
154
|
+
如需报告错误或请求新功能,请使用[GitHub Issues](https://github.com/risenlighten-qianxing/openapi-sdk-python/issues)页面。
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Lasvsim OpenAPI SDK for Python
|
|
2
|
+
|
|
3
|
+
千行仿真平台的Python SDK。提供了一种简单直观的方式来控制和获取自动驾驶场景的仿真。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
您可以直接从PyPI安装该软件包:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install lasvsim-openapi
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 快速开始
|
|
14
|
+
|
|
15
|
+
以下是SDK使用的简单示例:
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from lasvsim.client import Client
|
|
19
|
+
from lasvsim.http_client import HttpConfig
|
|
20
|
+
from lasvsim.simulator import SimulatorConfig
|
|
21
|
+
from lasvsim.request_model import Point
|
|
22
|
+
|
|
23
|
+
# 初始化客户端
|
|
24
|
+
client = Client(
|
|
25
|
+
HttpConfig(
|
|
26
|
+
token="your_token_here",
|
|
27
|
+
endpoint="your_endpoint_here"
|
|
28
|
+
)
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
# 从训练任务中获取可用场景
|
|
32
|
+
res = client.train_task.get_scene_id_list(task_id)
|
|
33
|
+
print(f"可用场景: {res}")
|
|
34
|
+
|
|
35
|
+
# 创建仿真器实例
|
|
36
|
+
simulator = client.init_simulator_from_config(
|
|
37
|
+
SimulatorConfig(
|
|
38
|
+
scenario_id=res.scene_id_list[0],
|
|
39
|
+
scenario_version=res.scene_version_list[0]
|
|
40
|
+
)
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# 运行仿真步骤
|
|
44
|
+
for i in range(10):
|
|
45
|
+
step_res = simulator.step()
|
|
46
|
+
print(f"第 {i} 步结果: {step_res}")
|
|
47
|
+
# 获取车辆信息
|
|
48
|
+
vehicle_ids = simulator.get_vehicle_id_list()
|
|
49
|
+
print(f"车辆ID列表: {vehicle_ids}")
|
|
50
|
+
|
|
51
|
+
# 控制车辆运动
|
|
52
|
+
simulator.set_vehicle_control_info(
|
|
53
|
+
vehicle_id="test_vehicle_1",
|
|
54
|
+
ste_wheel=1.2,
|
|
55
|
+
lon_acc=1.1
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
# 设置车辆位置
|
|
59
|
+
simulator.set_vehicle_position(
|
|
60
|
+
vehicle_id="test_vehicle_1",
|
|
61
|
+
point=Point(x=-8.75, y=-537.0316, z=0)
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
# 停止仿真
|
|
65
|
+
simulator.stop()
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## 可用API
|
|
69
|
+
|
|
70
|
+
### 仿真器API
|
|
71
|
+
|
|
72
|
+
#### 仿真控制
|
|
73
|
+
- `init_from_config(sim_config)`: 从配置初始化仿真器
|
|
74
|
+
- `init_from_sim(simulation_id, addr)`: 从现有仿真初始化仿真器
|
|
75
|
+
- `step()`: 仿真前进一步
|
|
76
|
+
- `stop()`: 停止仿真
|
|
77
|
+
- `reset(reset_traffic_flow)`: 重置仿真器到初始状态,可选择是否重置交通流
|
|
78
|
+
|
|
79
|
+
#### 车辆API
|
|
80
|
+
- `get_vehicle_id_list()`: 获取所有车辆ID
|
|
81
|
+
- `get_test_vehicle_id_list()`: 获取测试车辆ID
|
|
82
|
+
- `get_vehicle_base_info(id_list)`: 获取车辆基本信息
|
|
83
|
+
- `get_vehicle_position(id_list)`: 获取车辆位置
|
|
84
|
+
- `get_vehicle_moving_info(id_list)`: 获取车辆运动信息
|
|
85
|
+
- `get_vehicle_control_info(id_list)`: 获取车辆控制参数
|
|
86
|
+
- `get_vehicle_perception_info(vehicle_id)`: 获取车辆感知信息
|
|
87
|
+
- `get_vehicle_reference_lines(vehicle_id)`: 获取可用参考线
|
|
88
|
+
- `get_vehicle_planning_info(vehicle_id)`: 获取车辆规划信息
|
|
89
|
+
- `get_vehicle_navigation_info(vehicle_id)`: 获取车辆导航信息
|
|
90
|
+
- `get_vehicle_collision_status(vehicle_id)`: 检查车辆碰撞状态
|
|
91
|
+
- `get_vehicle_target_speed(vehicle_id)`: 获取车辆目标速度
|
|
92
|
+
- `set_vehicle_position(vehicle_id, point, phi)`: 设置车辆位置和航向角
|
|
93
|
+
- `set_vehicle_control_info(vehicle_id, ste_wheel, lon_acc)`: 设置车辆控制参数
|
|
94
|
+
- `set_vehicle_planning_info(vehicle_id, planning_path)`: 设置车辆规划路径
|
|
95
|
+
- `set_vehicle_moving_info(vehicle_id, u, v, w, u_acc, v_acc, w_acc)`: 设置车辆运动参数
|
|
96
|
+
- `set_vehicle_base_info(vehicle_id, base_info)`: 设置车辆基本信息
|
|
97
|
+
- `set_vehicle_link_nav(vehicle_id, link_nav)`: 设置车辆链接导航信息
|
|
98
|
+
- `set_vehicle_destination(vehicle_id, destination)`: 设置车辆目标点
|
|
99
|
+
|
|
100
|
+
#### 交通信号灯API
|
|
101
|
+
- `get_current_stage(junction_id)`: 获取当前交通信号灯阶段
|
|
102
|
+
- `get_movement_signal(movement_id)`: 获取转向信号灯颜色
|
|
103
|
+
- `get_signal_plan(junction_id)`: 获取交通信号灯配时方案
|
|
104
|
+
- `get_movement_list(junction_id)`: 获取路口转向列表
|
|
105
|
+
|
|
106
|
+
#### 行人API
|
|
107
|
+
- `get_ped_id_list()`: 获取所有行人ID
|
|
108
|
+
- `get_ped_base_info(ped_id_list)`: 获取行人基本信息
|
|
109
|
+
- `set_ped_position(ped_id, point, phi)`: 设置行人位置和航向角
|
|
110
|
+
|
|
111
|
+
#### 非机动车API
|
|
112
|
+
- `get_nmv_id_list()`: 获取所有非机动车ID
|
|
113
|
+
- `get_nmv_base_info(nmv_id_list)`: 获取非机动车基本信息
|
|
114
|
+
- `set_nmv_position(nmv_id, point, phi)`: 设置非机动车位置和航向角
|
|
115
|
+
|
|
116
|
+
### 训练任务API
|
|
117
|
+
- `get_scene_id_list(task_id)`: 获取训练任务可用场景列表
|
|
118
|
+
|
|
119
|
+
### 资源API
|
|
120
|
+
- `get_map(asset_id, asset_version)`: 获取特定资源的地图数据
|
|
121
|
+
|
|
122
|
+
## 系统要求
|
|
123
|
+
|
|
124
|
+
- Python >= 3.0
|
|
125
|
+
- requests >= 2.25.0
|
|
126
|
+
|
|
127
|
+
## 许可证
|
|
128
|
+
|
|
129
|
+
## 支持
|
|
130
|
+
|
|
131
|
+
如需报告错误或请求新功能,请使用[GitHub Issues](https://github.com/risenlighten-qianxing/openapi-sdk-python/issues)页面。
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# 包含仿真器等功能的客户端
|
|
2
|
+
|
|
3
|
+
from lasvsim_openapi.simulator import Simulator, SimulatorConfig
|
|
4
|
+
from lasvsim_openapi.http_client import HttpConfig, HttpClient
|
|
5
|
+
from lasvsim_openapi.train_task import TrainTask
|
|
6
|
+
from lasvsim_openapi.resources import Resources
|
|
7
|
+
from lasvsim_openapi.process_task import ProcessTask
|
|
8
|
+
from lasvsim_openapi.sim_record import SimRecord
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Client(object):
|
|
12
|
+
train_task: TrainTask
|
|
13
|
+
resources: Resources
|
|
14
|
+
process_task: ProcessTask
|
|
15
|
+
sim_record: SimRecord
|
|
16
|
+
|
|
17
|
+
def __init__(self, config: HttpConfig):
|
|
18
|
+
print('>>>>>')
|
|
19
|
+
self.config = config
|
|
20
|
+
self.init_common_client(config)
|
|
21
|
+
|
|
22
|
+
def init_common_client(self, config: HttpConfig):
|
|
23
|
+
client = HttpClient(config, {})
|
|
24
|
+
self.train_task = TrainTask(client)
|
|
25
|
+
self.resources = Resources(client)
|
|
26
|
+
self.process_task = ProcessTask(client)
|
|
27
|
+
self.sim_record = SimRecord(client)
|
|
28
|
+
|
|
29
|
+
def init_simulator_from_config(self, sim_config: SimulatorConfig):
|
|
30
|
+
simulator = Simulator(self.config)
|
|
31
|
+
simulator.init_from_config(sim_config)
|
|
32
|
+
return simulator
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class APIError(Exception):
|
|
5
|
+
def __init__(self, status_code, message, url):
|
|
6
|
+
super().__init__(f"APIError {url} {status_code}: {message}")
|
|
7
|
+
self.status_code = status_code
|
|
8
|
+
self.message = message
|
|
9
|
+
self.url = url
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class HttpConfig(object):
|
|
13
|
+
"""
|
|
14
|
+
Configuration for the client.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(self, token: str = None, endpoint: str = None):
|
|
18
|
+
self.token = token
|
|
19
|
+
self.endpoint = endpoint
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class HttpClient(object):
|
|
23
|
+
"""
|
|
24
|
+
HTTP client for the API.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, config: HttpConfig, headers: dict):
|
|
28
|
+
self.config = config
|
|
29
|
+
self.headers = headers
|
|
30
|
+
self.headers.update({"Authorization": "Bearer " + self.config.token})
|
|
31
|
+
|
|
32
|
+
def get(self, path: str, params: dict):
|
|
33
|
+
response = requests.get(
|
|
34
|
+
self.config.endpoint + path, params, headers=self.headers
|
|
35
|
+
)
|
|
36
|
+
if response.status_code != 200:
|
|
37
|
+
raise APIError(
|
|
38
|
+
response.status_code, tryParseResponse(response), response.url
|
|
39
|
+
)
|
|
40
|
+
return response.json()
|
|
41
|
+
|
|
42
|
+
def post(self, path: str, data: dict):
|
|
43
|
+
response = requests.post(
|
|
44
|
+
self.config.endpoint + path, json=data, headers=self.headers
|
|
45
|
+
)
|
|
46
|
+
if response.status_code != 200:
|
|
47
|
+
raise APIError(
|
|
48
|
+
response.status_code, tryParseResponse(response), response.url
|
|
49
|
+
)
|
|
50
|
+
return response.json()
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def tryParseResponse(response):
|
|
54
|
+
try:
|
|
55
|
+
return response.json()
|
|
56
|
+
except:
|
|
57
|
+
print("Failed to parse response:", response.text)
|
|
58
|
+
return response.reason
|