概述
目录
前言
接上回,本文介绍如何在lgsvl仿真软件自定义仿真场景,配置ego车辆的传感器参数,定义npc的行为,更完善的功能需要配合unity使用,但本文不涉及。(看本篇前最好先仔细研读官方文档,这里讲的不是很细)
一、ego车辆配置
1.传感器类型
1.1Color Camera
可视化彩色摄像头显示的是传感器配置中定义的正常跟随和自由摄像头可见的相同内容。
配置参数:
1.2LiDAR
可视化激光雷达显示检测到的点云。
配置参数:
1.3GPS
该传感器以经度/纬度和北向/东向坐标输出车辆的GPS位置以及车辆速度。
1.4IMU
该传感器以100 Hz的固定速率输出。IMU发布第二个主题已更正IMU数据的主题的数据。
1.5LGSVL Control
该传感器是车辆订阅ROS或ROS2中发布的控制主题
(消息类型lgsvl_msgs/VehicleControlData
)所必需的。
1.6Keyboard Control
该传感器是车辆接受键盘控制命令所必需的。参数不是必需的,但可以反转输入。
1.7Depth Camera
“可视化深度”(Visualized Depth)摄影机根据摄影机和对象之间的距离显示按灰度着色的对象。
1.8Segmentation Camera
可视化分割相机显示根据对象标记着色的对象。
Tag | Color | Hex Value |
---|---|---|
Car | Blue | #120E97 |
Road | Purple | #7A3F83 |
Sidewalk | Orange | #BA8350 |
Vegetation | Green | #71C02F |
Obstacle | White | #FFFFFF |
TrafficLight | Yellow | #FFFF00 |
Building | Turquoise | #238688 |
Sign | Dark Yellow | #C0C000 |
Shoulder | Pink | #FF00FF |
Pedestrian | Red | #FF0000 |
Curb | Dark Purple | #4A254F |
如果“实例分段标记”中包含一个标记,则具有该标记的每个对象实例的颜色都不同,但所有实例都具有相同的色调。
1.9Radar
可视化雷达显示了雷达锥,并创建了线框,将NPC封装在绿色框中,自行车封装在青色框中,其他EGO封装在品红色框中。
1.103D Ground Truth
可视化的3D地面真相创建了线框,将行人围在黄色框中,NPC围在绿色框中。
1.11Lane-line Sensor
可视化车道线传感器将当前车道的线显示为彩色图像的覆盖,透视图在JSON参数中定义。
2.完整传感器配置文件示例
[
{
"params": {
"Frequency": 12.5,
"Topic": "/nmea_sentence",
"Frame": "gps",
"IgnoreMapOrigin": true
},
"transform": {
"x": 0,
"y": 0,
"z": 0,
"pitch": 0,
"yaw": 0,
"roll": 0
},
"name": "GPS",
"parent": null,
"pluginId": "75bbcbfa-fdca-4703-8e82-abf8078f7991",
"sortKey": 0,
"plugin": {
"isFavored": true,
"isShared": false,
"isOwned": false,
"accessInfo": {
"userAccessType": "favored",
"owner": {
"id": "0d888b00-fa53-47c1-882a-b68391268a11",
"firstName": "SVL",
"lastName": "Content"
}
},
"supportedSimulatorVersions": [
"2021.3",
"2021.2",
"2021.2.2",
"2021.1",
"2021.1.1"
],
"id": "75bbcbfa-fdca-4703-8e82-abf8078f7991",
"name": "GPS Device Sensor",
"type": "GpsSensor",
"category": "sensor",
"ownerId": "0d888b00-fa53-47c1-882a-b68391268a11",
"accessType": "public",
"description": "This sensor outputs the GPS location of the vehicle in Longitude/Latitude and Northing/Easting coordintates.nSee https://www.svlsimulator.com/docs/simulation-content/sensors-list/#gps-device for more details.",
"copyright": "LG Electronics Inc.",
"licenseName": "LG Content",
"imageUrl": "/api/v1/assets/download/preview/f73de137-d067-47db-9fb7-242aae49b2ad",
"status": "active",
"owner": {
"id": "0d888b00-fa53-47c1-882a-b68391268a11",
"firstName": "SVL",
"lastName": "Content"
},
"shareRequests": []
},
"type": "GpsSensor"
},
{
"params": {
"Frequency": 12.5,
"Topic": "/odom",
"Frame": "gps",
"IgnoreMapOrigin": true
},
"transform": {
"x": 0,
"y": 0,
"z": 0,
"pitch": 0,
"yaw": 0,
"roll": 0
},
"name": "GPS Odometry",
"parent": null,
"pluginId": "483f7b90-2f76-42ee-82c1-22f02f25f924",
"sortKey": 1,
"plugin": {
"isFavored": true,
"isShared": false,
"isOwned": false,
"accessInfo": {
"userAccessType": "favored",
"owner": {
"id": "0d888b00-fa53-47c1-882a-b68391268a11",
"firstName": "SVL",
"lastName": "Content"
}
},
"supportedSimulatorVersions": [
"2021.3",
"2021.2",
"2021.2.2",
"2021.1",
"2021.1.1"
],
"id": "483f7b90-2f76-42ee-82c1-22f02f25f924",
"name": "GPS Odometry Sensor",
"type": "GpsOdometrySensor",
"category": "sensor",
"ownerId": "0d888b00-fa53-47c1-882a-b68391268a11",
"accessType": "public",
"description": "This sensor outputs the GPS location of the vehicle in Longitude/Latitude and Northing/Easting coordintates and the vehicle velocity.nSee https://www.svlsimulator.com/docs/simulation-content/sensors-list/#gps-odometry for more details.",
"copyright": "LG Electronics Inc.",
"licenseName": "LG Content",
"imageUrl": "/api/v1/assets/download/preview/d47cccd4-a029-4c03-87ef-3a5d3c1994a0",
"status": "active",
"owner": {
"id": "0d888b00-fa53-47c1-882a-b68391268a11",
"firstName": "SVL",
"lastName": "Content"
},
"shareRequests": []
},
"type": "GpsOdometrySensor"
},
{
"params": {
"Topic": "/imu_raw",
"Frame": "imu"
},
"transform": {
"x": 0,
"y": 0,
"z": 0,
"pitch": 0,
"yaw": 0,
"roll": 0
},
"name": "IMU",
"parent": null,
"pluginId": "9c34ec28-627d-4e73-9bb0-9c2aa7e978f5",
"sortKey": 2,
"plugin": {
"isFavored": true,
"isShared": false,
"isOwned": false,
"accessInfo": {
"userAccessType": "favored",
"owner": {
"id": "0d888b00-fa53-47c1-882a-b68391268a11",
"firstName": "SVL",
"lastName": "Content"
}
},
"supportedSimulatorVersions": [
"2021.3",
"2021.2",
"2021.2.2",
"2021.1",
"2021.1.1"
],
"id": "9c34ec28-627d-4e73-9bb0-9c2aa7e978f5",
"name": "IMU Sensor",
"type": "ImuSensor",
"category": "sensor",
"ownerId": "0d888b00-fa53-47c1-882a-b68391268a11",
"accessType": "public",
"description": "This sensor output at a fixed rate of 100 Hz. IMU publishes data on topics where the 2nd topic has corrected IMU data.nSee https://www.svlsimulator.com/docs/simulation-content/sensors-list/#imu for more details.",
"copyright": "LG Electronics Inc.",
"licenseName": "LG Content",
"imageUrl": "/api/v1/assets/download/preview/cf06a7ce-85d0-4edd-a1e1-ca11992800c2",
"status": "active",
"owner": {
"id": "0d888b00-fa53-47c1-882a-b68391268a11",
"firstName": "SVL",
"lastName": "Content"
},
"shareRequests": []
},
"type": "ImuSensor"
},
{
"params": {
"LaserCount": 64,
"MinDistance": 3,
"MaxDistance": 100,
"RotationFrequency": 10,
"MeasurementsPerRotation": 1024,
"FieldOfView": 45,
"CenterAngle": 10,
"Compensated": true,
"PointColor": "#FF0000FF",
"Topic": "/points_raw",
"Frame": "velodyne"
},
"transform": {
"x": 0,
"y": 1.78734,
"z": 1.02,
"pitch": 0,
"yaw": -0.85943669,
"roll": 0
},
"name": "Lidar",
"parent": null,
"pluginId": "b30d0478-8c7b-4687-bfc2-b3cdb3f5faff",
"sortKey": 3,
"plugin": {
"isFavored": true,
"isShared": false,
"isOwned": false,
"accessInfo": {
"userAccessType": "favored",
"owner": {
"id": "0d888b00-fa53-47c1-882a-b68391268a11",
"firstName": "SVL",
"lastName": "Content"
}
},
"supportedSimulatorVersions": [
"2021.3",
"2021.2",
"2021.2.2",
"2021.1",
"2021.1.1"
],
"id": "b30d0478-8c7b-4687-bfc2-b3cdb3f5faff",
"name": "Lidar Sensor",
"type": "LidarSensor",
"category": "sensor",
"ownerId": "0d888b00-fa53-47c1-882a-b68391268a11",
"accessType": "public",
"description": "This sensor returns a point cloud after 1 revolution.nSee https://www.svlsimulator.com/docs/simulation-content/sensors-list/#lidar for more details.",
"copyright": "LG Electronics Inc.",
"licenseName": "LG Content",
"imageUrl": "/api/v1/assets/download/preview/dd44a969-c038-4966-a39f-a445ab3b6c00",
"status": "active",
"owner": {
"id": "0d888b00-fa53-47c1-882a-b68391268a11",
"firstName": "SVL",
"lastName": "Content"
},
"shareRequests": []
},
"type": "LidarSensor"
},
{
"name": "Keyboard Car Control",
"parent": null,
"pluginId": "a2ff904a-ff06-4f06-9e45-cb58217a7142",
"sortKey": 4,
"plugin": {
"isFavored": true,
"isShared": false,
"isOwned": false,
"accessInfo": {
"userAccessType": "favored",
"owner": {
"id": "0d888b00-fa53-47c1-882a-b68391268a11",
"firstName": "SVL",
"lastName": "Content"
}
},
"supportedSimulatorVersions": [
"2021.3",
"2021.2",
"2021.2.2",
"2021.1",
"2021.1.1"
],
"id": "a2ff904a-ff06-4f06-9e45-cb58217a7142",
"name": "Keyboard Control Sensor",
"type": "KeyboardControlSensor",
"category": "sensor",
"ownerId": "0d888b00-fa53-47c1-882a-b68391268a11",
"accessType": "public",
"description": "This sensor is required for a vehicle to accept keyboard control commands. Parameters are not required.nSee https://www.svlsimulator.com/docs/simulation-content/sensors-list/#keyboard-control for more details.",
"copyright": "LG Electronics Inc.",
"licenseName": "LG Content",
"imageUrl": "/api/v1/assets/download/preview/7d0e8f41-8f38-4b0f-9e36-1ab6540ea6df",
"status": "active",
"owner": {
"id": "0d888b00-fa53-47c1-882a-b68391268a11",
"firstName": "SVL",
"lastName": "Content"
},
"shareRequests": []
},
"type": "KeyboardControlSensor"
},
{
"params": {
"Topic": "/vehicle_cmd"
},
"name": "Autoware Car Control",
"parent": null,
"pluginId": "76ff7bd1-81bf-4284-b9bf-e8173dc6053e",
"sortKey": 5,
"plugin": {
"isFavored": true,
"isShared": false,
"isOwned": false,
"accessInfo": {
"userAccessType": "favored",
"owner": {
"id": "0d888b00-fa53-47c1-882a-b68391268a11",
"firstName": "SVL",
"lastName": "Content"
}
},
"supportedSimulatorVersions": [
"2021.3",
"2021.2",
"2021.2.2",
"2021.1",
"2021.1.1"
],
"id": "76ff7bd1-81bf-4284-b9bf-e8173dc6053e",
"name": "AutowareAi Control Sensor",
"type": "AutowareAiControlSensor",
"category": "sensor",
"ownerId": "0d888b00-fa53-47c1-882a-b68391268a11",
"accessType": "public",
"description": "Sensor for subscribing to vehicle control topic from Autoware AI to drive the ego vehicle in the simulator.",
"copyright": "LG Electronics Inc.",
"licenseName": "LG Content",
"imageUrl": "/api/v1/assets/download/preview/0e4cf3c0-81e1-41b6-879c-fdb8e8634036",
"status": "active",
"owner": {
"id": "0d888b00-fa53-47c1-882a-b68391268a11",
"firstName": "SVL",
"lastName": "Content"
},
"shareRequests": []
},
"type": "AutowareAiControlSensor"
},
{
"params": {
"Width": 1444,
"JpegQuality": 15,
"FieldOfView": 25.3,
"Topic": "/camera_fl/image/compressed",
"Frame": "camera_fl"
},
"transform": {
"x": -0.17502,
"y": 1.1257099999999998,
"z": 1.83787,
"pitch": -5.41366775,
"yaw": 5.51836698,
"roll": -0.3626822843
},
"name": "camera_fl",
"parent": null,
"pluginId": "3d4f1e08-4c62-4e9f-b859-b26d4910b85e",
"sortKey": 6,
"plugin": {
"isFavored": true,
"isShared": false,
"isOwned": false,
"accessInfo": {
"userAccessType": "favored",
"owner": {
"id": "0d888b00-fa53-47c1-882a-b68391268a11",
"firstName": "SVL",
"lastName": "Content"
}
},
"supportedSimulatorVersions": [
"2021.3",
"2021.2",
"2021.2.2",
"2021.1",
"2021.1.1"
],
"id": "3d4f1e08-4c62-4e9f-b859-b26d4910b85e",
"name": "Color Camera Sensor",
"type": "ColorCameraSensor",
"category": "sensor",
"ownerId": "0d888b00-fa53-47c1-882a-b68391268a11",
"accessType": "public",
"description": "This is the type of sensor that would be used for the Main Camera in Apollo.nColor Camera also has multiple post processing sensor effects that can be added to the Postprocessing field in params. Effects can be combined with an array of Postprocessing fields but order is hard coded.nSee https://www.svlsimulator.com/docs/simulation-content/sensors-list/#color-camera for more details.",
"copyright": "LG Electronics Inc.",
"licenseName": "LG Content",
"imageUrl": "/api/v1/assets/download/preview/f9073a10-2920-4ba8-863c-93faa7c6496a",
"status": "active",
"owner": {
"id": "0d888b00-fa53-47c1-882a-b68391268a11",
"firstName": "SVL",
"lastName": "Content"
},
"shareRequests": []
},
"type": "ColorCameraSensor"
},
{
"params": {
"Frame": "camera_fr",
"Width": 1444,
"JpegQuality": 15,
"FieldOfView": 32.8,
"Topic": "/camera_fr/image/compressed"
},
"transform": {
"x": 0.26893,
"y": 1.13617,
"z": 1.7976,
"pitch": -9.21352384,
"yaw": 26.221051,
"roll": -5.3800737
},
"name": "camera_fr",
"parent": null,
"pluginId": "3d4f1e08-4c62-4e9f-b859-b26d4910b85e",
"sortKey": 7,
"plugin": {
"isFavored": true,
"isShared": false,
"isOwned": false,
"accessInfo": {
"userAccessType": "favored",
"owner": {
"id": "0d888b00-fa53-47c1-882a-b68391268a11",
"firstName": "SVL",
"lastName": "Content"
}
},
"supportedSimulatorVersions": [
"2021.3",
"2021.2",
"2021.2.2",
"2021.1",
"2021.1.1"
],
"id": "3d4f1e08-4c62-4e9f-b859-b26d4910b85e",
"name": "Color Camera Sensor",
"type": "ColorCameraSensor",
"category": "sensor",
"ownerId": "0d888b00-fa53-47c1-882a-b68391268a11",
"accessType": "public",
"description": "This is the type of sensor that would be used for the Main Camera in Apollo.nColor Camera also has multiple post processing sensor effects that can be added to the Postprocessing field in params. Effects can be combined with an array of Postprocessing fields but order is hard coded.nSee https://www.svlsimulator.com/docs/simulation-content/sensors-list/#color-camera for more details.",
"copyright": "LG Electronics Inc.",
"licenseName": "LG Content",
"imageUrl": "/api/v1/assets/download/preview/f9073a10-2920-4ba8-863c-93faa7c6496a",
"status": "active",
"owner": {
"id": "0d888b00-fa53-47c1-882a-b68391268a11",
"firstName": "SVL",
"lastName": "Content"
},
"shareRequests": []
},
"type": "ColorCameraSensor"
},
{
"params": {
"Topic": "/clock"
},
"name": "Clock Sensor",
"parent": null,
"pluginId": "968f386f-dc0b-485d-ba33-5bb71bff93ef",
"sortKey": 8,
"plugin": {
"isFavored": true,
"isShared": false,
"isOwned": false,
"accessInfo": {
"userAccessType": "favored",
"owner": {
"id": "0d888b00-fa53-47c1-882a-b68391268a11",
"firstName": "SVL",
"lastName": "Content"
}
},
"supportedSimulatorVersions": [
"2021.3",
"2021.2",
"2021.2.2",
"2021.1",
"2021.1.1"
],
"id": "968f386f-dc0b-485d-ba33-5bb71bff93ef",
"name": "Clock Sensor",
"type": "ClockSensor",
"category": "sensor",
"ownerId": "0d888b00-fa53-47c1-882a-b68391268a11",
"accessType": "public",
"description": "This sensor outputs simulated time to ROS as rosgraph_msgs/Clock message, or to CyberRT as clock message. The only parameter to use is topic/channel name.nSee https://www.svlsimulator.com/docs/simulation-content/sensors-list/#clock for more details.",
"copyright": "LG Electronics Inc.",
"licenseName": "LG Content",
"imageUrl": "/api/v1/assets/download/preview/fb75d445-2e83-440f-8268-c9d4e65024ae",
"status": "active",
"owner": {
"id": "0d888b00-fa53-47c1-882a-b68391268a11",
"firstName": "SVL",
"lastName": "Content"
},
"shareRequests": []
},
"type": "ClockSensor"
},
{
"params": {
"Topic": "/move_base_simple/goal"
},
"name": "Destination Sensor",
"parent": null,
"pluginId": "3f1db91f-4eed-43b2-99ed-c78c129d6aa1",
"sortKey": 9,
"plugin": {
"isFavored": true,
"isShared": false,
"isOwned": false,
"accessInfo": {
"userAccessType": "favored",
"owner": {
"id": "0d888b00-fa53-47c1-882a-b68391268a11",
"firstName": "SVL",
"lastName": "Content"
}
},
"supportedSimulatorVersions": [
"2021.3",
"2021.2",
"2021.2.2",
"2021.1",
"2021.1.1"
],
"id": "3f1db91f-4eed-43b2-99ed-c78c129d6aa1",
"name": "Destination Sensor",
"type": "DestinationSensor",
"category": "sensor",
"ownerId": "0d888b00-fa53-47c1-882a-b68391268a11",
"accessType": "public",
"description": "The Destination Sensor is used to set an initial pose or a destination pose of an attached agent for Navigation2 stack via python API scripts. The sensor publishes to ROS and ROS2 using the `geometry_msgs/PoseStamped` message type.nSee https://www.svlsimulator.com/docs/simulation-content/sensors-list/#destination-sensor for more details.",
"copyright": "LG Electronics Inc.",
"licenseName": "LG Content",
"imageUrl": "/api/v1/assets/download/preview/8bb43ad1-cc31-4da3-8bb6-53060343d59e",
"status": "active",
"owner": {
"id": "0d888b00-fa53-47c1-882a-b68391268a11",
"firstName": "SVL",
"lastName": "Content"
},
"shareRequests": []
},
"type": "DestinationSensor"
}
]
各个模块可以在网站在线可视化编辑,json配置文件自动生成,网站也提供了别人公开的配置参数。
二、自定义npc
1.通过VSE
可视化场景编辑器(VSE)是一种用于SVL模拟器可视化创建和编辑场景的工具。每个场景都代表一个测试用例。VSE专注于使用可视化控件快速创建场景,同时支持自定义脚本化插件来扩展工具面板。(使用前请务必安装好docker并配置,方法参看上一篇)
这部分详细内容,参看官网教程:Using VSE - SVL Simulator
1.1加载自动驾驶车辆
将新自动驾驶汽车放置到场景中需要将其从候选面板中拖动。在要添加的候选类型上按鼠标左键,然后将其拖到地图上;释放按钮将小车放置在地图上。可以以相同的方式添加不同的小车类型。如果要取消添加小车,请在拖动代理时按鼠标右键。如果在UI上完成拖动,它也将取消拖动。默认情况下,小车将捕捉到地图车道;可以在“文件”面板中切换此选项。
VSE列出了所有添加到云库的可选车辆,这些车辆可用于使用的模拟器版本。需要下载的Ego车辆名称包含两个云图标,第一次按下它们的按钮将调用下载过程。
1.2加载NPCs和pedestrians
可选他车类型有如下几种:
行人类型自行查看。
1.3编辑路点路径控制目标运动
目标点播放路径使用相同的路点路径来设置回放模式中的自动移动。用户可以根据需要在路径中设置任意多个路点,并对每个路点进行参数化。使用Add waypoints(添加航路点)按钮开始编辑路径点坐标,它将在现有路径的末端添加一个路径点。使用鼠标右键取消添加航路点,使用鼠标左键在当前位置添加航路点。可以通过这种方式添加多个航路点,直到取消操作。目标朝第一个路径点运动。创建的路径点可以像其他场景元素一样进行编辑,选中后可以删除、移动或用户可以编辑其参数。选择一个路径点并单击“添加下一步”后,可以在所选路径点之后添加更多路径点。VSE可以更改循环参数,当选择循环时,当到达最后一个路径点时,目标将从开始处继续移动。
路径点支持匀速线性运动和均匀加速运动。当加速度参数设置为0时,目标将以设置的速度不断移动。如果加速度大于零,则速度参数确定目标在加速时可以达到的最大速度。如果当前速度大于设定速度,则加速度变为减速参数,目标尝试减速到确定的速度。如果加速度值不够大,则在移动过程中可能无法达到设定速度。下面的动画比较了左侧没有加速度的移动和右侧设置了加速度的移动。
VSE支持两种不同的路径:线性和Bezier样条线。选择了Bezier样条线路径类型后,具有选定线性路径的目标将从一个航路点直接行驶到另一个航路,模拟器使用Bezier样线算法使移动平滑。下面的动画显示了具有相同路点但不同路径类型的路径。左侧的车辆使用线性路径,右侧的车辆使用Bezier样条线路径。
1.4设置行为
NPC支持控制车辆的各种行为脚本。VSE提供所有可用NPC行为的下拉列表,所选行为保存在场景中。某些行为可以参数化,例如,NPCLaneFollowBehavior获得isLaneChange切换参数和maxSpeed值。只有具有NPCWaypointBehavior的NPC支持编辑路径点。
1.5设置触发器
编辑路径点允许将不同的触发效应器添加到此点。添加到一个路径点的所有效应器并行执行。某些效应器需要其他设置和参数。每个效应器都可以使用自定义编辑面板。(可以复制和粘贴触发器。使用复制图标(“触发器”标题左侧的按钮)复制效应器,然后使用粘贴图标(“触发”标题右侧的按钮)将效应器复制到另一个航路点。)
a.碰撞时间触发器
该效应器计算NPC是否会与任何自我产生碰撞,计算当前方向、速度和加速度。NPC将等待前往下一个路径点,以便与自我车辆发生碰撞。如果没有发现可能的碰撞,NPC不会等待。
b.距离触发器
添加此效应器使NPC在路径点等待,直到任何自我车辆距离此触发效应器设置的最大距离(以米为单位)更近。如果没有自我车辆足够接近,NPC可以无限等待。
c.时间触发器
NPC将在该路径点等待固定时间(以秒为单位),然后继续向下一个航路点移动。
d.等待点
等待点使NPC等待,直到任何ego车辆进入激活区。通过拖动“移动”按钮,可以像其他场景元素一样移动激活区域。如果需要,激活区的半径(以米为单位)可以在航路点的编辑面板中更改,也可以通过向左(缩小)或向右(放大)拖动调整大小按钮来更改。
e.控制触发器 (不太明白)
当触发器被调用时,该触发器效应器将将编辑的策略应用于所有标记的可控对象。单击“标记可控对象”按钮,然后单击贴图上的可控对象以使用该效应器标记它们,右键单击可取消标记过程。一个控制触发器只能标记一种类型的可控对象,但允许使用多个控制触发器。
以上是主要操作方式,还有其他细节,请自行参看官方文档。
完成自定义场景后,导出保存至pc。但是VSE方式只支持与apollo的cyberrt桥接,使用autoware框架或者ROS均不可用,无法建立通讯,lgsvl开发者说当前版本(2021.03)不支持,后续版本考虑完善功能。(但是似乎跑路了?)
2.通过python脚本
上节说道通过VSE自定义场景只支持与apollo的联仿,可以通过python api定义场景解决这个问题。官方在github提供了可参考的api代码。链接如下:
GitHub - lgsvl/PythonAPI: Python API for Simulator
这里细节很多,暂时记录一些,有空再补充。以下代码以使用ROS桥接为例,
1.一般开头
#!/usr/bin/env python3
from environs import Env
import lgsvl
import os
env = Env()
#设置接口ip,一般照抄
SIMULATOR_HOST = os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1")
SIMULATOR_PORT = int(os.environ.get("LGSVL__SIMULATOR_PORT", 8181))
BRIDGE_HOST = os.environ.get("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1")
BRIDGE_PORT = int(os.environ.get("LGSVL__AUTOPILOT_0_PORT", 9090))
2.加载地图,在某位置放置ego车辆,并建立ros桥接
#加载地图
sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT)
sim.load(env.str("LGSVL__MAP"))
#加载ego
#lgsvl.wise.DefaultAssets.ego_jaguae2015xe_autowareai默认为ros桥接类型,别的自行更换
spawns = sim.get_spawn()
egoState = lgsvl.AgentState()
egoState.transform = sim.get_spawn()[0]
forward = lgsvl.utils.transform_to_forward(spawns[0])
egoState.transform.position += 5 * forward
ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_jaguae2015xe_autowareai), lgsvl.AgentType.EGO, egoState)
#建立ros桥接
ego.connect_bridge(BRIDGE_HOST, BRIDGE_PORT)
3.在某位置放置NPC,这里以SUV为例,其他类似
#放置NPC
state = lgsvl.AgentState()
state.transform.position = lgsvl.Vector(-0.0690141469240189,-1.8853896856308,-1.20359134674072)
state.transform.rotation = lgsvl.Vector(0.574522316455841,194.449142456055,-1.33408848412842E-08)
npc = sim.add_agent("SUV", lgsvl.AgentType.NPC, state)
4.设置该NPC的运动路径与方式
#定义路径点
waypoints = [
lgsvl.DriveWaypoint(lgsvl.Vector(-3.97260928153992,-1.97720015048981,-12.9610614776611), 6, 0, lgsvl.Vector(0.424606323242188,198.366668701172,-6.67028965395389E-09), 0, False, 0),
lgsvl.DriveWaypoint(lgsvl.Vector(-10.8697671890259,-1.91862571239471,-26.5176544189453), 6, 0, lgsvl.Vector(359.779357910156,206.965530395508,-3.33507799155086E-09), 0, False, 0),
lgsvl.DriveWaypoint(lgsvl.Vector(-18.8122711181641,-1.8330100774765,-57.7039413452148), 6, 0, lgsvl.Vector(359.847564697266,194.288299560547,1.66753244545959E-09), 0, False, 0)
#lgsvl.DriveWaypoint(lgsvl.Vector(50.0579299926758,-7.15255964678363E-07,-20.0973262786865), 6, 0, lgsvl.Vector(4.63607071569255E-13,2.18559765815735,-7.58303235786685E-22), 0, False, 0)
]
#启动NPC
npc.follow(waypoints, loop = True, waypoints_path_type = "BezierSpline")
5.设置NPC的行为与触发器
#暂缺
6.结束仿真,可有可无,如果不设置退出时间,仿真将在所有车辆、行人全部完成至少一轮运动后退出
#设置仿真时间45s
sim.run(45.0)
7.开始仿真
使用步骤请参看Running Simulator篇的Creating and running a Python Test Case Simulation部分。
仿真效果:
小技巧:
虽然VSE不能直接用来与ROS或autoware联仿,但是可以导出需要的路径点数据,这些路径点坐标可以用在python脚本中。
"waypoints":[ {"ordinalNumber":0, "position":{"x":-49.0670700073242,"y":-7.15255794148106E-07,"z":-41.71923828125}, "angle":{"x":-6.66072719982674E-13,"y":304.128051757813,"z":0}, "speed":6, "acceleration":0, "waitTime":0, "trigger":{"effectors":[]}} ]
参考文献
总结
本篇说明了如何在ROS环境下,配置ego车辆传感器,使用lgsvl自定义仿真场景。
欢迎交流,联系Q1456055290
最后
以上就是斯文大象为你收集整理的基于ROS与LGSVL的自动驾驶仿真开发教程前言一、ego车辆配置二、自定义npc参考文献总结的全部内容,希望文章能够帮你解决基于ROS与LGSVL的自动驾驶仿真开发教程前言一、ego车辆配置二、自定义npc参考文献总结所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复