|
@@ -16,24 +16,39 @@ xoscName = 'scenario.xosc'
|
|
|
logging.basicConfig(filename=path2 + 'log/simulation.log', level=logging.INFO,
|
|
|
format='%(asctime)s - %(levelname)s - %(message)s')
|
|
|
|
|
|
-sleep_time = 60 # 每多少秒扫描一次
|
|
|
+sleep_time = 30 # 每多少秒扫描一次
|
|
|
|
|
|
|
|
|
def move_xosc_before_simulation(root_path):
|
|
|
try:
|
|
|
- xosc_path = root_path + 'scenario_orig.xosc'
|
|
|
- logging.info('仿真还原需要的 xosc 路径为:%s' % xosc_path)
|
|
|
- tree1 = ET.parse(xosc_path)
|
|
|
-
|
|
|
+ xosc_src = os.path.join(root_path, 'scenario_orig.xosc')
|
|
|
+ xosc_target = os.path.join(root_path, 'openx0.xosc')
|
|
|
+ tree1 = ET.parse(xosc_src)
|
|
|
root1 = tree1.getroot()
|
|
|
for node0 in root1:
|
|
|
+ if node0.tag == 'RoadNetwork':
|
|
|
+ for node1 in node0:
|
|
|
+ # 打印根元素的标签名
|
|
|
+ if 'LogicFile' == node1.tag:
|
|
|
+ xodr_src = str(node1.set('filepath'))
|
|
|
+ shutil.copy(xodr_src, root_path + xodr_src.rsplit('/', 1)[-1])
|
|
|
+ if 'SceneGraphFile' == node1.tag:
|
|
|
+ osgb_src = str(node1.set('filepath'))
|
|
|
+ shutil.copy(osgb_src, root_path + osgb_src.rsplit('/', 1)[-1])
|
|
|
if node0.tag == 'Entities':
|
|
|
for node1 in node0:
|
|
|
if node1.get("name") == 'Ego':
|
|
|
for node2 in node1:
|
|
|
if node2.tag == 'Vehicle':
|
|
|
node2.set('name', vehicle_name)
|
|
|
- tree1.write(root_path + 'openx0.xosc')
|
|
|
+ tree1.write(xosc_target)
|
|
|
+ # 检查文件是否存在,以避免在文件不存在时引发异常
|
|
|
+ if os.path.exists(xosc_src):
|
|
|
+ # 删除文件
|
|
|
+ os.remove(xosc_src)
|
|
|
+ print("文件已删除:", xosc_src)
|
|
|
+ else:
|
|
|
+ print("文件不存在:", xosc_src)
|
|
|
|
|
|
except Exception as e:
|
|
|
logging.exception("修改xosc报错: %s" % str(e))
|