#配置导入库目录
import sys
import os
sys.path.append("F:/install/Sumo/tools")
#配置调用目录
sumoBinary = "F:/install/Sumo/bin/sumo-gui"
sumoCmd = [sumoBinary, "-c", "F:/install/Sumo/tools/game/square.sumocfg"]
#导入traci模块
import traci
traci.start(sumoCmd)
step = 0
isAdd=True
while step < 2000:
traci.simulationStep()
if traci.simulation.getTime() > 20:
if isAdd==True :
#获取编号为0的车辆路线id
#trip000= traci.vehicle.getRouteID("0")
#添加路线,编号为trip000,路线包含边'right0to1/0', '1/0to1/1', '1/1toright1'
traci.route.add("trip000", ['right0to1/0', '1/0to1/1', '1/1toright1'])
#输出编号“0”的车辆路线
print( traci.vehicle.getRoute("0"))
#添加车辆,车辆id为"newVeh",沿路线 "trip000"行驶
traci.vehicle.add("newVeh", "trip000")
isAdd=False
#设置"newVeh"的速度
traci.vehicle.setDecel("newVeh", 10)
#设置"newVeh"的颜色,暂未起作用
colora=(125,255,255,255)
traci.vehicle.setColor("newVeh",colora)
#设置"newVeh"的长度
traci.vehicle.setLength("newVeh",10)
#获取"newVeh"当前位置
#print(traci.vehicle.getPosition3D("newVeh"))
step += 1
Python调用Sumo接口示例
最新推荐文章于 2023-12-14 09:46:43 发布