Ali
Ali

Reputation: 115

Some problems with ~.slowDown() method

I want to force SUMO to make some vehicles slow down at specific time steps using traci. I used the following script but once the 'c1' vehicle leaves the network, the error issues saying " the vehicle 'c1" is not known and stops. I know this is due to the 'for' loop but have no idea instead.

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()  

Upvotes: 0

Views: 134

Answers (1)

Michael
Michael

Reputation: 3680

There are two possiblities here: Either you check whether the vehicle is still there using something like:

if 'c1' in traci.vehicle.getIDList():

or you catch the TraCIException which is raised and continue.

Upvotes: 1

Related Questions