首先OSM,下载地图,实测范围,一次下载一个互通范围刚刚够,
然后导入GM,删除多余元素。
以上准备工作。
然后需要CMD进入D:\UE\CARLA_0.9.14_01\WindowsNoEditor\PythonAPI\util>
执行代码:
python osm_to_xodr.py -i ...\...\Downloads\map1jh.osm -o D:\UE\CARLA_0.9.14_01\WindowsNoEditor\PythonAPI\util\out1jh.xodr
也就是:python osm_to_xodr.py -i xxx.osm -o xxx.xodr
然后自己新建个脚本用于导入xodr到UE4。Importxodr:
import carla
try:
print("================ Starting ================")
# 创建一个客户端
client = carla.Client('localhost', 2000)
client.set_timeout(5)
# 加载OpenDrive地图
xodr_path = r'D:\UE\CARLA_0.9.14_01\WindowsNoEditor\PythonAPI\util\out1jhjh.xodr'
with open(xodr_path, encoding='utf-8') as od_file:
data = od_file.read()
vertex_distance = 2.0 # in meters
max_road_length = 500.0 # in meters
wall_height = 0.5 # in meters
extra_width = 1 # in meters
world = client.generate_opendrive_world(
data, carla.OpendriveGenerationParameters(
vertex_distance=vertex_distance,
max_road_length=max_road_length,
wall_height=wall_height,
additional_width=extra_width,
smooth_junctions=True,
enable_mesh_visibility=True))
print("the current world is:", world)
#
except Exception as e:
print("Exception detected:", e)
finally:
pass
print("================ ending ================")
然后修改代码:
修改spawn_npc_sumo.py
在180行加入
修改run_synchronization.py
在160,左右加入以上代码,注意会报错,要加入carla、random的引用
注意使用import random 而不是from random import random 。
然后进入\Co-Simulation\Sumo目录cmd
python spawn_npc_sumo.py -n 10 --sumo-gui
就可以联合仿真了。
注意,OSM下载的道路,有很多问题的。很容易出现抖动的现象。