1. 常用的高精地图格式如下:
2. 本文采用OpenDrive->CommonRoad->Lanelet2的方式进行地图格式转换
3. 转换代码如下:
import sys import os from lxml import etree from commonroad.scenario.scenario import Tag from commonroad.common.file_writer import CommonRoadFileWriter, OverwriteExistingFile from commonroad.planning.planning_problem import PlanningProblemSet from commonroad.common.file_reader import CommonRoadFileReader # OpenDrive to CommonRoad from crdesigner.map_conversion.map_conversion_interface import opendrive_to_commonroad from crdesigner.map_conversion.opendrive.opendrive_parser.parser import parse_opendrive from crdesigner.map_conversion.opendrive.opendrive_conversion.network import Network # CommonRoad to Lanelet from crdesigner.map_conversion.map_conversion_interface import commonroad_to_lanelet class Xodr2lanelet2: def __init__(self, name): self.name = name self.opendrive_path = os.path.dirname(os.path.realpath(__file__)) + "/" + self.name + ".xodr" self.commonroad_path = os.path.dirname(os.path.realpath(__file__)) + "/" + self.name + ".xml" self.lanelet2_path = os.path.dirname(os.path.realpath(__file__)) + "/" + self.name + ".osm" def xodr2lanelet2(self): self.__xodr2commonroad() self.__commonroad2lanelet2() def __xodr2commonroad(self): # load OpenDrive file, parse it, and convert it to a CommonRoad scenario scenario = opendrive_to_commonroad(self.opendrive_path) # store converted file as CommonRoad scenario writer = CommonRoadFileWriter( scenario=scenario, planning_problem_set=PlanningProblemSet(), author="Synkrotron", affiliation="Synkrotron", source="CommonRoad Scenario Designer", tags={Tag.URBAN}, ) writer.write_to_file(self.commonroad_path, OverwriteExistingFile.ALWAYS) def __commonroad2lanelet2(self): commonroad_to_lanelet(self.commonroad_path, self.lanelet2_path) def main(name): convert = Xodr2lanelet2(name) convert.xodr2lanelet2() if __name__ == "__main__": main(sys.argv[1])
4. 转换方法:
(1) 安装地图转换包commonroad:
pip3 install commonroad-all -i https://pypi.tuna.tsinghua.edu.cn/simple
(2) 修改地图转换包commonroad中的代码:
~/.local/lib/python3.10/site-packages/crdesigner/map_conversion/opendrive/opendrive_parser/parser.py中将
with file_path.open("r") as file_in:
改为:
with open(file_path, "r") as file_in:
~/.local/lib/python3.10/site-packages/crdesigner/config/lanelet2_config.py中将
autoware = Attribute(False, "Autoware", "Boolean indicating whether the conversion should be autoware compatible")
改为:
autoware = Attribute(True, "Autoware", "Boolean indicating whether the conversion should be autoware compatible")
将:
use_local_coordinates = Attribute(False, "Use local coordinates", "Boolean indicating whether local coordinates should be added")
改为:
use_local_coordinates = Attribute(True, "Use local coordinates", "Boolean indicating whether local coordinates should be added")
(3) 运用3中的代码进行转换,示例如下:
python3 xodr2lanelet2.py Town01/Town01
参考文献:
[2] https://zhuanlan.zhihu.com/p/393715053
[3] https://commonroad.in.tum.de/getting-started
[4] https://commonroad.in.tum.de/tutorials/map-conversion
标签:__,lanelet2,OpenDrive,self,commonroad,file,import,path,方法 From: https://www.cnblogs.com/rzy-up/p/18054736