Hello, I am implementing a project (Dynamic Street Lighting system) in SUMO in which I need to change the color of the lamp(POI) when a vehicle is detected in it's vicinity. How do I do so?
Also, I am trying to retrieve values of the vehicles from the simulation but I am not getting any result. I have randomly generated vehicles in a *.rou.xml file* (using Python) In the Python code In *traci.start()* I have added my sumocfg file in which the route file has been given as input tag and in *subprocess.call()* i have added the *.net.xml* file still vehicles' values are not retrieved for traci.vehicle.IDList() but it is working for traci.poi.getColor. Why is this so? I have attached my code below #!/usr/bin/env python # Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo # Copyright (C) 2009-2017 German Aerospace Center (DLR) and others. # This program and the accompanying materials # are made available under the terms of the Eclipse Public License v2.0 # which accompanies this distribution, and is available at # http://www.eclipse.org/legal/epl-v20.html from __future__ import absolute_import from __future__ import print_function import struct import os import sys import optparse import subprocess import random import warnings # 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 import randomTrips except ImportError: sys.exit( "please declare environment variable 'SUMO_HOME'") import traci import sumolib def generate_routefile(): random.seed(42) # make tests reproducible N = 200 # number of time steps # demand per second from different directions pWE = 1. / 10 pEW = 1. / 11 ## pNS = 1. / 30 with open("tp.rou.xml", "w") as routes: print("""<routes> <vType id="Car" accel="1.0" decel="5.0" sigma="0" length="5.0" minGap="2.0" maxSpeed="50.0"/> <route id="route0" edges="2to1"/> <route id="route1" edges="1to2"/>""", file=routes) lastVeh = 0 vehNr = 0 for i in range(N): if random.uniform(0, 1) < pWE: print(' <vehicle id="right_%i" type="Car" route="route1" depart="%i" />' % ( vehNr, i), file=routes) vehNr += 1 lastVeh = i if random.uniform(0, 1) < pEW: print(' <vehicle id="left_%i" type="Car" route="route0" depart="%i" />' % ( vehNr, i), file=routes) vehNr += 1 lastVeh = i print("</routes>", file=routes) def run(): while traci.simulation.getMinExpectedNumber() > 0: traci.simulationStep() print("hello") print(traci.poi.getColor("1")) print(traci.poi.setColor("1",[0,0,255,255])) print(traci.poi.getColor("2")) print(traci.poi.setColor("2",[255,0,0,255])) print(traci.vehicle.getIDList()) vehicles = traci.simulation.getDepartedIDList() print("ID of vehicles are:") for i in range(len(vehicles)): print(vehicles[i]) print(traci.vehicle.getSpeed("left_0")) #error vehicle not known 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') net = 'tp.net.xml' subprocess.call([checkBinary('netconvert'), '-c', 'tp.net.xml', '--output-file', net]) randomTrips.main(randomTrips.get_options([ '--net-file', net])) generate_routefile() traci.start([sumoBinary, "-c", "tp.sumocfg", "--tripinfo-output", "tripinfo.xml"]) run() Also how should i approach the detection of vehicle under the POI's vicinity? ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ sumo-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sumo-user
