Hi Jacob,
I tried this and I am getting this error message.
[image: image.png]
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()
On Tue, Feb 28, 2023 at 9:44 AM Sona S <[email protected]> wrote:
> Thank you very much Jacob for the quick response.
>
> Regards,
> Sona
>
> On Mon, Feb 27, 2023 at 4:59 PM Jakob Erdmann <[email protected]>
> wrote:
>
>> 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
>>
>>
>> Am Mo., 27. Feb. 2023 um 11:19 Uhr schrieb Sona S <[email protected]>:
>>
>>> 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
>>> [email protected]
>>> To unsubscribe from this list, visit
>>> https://www.eclipse.org/mailman/listinfo/sumo-user
>>>
>> _______________________________________________
>> sumo-user mailing list
>> [email protected]
>> To unsubscribe from this list, visit
>> https://www.eclipse.org/mailman/listinfo/sumo-user
>>
>
_______________________________________________
sumo-user mailing list
[email protected]
To unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/sumo-user