[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [sumo-user] couldChangeLane() error
|
It doesn't help, using right-hand drive is giving me that error. Can you please go through the python code once. Corrected attachment is sent with this mail.
RegardsĀ
The right of way rules are obviously different but apart from that, the largest difference is the lane numbering which you already encountered.
_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/sumo-user
from __future__ import absolute_import
from __future__ import print_function
import os
import sys
import optparse
# we need to import python modules from the $SUMO_HOME/tools directory
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_HOME", os.path.join(
os.path.dirname(__file__), "..", "..", "..")), "tools")) # tutorial in docs
from sumolib import checkBinary # noqa
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')")
import sumolib
import traci
net = sumolib.net.readNet("net6.net.xml", withInternal=True)
def run():
step = 0
# time t = 150s, vehicle is added to the traffic.
while step < 150:
traci.simulationStep()
step += 1
# no_of_vehicle = traci.vehicle.getIDCount()
# obj = open("no_of_vehicle.txt", 'a')
# obj.write(str(step) + "," + str(no_of_vehicle) + '\n')
# obj.close()
traci.route.add("trip1", ["gneE4", "gneE20"])
traci.vehicle.add("newVeh1", "trip1", typeID="reroutingType")
# time t = 3000s, the simulation is ended.
while step < 3000:
traci.simulationStep()
step += 1
# no_of_vehicle = traci.vehicle.getIDCount()
# obj1 = open("no_of_vehicle.txt", 'a')
# obj1.write(str(step) + "," + str(no_of_vehicle) + '\n')
# to get instantaneous speed and distance for "newVeh1" vehicle.
if "newVeh1" in traci.vehicle.getIDList():
# speed = traci.vehicle.getSpeed("newVeh1")
# distance = traci.vehicle.getDistance("newVeh1")
# obj2 = open("distanceInfo.txt", 'a')
# obj2.write(str(step) + "," + str(distance) + '\n')
# obj3 = open("speedInfo.txt", 'a')
# obj3.write(str(step) + "," + str(speed) + '\n')
# to check the condition for Lane Change.
leaderVehicle = traci.vehicle.getLeader("newVeh1")
currentLane = traci.vehicle.getLaneIndex("newVeh1")
defaultMinGap = traci.vehicle.getMinGap("newVeh1")
safetyOffset = 10
definedMinGap = defaultMinGap + safetyOffset
if leaderVehicle == None:
pass
else:
leaderVehicleDistance = leaderVehicle[1]
if leaderVehicleDistance <= 100:
if currentLane == 0:
# int = 1 is for the left lane change state
changeLeftLaneState0 = traci.vehicle.couldChangeLane("newVeh1", 1)
if changeLeftLaneState0 == True:
currentLane = currentLane + 1
traci.vehicle.changeLane("newVeh1", currentLane, 2000)
else:
pass
elif currentLane == 1:
# int = -1 is for the right lane change state
changeRightLaneState1 = traci.vehicle.couldChangeLane("newVeh1", -1)
# int = 1 is for the left lane change
changeLeftLaneState1 = traci.vehicle.couldChangeLane("newVeh1", 1)
if changeRightLaneState1 == True:
currentLane = currentLane - 1
traci.vehicle.changeLane("newVeh1", currentLane, 2000)
elif changeLeftLaneState1 == True:
currentLane = currentLane + 1
traci.vehicle.changeLane("newVeh1", currentLane, 2000)
else:
pass
elif currentLane == 2:
# int = 1 is for the left lane change state
changeLeftLaneState2 = traci.vehicle.couldChangeLane("newVeh1", 1)
# int = -1 is for the right lane change state
changeRightLaneState2 = traci.vehicle.couldChangeLane("newVeh1", -1)
if changeLeftLaneState2 == True:
currentLane = currentLane + 1
traci.vehicle.changeLane("newVeh1", currentLane, 2000)
elif changeRightLaneState2 == True:
currentLane = currentLane - 1
traci.vehicle.changeLane("newVeh1", currentLane, 2000)
else:
pass
elif currentLane == 3:
# int = 1 is for the left lane change state
changeLeftLaneState3 = traci.vehicle.couldChangeLane("newVeh1", 1)
# int = -1 is for the right lane change state
changeRightLaneState3 = traci.vehicle.couldChangeLane("newVeh1", -1)
if changeLeftLaneState3 == True:
currentLane = currentLane + 1
traci.vehicle.changeLane("newVeh1", currentLane, 2000)
elif changeRightLaneState3 == True:
currentLane = currentLane - 1
traci.vehicle.changeLane("newVeh1", currentLane, 2000)
else:
pass
elif currentLane == 4:
# int = 1 is for the left lane change state
changeLeftLaneState4 = traci.vehicle.couldChangeLane("newVeh1", 1)
# int = -1 is for the right lane change state
changeRightLaneState4 = traci.vehicle.couldChangeLane("newVeh1", -1)
if changeLeftLaneState4 == True:
currentLane = currentLane + 1
traci.vehicle.changeLane("newVeh1", currentLane, 2000)
elif changeRightLaneState4 == True:
currentLane = currentLane - 1
traci.vehicle.changeLane("newVeh1", currentLane, 2000)
else:
pass
else:
pass
else:
pass
# t = traci.vehicle.couldChangeLane("newVeh1", 0)
# lane = traci.vehicle.getRoadID("newVeh1")
# lane = lane + "_0"
# lane = traci.vehicle.getLanePosition("newVeh1")
# print(str(step) + "," + str(width))
# print(str(step) + "," + str(t))
# obj1.write("\n")
# obj2.write("\n")
# obj3.write("\n")
# obj1.close()
# obj2.close()
# obj3.close()
traci.close()
sys.stdout.flush()
def get_options():
optParser = optparse.OptionParser()
optParser.add_option("--nogui", action="store_true",
default=False, help="run the commandline version of sumo")
options, args = optParser.parse_args()
return options
if __name__ == "__main__":
options = get_options()
if options.nogui:
sumoBinary = checkBinary('sumo')
else:
sumoBinary = checkBinary('sumo-gui')
# traci.start(
# [sumoBinary, "-c", "config_file5.sumocfg", "--tripinfo-output", "tripinfo.xml", "--netstate-dump",
# "netstate_dump.xml", "--ignore-route-errors"])
traci.start(
[sumoBinary, "-c", "config_file5.sumocfg", "--tripinfo-output", "tripinfo.xml", "--ignore-route-errors"])
run()