高清地图转换(xord转apollo的bin文件)
阅读原文时间:2023年07月09日阅读:6

将carla中的OpenDrive地图(carla\Unreal\CarlaUE4\Content\Carla\Maps\OpenDrive)转换为Apollo中可识别的地图格式(bin与txt文件)

python的imap_box包、apollov5、unity、 SVL SIMULATOR

Unity

  1. Download and Install Unity Hub(需要代理)

    • Ubuntu: You may need to allow the downloaded AppImage to be run as an executable

      • Right-click the AppImage
      • Select Properties
      • Go to the Permissions tab
      • Check Allow executing file as program
      • Alternatively, in the terminal run sudo chmod +x UnityHub.AppImage
  2. Download and Install Unity 2020.3.3f1 from the Unity Download Archive: (需要代理)

SVL SIMULATOR

安装文档地址:https://www.svlsimulator.com/docs/installation-guide/build-instructions/

  • Installing Git LFS top

    Make sure you have git-lfs installed before cloning the Simulator repository.

    • Instructions for installation are here
    • Verify installation
      • In a terminal enter git lfs install
      • Git LFS initialized. should print out
  • Building a standalone executable

imap_box

imap_box包用于读取转换出来的bin文件,导出txt文件,git地址:https://github.com/daohu527/imap

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple  imap_box

在windows中安装时要使用powershell命令行安装,否则会报错

将carla地图导出apollo的bin文件

  • 点击上方simulator-> Import HD Map,在弹出的HD Map Import中Import 选择carla地图路径,导入地图(这里以carla\Unreal\CarlaUE4\Content\Carla\Maps\OpenDrive\Town01.xodr为例)

    [图片]

  • 单击左边界面中新出现的MapOrigin,在右边出现的设置中,将Origin Easting设置为0,Origin Northing设置为0

  • 鼠标左键按住MapTown01,将其拖拽到MapOrigin上,成为其子节点。拖拽后点击MapTown01,将右边属性中的Rotation->Y设置为0

  • 选择simulator->Build HD Map Mesh, 在弹出的HD Map Mesh Builder中点击Build Mesh

  • 选择simulator->Export HD Map, 在弹出的HD Map Export中选择Apollo 5 HD Map格式,选择路径后点击Export,成功时可以看到左下界面提示(Carla地图1-10中,只有Town03没有导出成功)

使用imap_box包从bin文件导出txt文件

  • 创建新的工程,python环境选择的是python3.9.12(理论上3.6以上都可以).

  • 创建文件convert_bin_to_txt.py文件,内容为

    from modules.map.proto import map_pb2

    from imap.lib.proto_utils import get_pb_from_bin_file
    from imap.lib.proto_utils import write_pb_to_text_file

    def convert_bin_to_txt(input_file: str):
    map = map_pb2.Map()
    pb = get_pb_from_bin_file(filename=input_file, pb_value=map)
    write_pb_to_text_file(pb, input_file.split('.')[0])

    if name == 'main':
    convert_bin_to_txt(r"D:\tmp\base_map.bin")

  • 执行convert_bin_to_txt.py, 查看到D:\tmp下会出现base_map.txt。里面有可读的地图信息

生成sim_map与routing_map

将base_map.bin拷贝到安装了apollov5的容器内,在 /apollo/modules/map/data内创建新的文件夹,并将base_map.bin移动到新创建的文件夹中;然后运行脚本生成文件

# 将文件拷贝到docker容器的/apollo目录下
docker cp base_map.bin apollo_dev_ubuntu:/apollo
# 进入docker容器
/apollo/docker/scripts/dev_into.sh
# 创建文件夹
mkdir /apollo/modules/map/data/town01_example
# 移动文件
mv /apollo/base_map.bin /apollo/modules/map/data/town01_example/
# 执行脚本生成文件
/apollo/scripts/generate_maps.sh /apollo/modules/map/data/town01_example/

最后一步时执行会有两处报错,那是通过xml生成bin和txt的脚本命令,不影响直接用bin生成sim_map与routing_map

