Lasvsim OpenAPI SDK for Python - A client library for accessing Lasvsim's simulation platform
Project description
Lasvsim OpenAPI SDK for Python
千行仿真平台(Lasvsim)的 Python SDK。提供了一种简单直观的方式来控制和获取自动驾驶场景的仿真。
安装
您可以直接从PyPI安装该软件包:
pip install lasvsim-openapi
快速开始
以下是 SDK 使用的简单示例:
import os
from lasvsim_openapi.client import Client
from lasvsim_openapi.http_client import HttpConfig
from lasvsim_openapi.simulator import SimulatorConfig
# 接口地址
endpoint = os.getenv("QX_ENDPOINT") # 线上环境地址: https://qianxing-api.risenlighten.com
# 授权token
token = os.getenv("QX_TOKEN") # 登录仿真平台后访问https://qianxing.risenlighten.com/#/usecenter/personalCenter, 点击最下面按钮复制token
# 登录仿真平台, 选择想要进行联合仿真的任务及剧本
task_id = 0 # 替换为你的任务ID
record_id = 0 # 替换为你的剧本ID
# 1. 初始化客户端
cli = Client(HttpConfig(
endpoint=endpoint, # 接口地址
token=token, # 授权token
))
# 2. 拷贝剧本, 返回的结构中new_record_id字段就是新创建的剧本ID
# 仿真结束后可到该剧本下查看结果详情
new_record = cli.process_task.copy_record(task_id, record_id)
print("拷贝剧本成功")
# 3. 通过拷贝的场景Id、Version和SimRecordId初始化仿真器
simulator = cli.init_simulator_from_config({
"scen_id": new_record.scen_id,
"scen_ver": new_record.scen_ver,
"sim_record_id": new_record.sim_record_id,
})
print("初始化仿真器成功")
try:
# 获取测试车辆列表
test_vehicle_list = simulator.get_test_vehicle_id_list()
print("测试车辆ID列表:", test_vehicle_list)
# 使测试车辆环形行驶
for i in range(50):
# 设置方向盘转角10度, 纵向加速度0.05
ste_wheel = 10.0
lon_acc = 0.05
# 设置车辆的控制信息
simulator.set_vehicle_control_info(test_vehicle_list.list[0], ste_wheel, lon_acc)
# 执行仿真器步骤
step_res = simulator.step()
print(f"第 {i} 步结果: {step_res}")
# 可在此处继续调用其他接口, 查看联合仿真文档: https://www.risenlighten.com/#/union
# 仿真结束后, 到千行仿真平台对应的taskId/recordId下查看联合仿真结果详情
print(f"https://qianxing.risenlighten.com/#/configuration/circleTask?id={task_id}")
# 如想直接查看本次联合仿真的回放视频, 可访问下面网址:
print(f"https://qianxing.risenlighten.com/#/sampleRoad/cartest/?id={task_id}&record_id={new_record.new_record_id}&sim_record_id={new_record.sim_record_id}")
finally:
# 停止仿真器, 释放服务器资源
simulator.stop()
可用API
仿真器API
仿真控制
init_simulator_from_config(sim_config): 从配置初始化仿真器init_simulator_from_sim(simulation_id, addr): 从现有仿真初始化仿真器step(): 仿真前进一步stop(): 停止仿真reset(reset_traffic_flow): 重置仿真器到初始状态,可选择是否重置交通流
车辆API
get_vehicle_id_list(): 获取所有车辆IDget_test_vehicle_id_list(): 获取测试车辆IDget_vehicle_base_info(id_list): 获取车辆基本信息get_vehicle_position(id_list): 获取车辆位置get_vehicle_moving_info(id_list): 获取车辆运动信息get_vehicle_control_info(id_list): 获取车辆控制参数get_vehicle_perception_info(vehicle_id): 获取车辆感知信息get_vehicle_reference_lines(vehicle_id): 获取可用参考线get_vehicle_planning_info(vehicle_id): 获取车辆规划信息get_vehicle_navigation_info(vehicle_id): 获取车辆导航信息get_vehicle_collision_status(vehicle_id): 检查车辆碰撞状态get_vehicle_target_speed(vehicle_id): 获取车辆目标速度set_vehicle_position(vehicle_id, point, phi): 设置车辆位置和航向角set_vehicle_control_info(vehicle_id, ste_wheel, lon_acc): 设置车辆控制参数set_vehicle_planning_info(vehicle_id, planning_path): 设置车辆规划路径set_vehicle_moving_info(vehicle_id, u, v, w, u_acc, v_acc, w_acc): 设置车辆运动参数set_vehicle_base_info(vehicle_id, base_info): 设置车辆基本信息
交通流API
get_traffic_flow_info(): 获取交通流信息get_traffic_flow_vehicle_info(vehicle_id): 获取交通流车辆信息get_traffic_flow_vehicle_list(): 获取交通流车辆列表get_traffic_flow_vehicle_position(vehicle_id): 获取交通流车辆位置get_traffic_flow_vehicle_moving_info(vehicle_id): 获取交通流车辆运动信息get_traffic_flow_vehicle_control_info(vehicle_id): 获取交通流车辆控制信息
场景API
get_scene_info(): 获取场景信息get_scene_objects(): 获取场景物体列表get_scene_object_info(object_id): 获取场景物体信息get_scene_object_position(object_id): 获取场景物体位置get_scene_object_moving_info(object_id): 获取场景物体运动信息get_scene_object_control_info(object_id): 获取场景物体控制信息
路网API
get_lane_info(lane_id): 获取车道信息get_lane_list(): 获取车道列表get_lane_center_line(lane_id): 获取车道中心线get_lane_boundary(lane_id): 获取车道边界get_lane_width(lane_id): 获取车道宽度get_lane_speed_limit(lane_id): 获取车道限速get_lane_type(lane_id): 获取车道类型get_lane_direction(lane_id): 获取车道方向get_lane_predecessor(lane_id): 获取前序车道get_lane_successor(lane_id): 获取后继车道
路口API
get_junction_info(junction_id): 获取路口信息get_junction_list(): 获取路口列表get_junction_center_point(junction_id): 获取路口中心点get_junction_boundary(junction_id): 获取路口边界get_junction_type(junction_id): 获取路口类型get_junction_direction(junction_id): 获取路口方向get_junction_predecessor(junction_id): 获取前序路口get_junction_successor(junction_id): 获取后继路口get_movement_list(junction_id): 获取移动列表
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lasvsim-openapi-0.1.12a0.tar.gz
(25.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lasvsim-openapi-0.1.12a0.tar.gz.
File metadata
- Download URL: lasvsim-openapi-0.1.12a0.tar.gz
- Upload date:
- Size: 25.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad4e8bdcd1da32ab974de9463a347364df8150a76673f19c67ceccbf8be6739d
|
|
| MD5 |
0b52b83688dd5c66b1103e43b15a8b2f
|
|
| BLAKE2b-256 |
378bc3ba9f8fe06f9d040a0a06a583b3ac7fbf9490c53b627acce0d9802b2b29
|
File details
Details for the file lasvsim_openapi-0.1.12a0-py3-none-any.whl.
File metadata
- Download URL: lasvsim_openapi-0.1.12a0-py3-none-any.whl
- Upload date:
- Size: 49.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e82d464b0c2e6182718f3a41256684fe715463f928b08cfa562cfd3c6cb06385
|
|
| MD5 |
2acf5e681287cb0f2ab43d4e2250e934
|
|
| BLAKE2b-256 |
ce29ba593a02fa04dc259778b026c8030e75b1f9d2e442f4875d64fe7fe42db7
|