void Start() { try { config_file = GameObject.FindGameObjectsWithTag("Persistant_Data")[0].GetComponent <persistant_data>().path_to_osm; // read data from menue conn = new SumoTraciConnection(sumo_bin, config_file); //set some options conn.addOption("step-length", "0.1"); //timestep 100 ms conn.addOption("start", ""); conn.runServer(); conn.do_timestep(); carList = new List <Auto>(); linkList = new List <Link>(); ReadLanes(); printLanes(linkList); //for (int i = 0; i < 300; i++) //{ // ReadCars(); //} //printCars(carList); //Debug.Log("Invoke?"); //InvokeRepeating("Readcars", 1, 0.3F); //Debug.Log("Afterinvoke"); } catch (System.Exception) { conn.close(); } }
void Start() { conn = new SumoTraciConnection(sumo_bin, config_file); //set some options conn.addOption("step-length", "0.1"); //timestep 100 ms conn.addOption("start", ""); conn.runServer(); for (int i = 0; i < 10000; i++) { conn.do_timestep(); } conn.do_timestep(); coches = new List <Auto>(); Debug.Log("Sos puto?"); // InvokeRepeating("ReadCoches", 1, 0.3F); Debug.Log("Si, mucho"); }
/* * Initialize * * Pseudo : * * conn = new SumoTraciConnection(sumo_dir,config_file) * conn.runServer() * launchSumoInRemotePort() * tcp_connectToSUMO() * conn.do_timestep() * readLanes() * printLanes() * */ void Initialize() { conn = new SumoTraciConnection(sumo_bin, config_file); //set some options conn.addOption("step-length", "0.3333"); //timestep 33.33ms - 30 frames a second conn.addOption("start", null); conn.runServer(); for (int i = 0; i < 100; i++) { conn.do_timestep(); } lanes = new List <GameObject>(); vehicles = new List <GameObject>(); laneParent = new GameObject(); laneParent.name = "lanesCreatedOnRuntime"; vehicleParent = new GameObject(); vehicleParent.name = "vehiclesCreatedOnRuntime"; vehiclesCreationSuccess = false; }
//public static void step(NetworkStream bw, int j) //{ // byte[] bytes = { 0, 0, 0, 10, 6, 2, 0, 0, 0, 0 }; // bw.Write(bytes, 0, bytes.Length); // bw.Flush(); //} public static void Main(String[] argv) { //Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //socket.NoDelay = true; //try //{ // socket.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 60634)); //} //catch (Exception localConnectException) //{ // Console.WriteLine(localConnectException.StackTrace.ToString()); //} //NetworkStream ns = new NetworkStream(socket); ////BinaryWriter bw = new BinaryWriter(ns); //for (int i = 0; i < 1000; i++) //{ // step(ns,i); //} String configfile = "C:/Users/Biurrun/Tesis/Examples/Test2/Test2.sumo.cfg"; //start Simulation int seed = -1; bool withGui = true; int steplength = 300; SumoTraciConnection conn = new SumoTraciConnection(configfile, seed, withGui, steplength); //conn.addOption("step-length", steplength); float simtime; try { //start TraCI conn.runServer(); if (conn.isClosed()) { throw new InvalidOperationException("connection is closed"); } //load routes and initialize the simulation conn.do_timestep(); for (int i = 0; i < 500; i++) { simtime = i * steplength; //ms //current simulation time //int simtime = (int)conn.do_job_get(Simulation.getCurrentTime()); //Console.WriteLine(simtime); //conn.do_job_set(Vehicle.add("veh" + i, "car", "s1", simtime, 0, 13.8, (byte)1)); conn.do_timestep(); } //conn.get_vehicle_count(); //conn.get_vehicle_list(); //stop TraCI conn.close(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } }