Exemple #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();
        }
    }
Exemple #2
0
    //public void Update()
    //{
    //    Readcars();
    //}
    void ReadCars()
    {
        Debug.Log("LLAMANDO");
        carList.Clear();
        /*int simtime = (int)*/
        int simtime = ((Integer)(conn.do_job_get(Simulation.getCurrentTime()))).intValue();

        carIds = (SumoStringList)conn.do_job_get(Vehicle.getIDList());


        foreach (string id in carIds)
        {
            Debug.Log("id:" + id);
            position = (SumoPosition2D)conn.do_job_get(Vehicle.getPosition(id));
            car      = new Auto(position.x, position.y, Convert.ToInt32(id));
            speed    = ((java.lang.Double)conn.do_job_get(Vehicle.getSpeed(id))).doubleValue();
            angle    = ((java.lang.Double)conn.do_job_get(Vehicle.getAngle(id))).doubleValue();
            car.setSpeed(speed);
            car.setAngle(angle);
            carList.Add(car);
        }


        //printCars(cars);
        conn.do_timestep();
    }
Exemple #3
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");
 }
Exemple #4
0
    bool ReadVehicles()
    {
        try
        {
            RemoveVehicles();

            SumoStringList carIds = (SumoStringList)conn.do_job_get(de.tudresden.sumo.cmd.Vehicle.getIDList());

            foreach (string id in carIds)
            {
                conn.do_timestep();
                // create new car
                GameObject newVehicle = Instantiate(carPrefab);
                // assign id
                newVehicle.GetComponent <VehicleContainer>().setId(id);
                // get position
                SumoPosition2D position = (SumoPosition2D)conn.do_job_get(de.tudresden.sumo.cmd.Vehicle.getPosition(id));
                // assign position
                newVehicle.transform.position = new Vector3((float)position.x, CarHeight, (float)position.y);
                // get speed
                double speed = double.Parse(conn.do_job_get(de.tudresden.sumo.cmd.Vehicle.getSpeed(id)).ToString());
                // assign speed
                newVehicle.GetComponent <VehicleContainer>().setSpeed(speed);

                if (id.Contains("ev"))
                {
                    // assign red color to EV
                    newVehicle.GetComponent <Renderer>().material.color = Color.red;
                }

                newVehicle.transform.parent = vehicleParent.transform;
                // store vehicle
                vehicles.Add(newVehicle);
            }
        }
        catch (Exception e)
        {
            Debug.Log("Read Vehicles Exception : " + e.Message + " -- " + e.StackTrace);
            return(false);
        }

        return(true);
    }
Exemple #5
0
    void ReadCoches()
    {
        Debug.Log("LLAMANDO");
        coches.Clear();
        int simtime = (int)conn.do_job_get(Simulation.getCurrentTime());

        carIds = (SumoStringList)conn.do_job_get(Vehicle.getIDList());
        foreach (string id in carIds)
        {
            Debug.Log(id + " ");
            position = (SumoPosition2D)conn.do_job_get(Vehicle.getPosition(id));
            coche    = new Auto(position.x, position.y, Convert.ToInt32(id));
            speed    = (Double)conn.do_job_get(Vehicle.getSpeed(id));
            coche.setSpeed(speed);
            coches.Add(coche);
        }
        pintarCoches(coches);
        conn.do_timestep();
    }
Exemple #6
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;
    }
Exemple #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);
            }
        }