ubuntu@in_dev_docker:/apollo$ /apollo/scripts/generate_maps.sh /apollo/modules/map/data/town01_example/
I0906 10:10:26.932503 2935423 topo_creator.cc:32] [routing] Conf file: /apollo/modules/routing/conf/routing_config.pb.txt is loaded.
I0906 10:10:26.941069 2935423 graph_creator.cc:78] [routing] Number of lanes: 124
I0906 10:10:26.942127 2935423 graph_creator.cc:111] [routing] Current lane id: lane_0
.....
.....
I0906 10:10:26.983175 2935423 graph_creator.cc:158] [routing] Txt file is dumped successfully. Path: /apollo/modules/map/data/town01_example//routing_map.txt
I0906 10:10:26.984313 2935423 graph_creator.cc:163] [routing] Bin file is dumped successfully. Path: /apollo/modules/map/data/town01_example//routing_map.bin
I0906 10:10:26.984656 2935423 topo_creator.cc:40] [routing] Create routing topo successfully from /apollo/modules/map/data/town01_example//base_map.bin to /apollo/modules/map/data/town01_example//routing_map.bin
I0906 10:10:27.100512 2935439 sim_map_generator.cc:86] [] Downsampling lane lane_0
I0906 10:10:27.100884 2935439 sim_map_generator.cc:74] [] Lane curve downsampled from 8 points to 2 points
I0906 10:10:27.100904 2935439 sim_map_generator.cc:74] [] Lane curve downsampled from 8 points to 2 points
I0906 10:10:27.100915 2935439 sim_map_generator.cc:74] [] Lane curve downsampled from 8 points to 2 points
.....
.....
I0906 10:10:27.112815 2935439 sim_map_generator.cc:74] [] Lane curve downsampled from 5 points to 2 points.
I0906 10:10:27.164212 2935439 sim_map_generator.cc:122] [] sim_map generated at:/apollo/modules/map/data/town01_example/
# 下面的报错并不影响
E0906 10:10:27.247184 2935455 opendrive_adapter.cc:33] [] fail to load file /apollo/modules/map/data/town01_example//base_map.xml
F0906 10:10:27.247690 2935455 proto_map_generator.cc:39] Check failed: apollo::hdmap::adapter::OpendriveAdapter::LoadData(map_filename, &pb_map) fail to load data from : /apollo/modules/map/data/town01_example//base_map.xml
*** Check failure stack trace: ***
    @     0x7fb3a918aec0  google::LogMessage::Fail()
    @     0x7fb3a918ae07  google::LogMessage::SendToLog()
    @     0x7fb3a918a7de  google::LogMessage::Flush()
    @     0x7fb3a918d83b  google::LogMessageFatal::~LogMessageFatal()
    @           0x45d1a9  main
    @     0x7fb3a6b09f45  __libc_start_main
    @           0x45cf89  (unknown)
/apollo/scripts/generate_maps.sh: line 8: 2935455 Aborted                 (core dumped) bazel-bin/modules/map/tools/proto_map_generator --map_dir=$1 --output_dir=$1
E0906 10:10:28.046296 2935471 file.cc:73] [] Failed to open file /apollo/modules/map/data/town01_example//base_map.txt in text mode.
E0906 10:10:28.051890 2935471 file.cc:99] [] Failed to open file /apollo/modules/map/data/town01_example//base_map.txt in binary mode.
F0906 10:10:28.051970 2935471 bin_map_generator.cc:38] Check failed: apollo::cyber::common::GetProtoFromFile(map_filename, &pb_map) fail to load data from : /apollo/modules/map/data/town01_example//base_map.txt
*** Check failure stack trace: ***
    @     0x7f1fed03fec0  google::LogMessage::Fail()
    @     0x7f1fed03fe07  google::LogMessage::SendToLog()
    @     0x7f1fed03f7de  google::LogMessage::Flush()
    @     0x7f1fed04283b  google::LogMessageFatal::~LogMessageFatal()
    @           0x45bd29  main
    @     0x7f1fea9bef45  __libc_start_main
    @           0x45bb09  (unknown)
/apollo/scripts/generate_maps.sh: line 9: 2935471 Aborted                 (core dumped) bazel-bin/modules/map/tools/bin_map_generator --map_dir=$1 --output_dir=$1

查看生成的文件

ubuntu@in_dev_docker:/apollo$ ls /apollo/modules/map/data/town01_example/
base_map.bin  routing_map.bin  routing_map.txt  sim_map.bin  sim_map.txt

使用SVL SIMULATOR而放弃RoadRunner的原因

在使用SVL SIMULATOR前首先调研的是使用RoadRunner导出地图。使用过程中遇到的主要问题有:

  • 地图中心点的设置问题

    在设置SVL SIMULATOR与RoadRunner中都有MapOrigin设置的能力,但是RoadRunner中将MapOrigin设置为0后,导出的文件坐标依然不是以地图中心为原点的坐标系,这样就需要将MapOrigin中的参数设置为负数来抵消坐标系带来的影响,这需要反复试验

  • 红绿灯和停止线的问题

    在生成的场景中,能够看到场景中的红绿灯高度不足,停止线缺失的现象,需要手动进行调整

  • 红绿灯id不对应问题

    生成的txt文件中可以看出,生成的信号灯的id并不能与carla中的灯的id对应上,这样就无法用carla进行模拟

    结论:

    RoadRunner可以在自定义场景时使用,如果想将已经完成的地图转换成apollo地图,考虑SVL SIMULATOR更合适一些

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章