[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [sumo-user] Direction of all vehicle
|
look at the error message from your traci script rather than the error in sumo-gui (which just tries to tell you that the traci script had a problem).
Hi Jacob,
I tried this and I am getting this error message.

My python code is this:
import os
import sys
import traci
import optparse
# we need to import some python modules from the $SUMO_HOME/tools directory
if 'SUMO_HOME' in os.environ:
tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
sys.path.append(tools)
else:
sys.exit("please declare environment variable 'SUMO_HOME'")
from sumolib import checkBinary # Checks for the binary in environ vars
#sumoBinary = "C:/Program Files (x86)/Eclipse/Sumo/bin/sumo-gui.exe"
#sumoCmd = [sumoBinary, "-c", "crossroad.sumocfg","--start"]
# with open("traffic.rou.xml", "wb") as f:
def get_options():
opt_parser = optparse.OptionParser()
opt_parser.add_option("--nogui", action="store_true",
default=False, help="run the commandline version of sumo")
options, args = opt_parser.parse_args()
return options
# contains TraCI control loop
def run():
step = 0
count = 0
while traci.simulation.getMinExpectedNumber() > 0 and step < 200:
traci.simulationStep()
print('Step: ', step)
step += 1
vehID = traci.vehicle.getIDList()
print(traci.vehicle.getIDList())
count = count + vehID
print(traci.vehicle.getLaneID(vehID))
edges = traci.vehicle.getRoute(vehID)
index = traci.vehicle.getRouteIndex(vehID)
nextEdge = edges[index + 1]
laneID = traci.vehicle.getLane(vehID)
links = traci.lane.getLinks(laneID)
print(vehID)
print(count)
traci.close()
sys.stdout.flush()
# main entry point
if __name__ == "__main__":
options = get_options()
# check binary
if options.nogui:
sumoBinary = checkBinary('sumo')
else:
sumoBinary = checkBinary('sumo-gui')
print("TRaCI Starts Sumo")
# traci starts sumo as a subprocess and then this script connects and runs
traci.start([sumoBinary, "-c", "crossroad.sumocfg",
"--tripinfo-output", "tripinfo.xml"])
run()
Thank you very much Jacob for the quick response.
Regards,
Sona
edges = traci.vehicle.getRoute(vehID)
index = traci.vehicle.getRouteIndex(vehID)
nextEdge = edges[index + 1]
laneID = traci.vehicle.getLane(vehID)
links = traci.lane.getLinks(laneID)
each object in links has a direction, find the one where laneID.startswith(nextEdge) is True
Hi,
How to get the direction of the vehicle in SUMO? For example,at the intersection there are four directions in total and vehicles can travel in three directions. So how to get the direction which vehicle is going straight, right and left?
Thanks in advance.
Regards,
Sona
_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/sumo-user
_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/sumo-user
_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/sumo-user