Ejemplo n.º 1
0
    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();
        }
    }
Ejemplo n.º 2
0
 public virtual void Start(string sumo_bin, string net_file, string route_file)
 {
     conn = new SumoTraciConnection(sumo_bin, net_file, route_file);
     try
     {
         conn.RunServer("127.0.0.1", 0);
         this.running = true;
     }
     catch (Exception ex)
     {
         MonoBehaviour.print(ex.GetBaseException());
         this.running = false;
     }
 }
Ejemplo n.º 3
0
 public virtual void Start_ws()
 {
     conn = new SumoTraciConnection(conf.sumo_bin, conf.config_file);
     //this.Add_options();
     try
     {
         conn.RunServer("127.0.0.1", 0);
         this.running = true;
     }
     catch (Exception ex)
     {
         MonoBehaviour.print(ex.GetBaseException());
         this.running = false;
     }
 }
Ejemplo n.º 4
0
 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");
 }
Ejemplo n.º 5
0
    /*
     * 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;
    }
Ejemplo n.º 6
0
    // Use this for initialization
    void Start()
    {
        // Init Colors
        colors = new List <Color> {
            new Color(153f / 255f, 0f, 0f),
            new Color(51f / 255f, 102f / 255f, 0f),
            new Color(0f, 102f / 255f, 204f / 255f),
            new Color(1f, 1f, 1f),
            new Color(0f, 0f, 0f),
            new Color(77f / 255f, 77f / 255f, 77f / 255f),
            new Color(97f / 255f, 83f / 255f, 63f / 255f),
            new Color(1f, 1f, 102f / 255f),
            new Color(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f)),
            new Color(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f)),
            new Color(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f)),
            new Color(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f))
        };

        // Read paths from text files
        string sumoBinPath;

        if (sumoGUIEnabled)
        {
            sumoBinPath = System.IO.File.ReadAllText(Application.dataPath + "\\Resources\\sumoBinPath.dat") + "\\sumo-gui.exe";
        }
        else
        {
            sumoBinPath = System.IO.File.ReadAllText(Application.dataPath + "\\Resources\\sumoBinPath.dat") + "\\sumo.exe";
        }
        string mapNet   = (System.IO.File.ReadAllText(Application.dataPath + "\\Resources\\sumoFilesPath.dat") + "\\map.net.xml").Replace("/", "\\");
        string routeNet = (System.IO.File.ReadAllText(Application.dataPath + "\\Resources\\sumoFilesPath.dat") + "\\map.rou.xml").Replace("/", "\\");

        // Other vehicles
        vehiclesInScene = new List <GameObject>();
        vehicles        = new Dictionary <string, SUMOCombinedPositionOrientation>();
        vehicles3D      = new Dictionary <string, GameObject>();

        conn = new SumoTraciConnection(sumoBinPath, mapNet, routeNet);

        conn.AddOption("step-length", stepLengthSeconds + "");
        conn.AddOption("start", "");       // start sumo immediately
        conn.AddOption("quit-on-end", ""); // stop sumo immediately after unity3D stopped

        // start Traci Server
        conn.RunServer(remoteIpAddress, Convert.ToInt32(this.remotePort));

        if (enableEgoVehicle)
        {
            // Insert ego vehicle
            // Get random route for being able to insert the ego vehicle (A new vehicle must have a route assigned)
            SumoStringList routes = (SumoStringList)conn.Do_job_get(Route.GetIDList());
            conn.Do_job_set(Vehicle.Add("egoVehicle", "DEFAULT_VEHTYPE", routes.Get(0), 0, 0, 0, (byte)0));
            conn.Do_job_set(Vehicle.SetColor("egoVehicle", new SumoColor(127, 0, 0, 127)));
        }

        // Find all traffic lights
        trafficLights3D = new Dictionary <string, GameObject>();
        SumoStringList trafficLights = (SumoStringList)conn.Do_job_get(Trafficlights.GetIDList());

        foreach (string s in trafficLights.getList())
        {
            var objects = Resources.FindObjectsOfTypeAll <GameObject>().Where(obj => obj.name.Equals("TrafficLight_" + s));
            foreach (GameObject g in objects)
            {
                trafficLights3D.Add(s + g.transform.Find("index").GetChild(0).name, g);
            }
        }

        // Timer for Realtime-Simulation
        unity3DstartTime = Stopwatch.StartNew();

        // Timer for traffic lights update (No need to do this every sim step)
        trafficLightsUpdate = Stopwatch.StartNew();

        // Timer for watchdog
        watchdog = new Stopwatch();
    }
Ejemplo n.º 7
0
        //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);
            }
        }