Multiple Python Client Objects Connecting To One Sumo Simulation
I am new in SUMO. I have a .net, a .rou (containing 300 vehicles with vehicle depart, id, route edges attributes), a .trip and a .sumoconfig file representing a traffic scenario. I
Solution 1:
The example which is closest to what you want to achieve is probably the CityMobil tutorial, see http://sumo.dlr.de/wiki/Tutorials/CityMobil but it boils down to something like that:
import traci
import traci.constants as tc
traci.start(["sumo", "my.sumocfg"])
traci.simulation.subscribe()
whileTrue:
moveNodes = {}
traci.simulationStep()
# update the position of all running vehiclesfor veh, subs in traci.vehicle.getAllSubscriptionResults().items():
moveNodes[veh] = (subs[tc.VAR_ROAD_ID], subs[tc.VAR_LANEPOSITION])
# add new departed vehiclesfor v in traci.simulation.getSubscriptionResults()[tc.VAR_DEPARTED_VEHICLES_IDS]:
traci.vehicle.subscribe(v)
subs = traci.vehicle.getSubscriptionResults(v)
moveNodes[v] = (subs[tc.VAR_ROAD_ID], subs[tc.VAR_LANEPOSITION])
This gives you a map storing up to date positions for all vehicles. Please note that the map is rebuilt every step from scratch and thus you do not need to care about leaving vehicles. If your vehicle objects persist for longer you will need to delete them as soon as there are no more subscription results for them.
Post a Comment for "Multiple Python Client Objects Connecting To One Sumo Simulation"