OpenstreetMap+GlobalMapper+CARLA+SUMO笔记

首先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下载的道路,有很多问题的。很容易出现抖动的现象。

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值