Python调用SUMO接口,解决vehicle颜色设置问题
1.Python调用sumo 的traci接口,通过
traci.vehicle.setColor
进行设置,以下是
示例代码
.
import sys
import os
sys.path.append("D:/Tool/sumo/tools")
sumoBinary = "D:/Tool/sumo/bin/sumo-gui"
sumoCmd = [sumoBinary, "-c", "D:/Tool/sumo/tools/game/square.sumocfg"]
import traci
traci.start(sumoCmd)
step = 0
isAdd=True
while step < 50000:
traci.simulationStep()
if traci.simulation.getTime() > 20:
if isAdd==True :
traci.route.add("trip000", ['right0to1/0', '1/0to1/1', '1/1toright1'])
traci.vehicle.add("newVeh", "trip000")
isAdd=False
traci.vehicle.setDecel("newVeh", 10)
color_red=(255,0,0)
color_green=(0,255,0)
traci.vehicle.setColor("newVeh",color_red)
traci.vehicle.getPosition("newVeh")
traci.vehicle.setLength("newVeh",10)
step += 1
2.写完脚本后,运行脚本,打开sumo界面后,在sumo中设置:设置view settings-->Vehicles-->设置color为given/assigned vehicle color
,如下图所示:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)