Hello Folks,
Here's a brief description of problem I am facing.
Goal - Gather information in real time to find how far are the vehicles
from next signalized intersection
How - To do this I am fetching XML file (fcdoutput). I was able to create a
python code to read the XML file and find out vehicle IDs which have
certain criteria.
Observation - The python code I created to read the XML file works but it
takes while to run (readxmltrace.py).
Error - When I included the section of code which helps me read the XML
file in TraCI code (traci_simexp1.py), I get the error.
I have attached the python files. Please help me understand the error with
this approach. To my understanding (correct me if I am wrong) one reason
might be that python code created to read the XML file is taking a while to
execute/process, possibly more than 1s, which is clock time in SUMO.
The error looks like:
Loading configuration... done.
***Starting server on port 8813 ***
Loading net-file from 'simexp.net.xml'... done (0ms).
Loading done.
Simulation started with time: 0.00
Error: tcpip::Socket::recvAndCheck @ recv: Socket reset by peer
Quitting (on error).
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.28.0' in os.environ:
tools = os.path.join(os.environ['sumo-0.28.0'], 'tools')
sys.path.append(tools)
else:
sys.exit("please declare environment variables 'sumo-0.28.0'")
'''
try:
sys.path.append(os.path.join(os.path.dirname(
__file__), '..', '..', '..', '..', "tools")) # tutorial in tests
sys.path.append(os.path.join(os.environ.get("sumo-0.28.0", os.path.join(
os.path.dirname(__file__), "..", "..", "..")), "tools")) # tutorial in
docs
from sumolib import checkBinary
except ImportError:
sys.exit(
"please declare environment variable 'SUMO_HOME' as the root directory
of your sumo installation (it should contain folders 'bin', 'tools' and
'docs')")
PORT = 8813 #port used for communicating with sumo instance
#sumo is started as a subprocess
sumoBinary = "C:/Users/Public/Music/Sample
Music/sumo-win64-0.28.0/sumo-0.28.0/bin/sumo-gui.exe"
#sumoBinary is a variable which holds the path to sumo-gui, you can any name
for this variable
sumoProcess = subprocess.Popen([sumoBinary, "-c", "simexp.sumo.cfg",
"--remote-port", str(PORT)], stdout=sys.stdout, stderr=sys.stderr)
#For any time step I am saving all the vehicle IDs in a text file and then
verifying if the vehicle v1 is in the text file (i.e; exited system).
#If it's in the system it's stopped irrespective of it's position depending on
state of signal at node B2.
import traci
traci.init(PORT)
step = 0
while traci.simulation.getMinExpectedNumber() > 0:
traci.simulationStep()
inp_file = ET.parse('simexp_trace.xml') #reading the XML file
fcdexport = inp_file.getroot() #to identify the root,
to my understanding the first tag <fcd-export>
time_step = fcdexport.findall("timestep") #There are multiple
timestep tags, creates a list
z=step #timestep value,
simulation procceds in timesteps
vehicle_info = time_step[z].findall("vehicle") #all vehicle tags in a
particular timestep, timestep 100 in this case
car_in_way = [] #creates a list which
stores vehicle ids
for x in vehicle_info: #runs loop for all
elements in list vehicle_info
if (x.get("type")) == "trail": #to identify trailer
with open ("car_in_way.txt", "a") as vehicle_info:
vehicle_info.write(step + '\n' + car_in_way + '\n')
if ((x.get("lane")) == "A1B1_0"): #specifying the lane
truck_pos = float(x.get("pos")) #copys value of truck's
position
for new_vehicle in vehicle_info: #loop in loop, checks
elements of the list vehicle_info
if (truck_pos < float(new_vehicle.get("pos")) and
new_vehicle.get("lane") == "A1B1_0"):
car_in_way.append(new_vehicle.get("id"))
#identifying cars on same lane ahead of the trailer
else:
#print("no vehicle in the way")
continue
else:
#print("trailer on other path")
continue
else:
continue
#B = B+1
step = step + 1
traci.close()
import xml.etree.ElementTree as ET #required library
inp_file = ET.parse('simexp_trace.xml') #reading the XML file
fcdexport = inp_file.getroot() #to identify the root, to
my understanding the first tag <fcd-export>
time_step = fcdexport.findall("timestep") #There are multiple
timestep tags, creates a list
z=207 #timestep value, simulation
procceds in timesteps
vehicle_info = time_step[z].findall("vehicle") #all vehicle tags in a
particular timestep, timestep 100 in this case
y = 0 #some indicators to
evaluate if the code is correct
A = 0 #some indicators to
evaluate if the code is correct
B= 0 #some indicators to
evaluate if the code is correct
car_in_way = [] #creates a list which
stores vehicle ids
for x in vehicle_info: #runs loop for all elements
in list vehicle_info
#print(x.get("id"))
y = y+1
if (x.get("type")) == "trail": #to identify trailer
A = A+ 1
if ((x.get("lane")) == "A1B1_0"): #specifying the lane
truck_pos = float(x.get("pos")) #copys value of truck's
position
for new_vehicle in vehicle_info: #loop in loop, checks
elements of the list vehicle_info
if (truck_pos < float(new_vehicle.get("pos")) and
new_vehicle.get("lane") == "A1B1_0"):
car_in_way.append(new_vehicle.get("id")) #identifying
cars on same lane ahead of the trailer
else:
print("no vehicle in the way")
else:
print("trailer on other path")
else:
B = B+1
print(y)
print("No. of trailer =", A)
print("No. of other vehicles =", B)
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
sumo-user mailing list
sumo-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sumo-user