我想强迫相扑让一些车辆在特定的时间步骤使用特蕾西减速。我使用了以下脚本,但一旦'c1‘车辆离开网络,错误问题说“车辆'c1”是不知道和停止。我知道这是由于'for’循环,但不知道相反。
def slowdown():
traci.start(sumoCmd)
N = 1000
step = 0
traci.vehicle.add(vehID = 'c1', typeID = "car1", routeID = "route_1", departLane='0', depart = 30)
traci.vehicle.add(vehID = 'c2', typeID = "car1", routeID = "route_1", departLane='0', depart = 60)
for step in range(N):
if step % 10 == 5:
traci.vehicle.slowDown('c1', 0, 5)
traci.vehicle.slowDown('c2 ', 0, 5)
step += 1
traci.simulationStep()
traci.close()
sys.stdout.flush()
slowdown() 发布于 2022-03-21 06:59:41
这里有两个可能性:要么检查车辆是否还在那里,要么使用如下所示:
if 'c1' in traci.vehicle.getIDList():
或者捕获引发的TraCIException并继续。
https://stackoverflow.com/questions/71526710
复制相似问题