Hello, I am trying to create a simple interface with python. I am not getting any errors in python script, but the desired sumo file isn't getting executed.
What I wish to do for now to see of the code is working right or not is, if
the traffic light turns red, any vehicle on that edge should stop right
away.
The two sets of TraCI commands I'll need to do this are:
- Traffic Lights Value Retrieval
- Change Vehicle State
I could understand the use of *Traffic Lights Value Retrieval* command from
*runner.py*
*traci.trafficlights.getPhase*("ID_of_trafficlight")
However, I am not sure about use of *Change Vehicle State*
*-*Use of PORT
How do I identify the PORT? For now I have declared the same port as given
in runner.py
-Starting sumo as a subprocess
I have stored the path as a string in a variable and using that in function
subporocess.Popen()
I believe this should open the file I wish to access via python script
(att2.sumo.cfg)
For now I have given a dummy step which doesn't do anything in TraCI. Once
this works, I can make further changes.
All the files are currently in the same folder.
Regards,
Vaibhav Rungta
Graduate Student - Industrial and Systems Engineering
Graduate Assistant - Toyota Production Systems Lab
Research Assistant - University Transport Research Center
585-754-7133
#First interfacing program
#TraCI
import os #OS module which provides function for interacting with OS
import sys #to communicate with other software
import optparse #a python module to write command line tools
import subprocess #allows to communicate b/w pyhton script and cmd.exe
import random
#check for environment variables
if 'sumo-0.27.1' in os.environ:
tools = os.path.join(os.environ['sumo-0.27.1'], 'tools')
sys.path.append(tools)
else:
sys.exit("please declare environment variables 'sumo-0.27.1'")
PORT = 8813 #port used for communicating with sumo instance
#sumo is started as a subprocess
sumoBinary = "C:/Users/vr2002/Downloads/sumo-win64-0.27.1/sumo-0.27.1/bin"
#sumoBinary is a variable which holds the path to sumo-gui, you can any name
for this variable
sumoProcess = subprocess.Popen([sumoBinary, "-c", "att2.sumo.cfg",
"--remote-port", str(PORT)], stdout=sys.stdout, stderr=sys.stderr)
import traci
traci.init(PORT)
step = 0
while step < 1000:
traci.simulationStep()
if traci.trafficlights.getPhase("B2") == 0: #signal at B2 in state GGrr
continue
else:
continue
traci.close()
<?xml version="1.0" encoding="UTF-8"?> <!-- generated on 10/24/16 10:44:10 by SUMO netconvert Version 0.27.1 <?xml version="1.0" encoding="UTF-8"?> <configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/netconvertConfiguration.xsd"> <input> <node-files value="att2.nod.xml"/> <edge-files value="att2.edg.xml"/> <connection-files value="att2.con.xml"/> <type-files value="att2.typ.xml"/> </input> <output> <output-file value="att2.net.xml"/> </output> <processing> <no-turnarounds value="true"/> </processing> </configuration> --> <net version="0.27" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/net_file.xsd"> <location netOffset="1000.00,1000.00" convBoundary="0.00,0.00,2000.00,2000.00" origBoundary="-1000.00,-1000.00,1000.00,1000.00" projParameter="!"/> <type id="a" priority="1" numLanes="2" speed="17.60"/> <edge id=":B1_0" function="internal"> <lane id=":B1_0_0" index="0" speed="17.60" length="0.10" shape="504.95,500.00 504.95,500.00"/> <lane id=":B1_0_1" index="1" speed="17.60" length="0.10" shape="501.65,500.00 501.65,500.00"/> </edge> <edge id=":B2_0" function="internal"> <lane id=":B2_0_0" index="0" speed="17.60" length="9.50" shape="504.95,991.95 504.95,1001.45"/> <lane id=":B2_0_1" index="1" speed="17.60" length="9.50" shape="501.65,991.95 501.65,1001.45"/> </edge> <edge id=":B2_2" function="internal"> <lane id=":B2_2_0" index="0" speed="17.60" length="9.50" shape="498.55,995.05 508.05,995.05"/> <lane id=":B2_2_1" index="1" speed="17.60" length="9.50" shape="498.55,998.35 508.05,998.35"/> </edge> <edge id=":B3_0" function="internal"> <lane id=":B3_0_0" index="0" speed="17.60" length="0.10" shape="504.95,1500.00 504.95,1500.00"/> <lane id=":B3_0_1" index="1" speed="17.60" length="0.10" shape="501.65,1500.00 501.65,1500.00"/> </edge> <edge id=":C2_0" function="internal"> <lane id=":C2_0_0" index="0" speed="17.60" length="0.10" shape="1000.00,995.05 1000.00,995.05"/> <lane id=":C2_0_1" index="1" speed="17.60" length="0.10" shape="1000.00,998.35 1000.00,998.35"/> </edge> <edge id=":D1_0" function="internal"> <lane id=":D1_0_0" index="0" speed="17.60" length="0.10" shape="1504.95,500.00 1504.95,500.00"/> <lane id=":D1_0_1" index="1" speed="17.60" length="0.10" shape="1501.65,500.00 1501.65,500.00"/> </edge> <edge id=":D2_0" function="internal"> <lane id=":D2_0_0" index="0" speed="17.60" length="9.50" shape="1504.95,991.95 1504.95,1001.45"/> <lane id=":D2_0_1" index="1" speed="17.60" length="9.50" shape="1501.65,991.95 1501.65,1001.45"/> </edge> <edge id=":D2_2" function="internal"> <lane id=":D2_2_0" index="0" speed="17.60" length="9.50" shape="1498.55,995.05 1508.05,995.05"/> <lane id=":D2_2_1" index="1" speed="17.60" length="9.50" shape="1498.55,998.35 1508.05,998.35"/> </edge> <edge id=":D3_0" function="internal"> <lane id=":D3_0_0" index="0" speed="17.60" length="0.10" shape="1504.95,1500.00 1504.95,1500.00"/> <lane id=":D3_0_1" index="1" speed="17.60" length="0.10" shape="1501.65,1500.00 1501.65,1500.00"/> </edge> <edge id="A2B2" from="A2" to="B2" priority="1" type="a"> <lane id="A2B2_0" index="0" speed="17.60" length="498.55" shape="0.00,995.05 498.55,995.05"/> <lane id="A2B2_1" index="1" speed="17.60" length="498.55" shape="0.00,998.35 498.55,998.35"/> </edge> <edge id="B0B1" from="B0" to="B1" priority="1" type="a"> <lane id="B0B1_0" index="0" speed="17.60" length="500.00" shape="504.95,0.00 504.95,500.00"/> <lane id="B0B1_1" index="1" speed="17.60" length="500.00" shape="501.65,0.00 501.65,500.00"/> </edge> <edge id="B1B2" from="B1" to="B2" priority="1" type="a"> <lane id="B1B2_0" index="0" speed="17.60" length="491.95" shape="504.95,500.00 504.95,991.95"/> <lane id="B1B2_1" index="1" speed="17.60" length="491.95" shape="501.65,500.00 501.65,991.95"/> </edge> <edge id="B2B3" from="B2" to="B3" priority="1" type="a"> <lane id="B2B3_0" index="0" speed="17.60" length="498.55" shape="504.95,1001.45 504.95,1500.00"/> <lane id="B2B3_1" index="1" speed="17.60" length="498.55" shape="501.65,1001.45 501.65,1500.00"/> </edge> <edge id="B2C2" from="B2" to="C2" priority="1" type="a"> <lane id="B2C2_0" index="0" speed="17.60" length="491.95" shape="508.05,995.05 1000.00,995.05"/> <lane id="B2C2_1" index="1" speed="17.60" length="491.95" shape="508.05,998.35 1000.00,998.35"/> </edge> <edge id="B3B4" from="B3" to="B4" priority="1" type="a"> <lane id="B3B4_0" index="0" speed="17.60" length="500.00" shape="504.95,1500.00 504.95,2000.00"/> <lane id="B3B4_1" index="1" speed="17.60" length="500.00" shape="501.65,1500.00 501.65,2000.00"/> </edge> <edge id="C2D2" from="C2" to="D2" priority="1" type="a"> <lane id="C2D2_0" index="0" speed="17.60" length="498.55" shape="1000.00,995.05 1498.55,995.05"/> <lane id="C2D2_1" index="1" speed="17.60" length="498.55" shape="1000.00,998.35 1498.55,998.35"/> </edge> <edge id="D0D1" from="D0" to="D1" priority="1" type="a"> <lane id="D0D1_0" index="0" speed="17.60" length="500.00" shape="1504.95,0.00 1504.95,500.00"/> <lane id="D0D1_1" index="1" speed="17.60" length="500.00" shape="1501.65,0.00 1501.65,500.00"/> </edge> <edge id="D1D2" from="D1" to="D2" priority="1" type="a"> <lane id="D1D2_0" index="0" speed="17.60" length="491.95" shape="1504.95,500.00 1504.95,991.95"/> <lane id="D1D2_1" index="1" speed="17.60" length="491.95" shape="1501.65,500.00 1501.65,991.95"/> </edge> <edge id="D2D3" from="D2" to="D3" priority="1" type="a"> <lane id="D2D3_0" index="0" speed="17.60" length="498.55" shape="1504.95,1001.45 1504.95,1500.00"/> <lane id="D2D3_1" index="1" speed="17.60" length="498.55" shape="1501.65,1001.45 1501.65,1500.00"/> </edge> <edge id="D2E2" from="D2" to="E2" priority="1" type="a"> <lane id="D2E2_0" index="0" speed="17.60" length="491.95" shape="1508.05,995.05 2000.00,995.05"/> <lane id="D2E2_1" index="1" speed="17.60" length="491.95" shape="1508.05,998.35 2000.00,998.35"/> </edge> <edge id="D3D4" from="D3" to="D4" priority="1" type="a"> <lane id="D3D4_0" index="0" speed="17.60" length="500.00" shape="1504.95,1500.00 1504.95,2000.00"/> <lane id="D3D4_1" index="1" speed="17.60" length="500.00" shape="1501.65,1500.00 1501.65,2000.00"/> </edge> <tlLogic id="B2" type="static" programID="0" offset="0"> <phase duration="40" state="GGrr"/> <phase duration="5" state="yyrr"/> <phase duration="40" state="rrGG"/> <phase duration="5" state="rryy"/> </tlLogic> <tlLogic id="D2" type="static" programID="0" offset="0"> <phase duration="40" state="GGrr"/> <phase duration="5" state="yyrr"/> <phase duration="40" state="rrGG"/> <phase duration="5" state="rryy"/> </tlLogic> <junction id="A2" type="unregulated" x="0.00" y="1000.00" incLanes="" intLanes="" shape="0.00,999.95 0.00,993.45"/> <junction id="B0" type="unregulated" x="500.00" y="0.00" incLanes="" intLanes="" shape="500.05,0.00 506.55,0.00"/> <junction id="B1" type="priority" x="500.00" y="500.00" incLanes="B0B1_0 B0B1_1" intLanes=":B1_0_0 :B1_0_1" shape="500.05,500.00 506.55,500.00 500.05,500.00"> <request index="0" response="00" foes="00" cont="0"/> <request index="1" response="00" foes="00" cont="0"/> </junction> <junction id="B2" type="traffic_light" x="500.00" y="1000.00" incLanes="B1B2_0 B1B2_1 A2B2_0 A2B2_1" intLanes=":B2_0_0 :B2_0_1 :B2_2_0 :B2_2_1" shape="500.05,1001.45 506.55,1001.45 508.05,999.95 508.05,993.45 506.55,991.95 500.05,991.95 498.55,993.45 498.55,999.95"> <request index="0" response="0000" foes="1100" cont="0"/> <request index="1" response="0000" foes="1100" cont="0"/> <request index="2" response="0011" foes="0011" cont="0"/> <request index="3" response="0011" foes="0011" cont="0"/> </junction> <junction id="B3" type="priority" x="500.00" y="1500.00" incLanes="B2B3_0 B2B3_1" intLanes=":B3_0_0 :B3_0_1" shape="500.05,1500.00 506.55,1500.00 500.05,1500.00"> <request index="0" response="00" foes="00" cont="0"/> <request index="1" response="00" foes="00" cont="0"/> </junction> <junction id="B4" type="unregulated" x="500.00" y="2000.00" incLanes="B3B4_0 B3B4_1" intLanes="" shape="506.55,2000.00 500.05,2000.00"/> <junction id="C2" type="priority" x="1000.00" y="1000.00" incLanes="B2C2_0 B2C2_1" intLanes=":C2_0_0 :C2_0_1" shape="1000.00,999.95 1000.00,993.45 1000.00,999.95"> <request index="0" response="00" foes="00" cont="0"/> <request index="1" response="00" foes="00" cont="0"/> </junction> <junction id="D0" type="unregulated" x="1500.00" y="0.00" incLanes="" intLanes="" shape="1500.05,0.00 1506.55,0.00"/> <junction id="D1" type="priority" x="1500.00" y="500.00" incLanes="D0D1_0 D0D1_1" intLanes=":D1_0_0 :D1_0_1" shape="1500.05,500.00 1506.55,500.00 1500.05,500.00"> <request index="0" response="00" foes="00" cont="0"/> <request index="1" response="00" foes="00" cont="0"/> </junction> <junction id="D2" type="traffic_light" x="1500.00" y="1000.00" incLanes="D1D2_0 D1D2_1 C2D2_0 C2D2_1" intLanes=":D2_0_0 :D2_0_1 :D2_2_0 :D2_2_1" shape="1500.05,1001.45 1506.55,1001.45 1508.05,999.95 1508.05,993.45 1506.55,991.95 1500.05,991.95 1498.55,993.45 1498.55,999.95"> <request index="0" response="0000" foes="1100" cont="0"/> <request index="1" response="0000" foes="1100" cont="0"/> <request index="2" response="0011" foes="0011" cont="0"/> <request index="3" response="0011" foes="0011" cont="0"/> </junction> <junction id="D3" type="priority" x="1500.00" y="1500.00" incLanes="D2D3_0 D2D3_1" intLanes=":D3_0_0 :D3_0_1" shape="1500.05,1500.00 1506.55,1500.00 1500.05,1500.00"> <request index="0" response="00" foes="00" cont="0"/> <request index="1" response="00" foes="00" cont="0"/> </junction> <junction id="D4" type="unregulated" x="1500.00" y="2000.00" incLanes="D3D4_0 D3D4_1" intLanes="" shape="1506.55,2000.00 1500.05,2000.00"/> <junction id="E2" type="unregulated" x="2000.00" y="1000.00" incLanes="D2E2_0 D2E2_1" intLanes="" shape="2000.00,993.45 2000.00,999.95"/> <connection from="A2B2" to="B2C2" fromLane="0" toLane="0" via=":B2_2_0" tl="B2" linkIndex="2" dir="s" state="o"/> <connection from="A2B2" to="B2C2" fromLane="1" toLane="1" via=":B2_2_1" tl="B2" linkIndex="3" dir="s" state="o"/> <connection from="B0B1" to="B1B2" fromLane="0" toLane="0" via=":B1_0_0" dir="s" state="M"/> <connection from="B0B1" to="B1B2" fromLane="1" toLane="1" via=":B1_0_1" dir="s" state="M"/> <connection from="B1B2" to="B2B3" fromLane="0" toLane="0" via=":B2_0_0" tl="B2" linkIndex="0" dir="s" state="o"/> <connection from="B1B2" to="B2B3" fromLane="1" toLane="1" via=":B2_0_1" tl="B2" linkIndex="1" dir="s" state="o"/> <connection from="B2B3" to="B3B4" fromLane="0" toLane="0" via=":B3_0_0" dir="s" state="M"/> <connection from="B2B3" to="B3B4" fromLane="1" toLane="1" via=":B3_0_1" dir="s" state="M"/> <connection from="B2C2" to="C2D2" fromLane="0" toLane="0" via=":C2_0_0" dir="s" state="M"/> <connection from="B2C2" to="C2D2" fromLane="1" toLane="1" via=":C2_0_1" dir="s" state="M"/> <connection from="C2D2" to="D2E2" fromLane="0" toLane="0" via=":D2_2_0" tl="D2" linkIndex="2" dir="s" state="o"/> <connection from="C2D2" to="D2E2" fromLane="1" toLane="1" via=":D2_2_1" tl="D2" linkIndex="3" dir="s" state="o"/> <connection from="D0D1" to="D1D2" fromLane="0" toLane="0" via=":D1_0_0" dir="s" state="M"/> <connection from="D0D1" to="D1D2" fromLane="1" toLane="1" via=":D1_0_1" dir="s" state="M"/> <connection from="D1D2" to="D2D3" fromLane="0" toLane="0" via=":D2_0_0" tl="D2" linkIndex="0" dir="s" state="o"/> <connection from="D1D2" to="D2D3" fromLane="1" toLane="1" via=":D2_0_1" tl="D2" linkIndex="1" dir="s" state="o"/> <connection from="D2D3" to="D3D4" fromLane="0" toLane="0" via=":D3_0_0" dir="s" state="M"/> <connection from="D2D3" to="D3D4" fromLane="1" toLane="1" via=":D3_0_1" dir="s" state="M"/> <connection from=":B1_0" to="B1B2" fromLane="0" toLane="0" dir="s" state="M"/> <connection from=":B1_0" to="B1B2" fromLane="1" toLane="1" dir="s" state="M"/> <connection from=":B2_0" to="B2B3" fromLane="0" toLane="0" dir="s" state="M"/> <connection from=":B2_0" to="B2B3" fromLane="1" toLane="1" dir="s" state="M"/> <connection from=":B2_2" to="B2C2" fromLane="0" toLane="0" dir="s" state="M"/> <connection from=":B2_2" to="B2C2" fromLane="1" toLane="1" dir="s" state="M"/> <connection from=":B3_0" to="B3B4" fromLane="0" toLane="0" dir="s" state="M"/> <connection from=":B3_0" to="B3B4" fromLane="1" toLane="1" dir="s" state="M"/> <connection from=":C2_0" to="C2D2" fromLane="0" toLane="0" dir="s" state="M"/> <connection from=":C2_0" to="C2D2" fromLane="1" toLane="1" dir="s" state="M"/> <connection from=":D1_0" to="D1D2" fromLane="0" toLane="0" dir="s" state="M"/> <connection from=":D1_0" to="D1D2" fromLane="1" toLane="1" dir="s" state="M"/> <connection from=":D2_0" to="D2D3" fromLane="0" toLane="0" dir="s" state="M"/> <connection from=":D2_0" to="D2D3" fromLane="1" toLane="1" dir="s" state="M"/> <connection from=":D2_2" to="D2E2" fromLane="0" toLane="0" dir="s" state="M"/> <connection from=":D2_2" to="D2E2" fromLane="1" toLane="1" dir="s" state="M"/> <connection from=":D3_0" to="D3D4" fromLane="0" toLane="0" dir="s" state="M"/> <connection from=":D3_0" to="D3D4" fromLane="1" toLane="1" dir="s" state="M"/> </net>
<?xml version="1.0" encoding="UTF-8"?> <routes> <vType id = "typA" accel = "0.8" decel ="4.5" sigma = "0.7" length = "4.5" maxspeed = "70" emissionClass = "P_7_7"/> <vType id = "typB" accel = "0.6" decel ="4.5" sigma = "0.8" length = "4.5" maxspeed = "70" emissionClass = "P_7_5"/> <vType id = "typC" accel = "0.8" decel ="4.5" sigma = "0.9" length = "6" maxspeed = "70" emissionClass = "P_7_6"/> <vType id = "typD" accel = "0.3" decel ="4.5" sigma = "0.9" length = "10" maxspeed = "60" emissionClass = "HDV_3_1"/> <route id = "LR" edges = "A2B2 B2C2 C2D2 D2E2"/> <route id = "DU" edges = "B0B1 B1B2 B2B3 B3B4"/> <route id = "UD" edges = "D0D1 D1D2 D2D3 D3D4"/> <vehicle id = "v1" type = "typA" route = "LR" depart = "0"/> <vehicle id = "v5" type = "typA" route = "DU" depart = "0"/> <vehicle id = "v9" type = "typA" route = "UD" depart = "0"/> <vehicle id = "v2" type = "typB" route = "LR" depart = "10"/> <vehicle id = "v6" type = "typB" route = "DU" depart = "10"/> <vehicle id = "v10" type = "typB" route = "UD" depart = "10"/> <vehicle id = "v3" type = "typC" route = "LR" depart = "20"/> <vehicle id = "v7" type = "typC" route = "DU" depart = "20"/> <vehicle id = "v11" type = "typC" route = "UD" depart = "20"/> <vehicle id = "v4" type = "typD" route = "LR" depart = "30"/> <vehicle id = "v8" type = "typD" route = "DU" depart = "30"/> <vehicle id = "v12" type = "typD" route = "UD" depart = "30"/> <vehicle id = "v13" type = "typB" route = "LR" depart = "40"/> <vehicle id = "v14" type = "typB" route = "LR" depart = "50"/> <vehicle id = "v15" type = "typC" route = "LR" depart = "60"/> <vehicle id = "v16" type = "typA" route = "LR" depart = "70"/> <vehicle id = "v17" type = "typD" route = "DU" depart = "80"/> <vehicle id = "v18" type = "typB" route = "DU" depart = "90"/> <vehicle id = "v19" type = "typC" route = "DU" depart = "100"/> <vehicle id = "v20" type = "typA" route = "DU" depart = "110"/> <vehicle id = "v21" type = "typA" route = "UD" depart = "120"/> <vehicle id = "v22" type = "typB" route = "UD" depart = "130"/> <vehicle id = "v23" type = "typD" route = "UD" depart = "140"/> <vehicle id = "v24" type = "typD" route = "UD" depart = "150"/> <vehicle id = "v25" type = "typB" route = "LR" depart = "160"/> <vehicle id = "v26" type = "typB" route = "LR" depart = "170"/> <vehicle id = "v27" type = "typD" route = "LR" depart = "180"/> <vehicle id = "v28" type = "typA" route = "LR" depart = "190"/> <vehicle id = "v29" type = "typA" route = "DU" depart = "200"/> <vehicle id = "v30" type = "typB" route = "DU" depart = "210"/> <vehicle id = "v31" type = "typD" route = "DU" depart = "220"/> <vehicle id = "v32" type = "typD" route = "DU" depart = "230"/> <vehicle id = "v33" type = "typC" route = "UD" depart = "240"/> <vehicle id = "v34" type = "typB" route = "UD" depart = "250"/> <vehicle id = "v35" type = "typA" route = "UD" depart = "260"/> <vehicle id = "v36" type = "typB" route = "UD" depart = "270"/> <vehicle id = "v37" type = "typD" route = "LR" depart = "280"/> <vehicle id = "v38" type = "typB" route = "LR" depart = "290"/> <vehicle id = "v39" type = "typC" route = "LR" depart = "300"/> <vehicle id = "v40" type = "typD" route = "LR" depart = "310"/> <vehicle id = "v41" type = "typD" route = "DU" depart = "320"/> <vehicle id = "v42" type = "typB" route = "DU" depart = "330"/> <vehicle id = "v43" type = "typC" route = "DU" depart = "340"/> <vehicle id = "v44" type = "typA" route = "DU" depart = "350"/> <vehicle id = "v45" type = "typA" route = "UD" depart = "360"/> <vehicle id = "v46" type = "typB" route = "UD" depart = "370"/> <vehicle id = "v47" type = "typA" route = "UD" depart = "380"/> <vehicle id = "v48" type = "typA" route = "UD" depart = "390"/> </routes>
att2.sumo.cfg
Description: Binary data
------------------------------------------------------------------------------ The Command Line: Reinvented for Modern Developers Did the resurgence of CLI tooling catch you by surprise? Reconnect with the command line and become more productive. Learn the new .NET and ASP.NET CLI. Get your free copy! http://sdm.link/telerik
_______________________________________________ sumo-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sumo-user
