Hi, I am Charan working as Research Assistant, newbie to SUMO.
My primary objective is to do a traffic scenario with specified parameters of the vehicles. To accomplish that i made network, route, sumocfg files and the simulation is working fine in SUMO-GUI. Herewith i enclosed the files for your reference. I am trying to use TraCI commands in "runner.py" file and in the wiki for TraCI the commands are presented in octal format or so. How to configure the behavior of vehicle in "runner.py" file ? *Can we change the parameters of the vehicle dynamically (change in speed during simulation) ?* It has become a bit difficult task even to manipulate the existing example code. I enclosed a "runner.py" file which i tried to manipulate according to my requirements and failed to do so. Here are the queries: 1. Change the speed of the specified vehicle(s) to the given value over the given amount of time in milliseconds (increase/decrease to decrease/increase speed). I guess that would happen only using TraCI commands. 2.. If there is traffic on the current lane, the vehicle should be able to switch to next lane accordingly. 3. How to control the vehicles not to undergo random lane change ? I would really appreciate if you could help me to sort out this.I am sure you will be busy with your schedule. Please take time to reply in your free time. Thanks in advance. *Best Regards,* Sai Charan A Research Assistant (RA), IIIT Sricity.
SUMO_files.tar.gz
Description: GNU Zip compressed data
#!/usr/bin/env python
import os, sys
import optparse
import subprocess
import random
# 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
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 traci
# the port used for communicating with your sumo instance
PORT = 9999
def generate_routefile():
with open("data/i.rou.xml", "w") as routes:
print >> routes, """<routes>
<vType id="bus" accel="2.6" decel="4.5" sigma="0" length="12" minGap="3" maxSpeed="70" color="1,1,0" guiShape="bus"/>
<vType id="CarA" accel="3.0" decel="6.0" length="5.0" minGap="2.5" maxSpeed="50.0" sigma="0" />
<route id="route01" edges="D1 D2 D3 D4 D5 D6 D7"/>"""
print >> routes, "</routes>"
def run():
"""execute the TraCI control loop"""
traci.init(PORT)
traci.vehicle.setStop(CarA,D2, pos=200.0, laneIndex=10, duration=2147483647, flags=0)
traci.vehicle.setDecel(bus1,2)
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
# this is the main entry point of this script
if __name__ == "__main__":
options = get_options()
# this script has been called from the command line. It will start sumo as a
# server, then connect and run
if options.nogui:
sumoBinary = checkBinary('sumo')
else:
sumoBinary = checkBinary('sumo-gui')
# first, generate the route file for this simulation
generate_routefile()
# this is the normal way of using traci. sumo is started as a
# subprocess and then the python script connects and runs
sumoProcess = subprocess.Popen([sumoBinary, "-c", "data/i.sumocfg", "--tripinfo-output", "tripinfo.xml", "--remote-port", str(PORT)], stdout=sys.stdout, stderr=sys.stderr)
run()
sumoProcess.wait()
------------------------------------------------------------------------------
_______________________________________________ sumo-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sumo-user
