Hello,
I am trying to make some simple applications using TraCI.

*usingtraci1.py*
This code executes correctly and vehicle with vehicle ID v1 is stops
whenever the traffic light is red irrespective of it's position.

traci.simulationStep()
    if traci.trafficlights.getPhase("B2") == 0:      #signal at B2 in state
GGrr
        traci.vehicle.setSpeed("v1", 0)
    else:
        traci.vehicle.setSpeed("v1", 20)
    step = step + 1

But the problem once the vehicle v1 leaves the network the execution stops
and an error is generated because v1 is no longer in network. Please help
understand how may I avoid it.

*My approach to avoid this error*:
I thought of capturing vehicle ID and writing that to txt file. I'll
re-structure the if statement and only if v1 is in the network then the
previous command will be executed.

However I am getting an in file *usingtraci3.py*

*Error: tcpip::Socket::recvAndCheck @ recv: Socket reset by peer*
*Quitting (on error).*

I think it's for the wrong usage of command:
get_id = traci.vehicle.getId()
Please help me identify the correct command.

Next, I plan write all the values to text file:
with open ("vid.txt", "w") as vehicle_id:
        get_id = traci.vehicle.getLastStepVehicleIDs()
        vehicle_id.write (str(get_id) + '\n')

Is there a standard syntax for using commands retrieving vehicle ID?
How can we use these values in run time?

For eg:
if (traci.vehicle.getId() == 'A1')
 traci.trafficlights.setPhase("traffic_light_index", phase_index)


Thank you.

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'")
'''
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.27.1", 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/vr2002/Downloads/sumo-win64-0.27.1/sumo-0.27.1/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", "att2.sumo.cfg", 
"--remote-port", str(PORT)], stdout=sys.stdout, stderr=sys.stderr)

import traci
traci.init(PORT)
step = 0
while traci.simulation.getMinExpectedNumber() > 0:
    traci.simulationStep()
    if traci.trafficlights.getPhase("B2") == 0:      #signal at B2 in state GGrr
        traci.vehicle.setSpeed("v1", 0)
    else:
        traci.vehicle.setSpeed("v1", 20)
    step = step + 1
traci.close()

       
#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'")
'''
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.27.1", 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/vr2002/Downloads/sumo-win64-0.27.1/sumo-0.27.1/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", "att2.sumo.cfg", 
"--remote-port", str(PORT)], stdout=sys.stdout, stderr=sys.stderr)

import traci
traci.init(PORT)
step = 0
while traci.simulation.getMinExpectedNumber() > 0:
    traci.simulationStep()
    get_id = traci.vehicle.getIdList()
    step = step + 1
traci.close()

       
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
sumo-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sumo-user

Reply via email to