Esempio n. 1
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();
    }
Esempio n. 2
0
    public static List <string> GetAllowedVehiclesListFromSumoStringList(SumoStringList list)
    {
        List <string> finalList = new List <string>();


        return(finalList);
    }
Esempio n. 3
0
        public SumoCommand(Object input1, Object input2, Object input3, Object input)
        {
            this.cmd    = new Command((int)input1);
            this.input1 = (int)input1;
            this.input2 = (int)input2;
            cmd.Content().WriteUnsignedByte((int)input2);
            cmd.Content().WriteStringASCII(input3.ToString());
            if (input.GetType().Equals(typeof(StringList)))
            {
                StringList sl = (StringList)input;
                cmd.Content().WriteUnsignedByte(Constants.TYPE_STRINGLIST);
                cmd.Content().WriteInt(sl.Count());
                foreach (string s in sl)
                {
                    cmd.Content().WriteStringASCII(s);
                }
            }
            else if (input.GetType().Equals(typeof(SumoStringList)))
            {
                SumoStringList sl = (SumoStringList)input;
                cmd.Content().WriteUnsignedByte(Constants.TYPE_STRINGLIST);
                cmd.Content().WriteInt(sl.getList().Count());
                foreach (string s in sl.getList())
                {
                    cmd.Content().WriteStringASCII(s);
                }
            }
            else if (input.GetType().Equals(typeof(SumoTLSLogic)))
            {
                SumoTLSLogic stl = (SumoTLSLogic)input;
                cmd.Content().WriteUnsignedByte(Constants.TYPE_COMPOUND);
                cmd.Content().WriteInt(stl.phases.Count());
                cmd.Content().WriteUnsignedByte(Constants.TYPE_STRING);
                cmd.Content().WriteStringASCII(stl.subID);
                cmd.Content().WriteUnsignedByte(Constants.TYPE_INTEGER);
                cmd.Content().WriteInt(0);
                cmd.Content().WriteUnsignedByte(Constants.TYPE_COMPOUND);
                cmd.Content().WriteInt(0);
                cmd.Content().WriteUnsignedByte(Constants.TYPE_INTEGER);
                cmd.Content().WriteInt(stl.currentPhaseIndex);
                cmd.Content().WriteUnsignedByte(Constants.TYPE_INTEGER);
                cmd.Content().WriteInt(stl.phases.Count());
                foreach (SumoTLSPhase phase in stl.phases)
                {
                    Add_variable(phase);
                }
            }
            else
            {
                Add_type(input);
                Add_variable(input);
            }

            this.raw = new LinkedList <Object>();
            this.raw.AddLast(input1);
            this.raw.AddLast(input2);
            this.raw.AddLast(input3);
            this.raw.AddLast(input);
        }
Esempio n. 4
0
    private void updateAllTrafficLights()
    {
        SumoStringList trafficLights = (SumoStringList)conn.Do_job_get(Trafficlights.GetIDList());

        foreach (string s in trafficLights.getList())
        {
            //string phase = (string) conn.Do_job_get(Trafficlights.GetProgram(s));
            string phase = (string)conn.Do_job_get(Trafficlights.GetRedYellowGreenState(s));
            // TODO: ONLY WORKS FOR 3- or 4- lanes intersections!!!!!!!!!
            int increment = (phase.Length == 6 ? 2 : 3);
            for (int i = 0; i < phase.Length; i += increment)
            {
                switch (phase.Substring(i, 1))
                {
                case "G":
                case "g":
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/rot").gameObject.SetActive(false);
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/gelb").gameObject.SetActive(false);
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/gruen").gameObject.SetActive(true);
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/rot1").gameObject.SetActive(false);
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/gelb1").gameObject.SetActive(false);
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/gruen1").gameObject.SetActive(true);
                    break;

                case "Y":
                case "y":
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/rot").gameObject.SetActive(false);
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/gelb").gameObject.SetActive(true);
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/gruen").gameObject.SetActive(false);
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/rot1").gameObject.SetActive(false);
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/gelb1").gameObject.SetActive(true);
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/gruen1").gameObject.SetActive(false);
                    break;

                case "r":
                case "R":
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/rot").gameObject.SetActive(true);
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/gelb").gameObject.SetActive(false);
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/gruen").gameObject.SetActive(false);
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/rot1").gameObject.SetActive(true);
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/gelb1").gameObject.SetActive(false);
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/gruen1").gameObject.SetActive(false);
                    break;

                case "0":
                case "o":
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/rot").gameObject.SetActive(false);
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/gelb").gameObject.SetActive(false);
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/gruen").gameObject.SetActive(false);
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/rot1").gameObject.SetActive(false);
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/gelb1").gameObject.SetActive(false);
                    trafficLights3D[s + i / increment].transform.Find("Traffic_light/gruen1").gameObject.SetActive(false);
                    break;
                }
            }
        }
    }
Esempio n. 5
0
        public virtual SumoStringList GetStringList(System.Object obj)
        {
            SumoStringList output = new SumoStringList();

            try
            {
                if (obj.GetType().Equals(typeof(SumoStringList)))
                {
                    output = (SumoStringList)obj;
                }
            }
            catch (Exception ex)
            {
                MonoBehaviour.print(ex.GetBaseException());
            }

            return(output);
        }
Esempio n. 6
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();
    }
Esempio n. 7
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);
    }
Esempio n. 8
0
    /*
     * ReadLanes
     *
     * Pseudo:
     *
     * conn.do_job_get(LaneIDList)
     * linkList = new List<Link>()
     * foreach(id in IDlist)
     *  vertices = conn.do_job_get(laneID.Vertices)
     *  width = conn.do_job_get(laneID.Width)
     *  allowed = conn.do_job_get(laneID.AllowedVehicles)
     *      type = switch(allowed)
     *  link = new Link(vertices,width,id,type)
     *  linkList.add(link)
     * printLanes()
     *
     * */

    void ReadAndPrintLanes()
    {
        try
        {
            lanes.Clear();
            SumoStringList laneIDs = (SumoStringList)conn.do_job_get(Lane.getIDList());
            foreach (string id in laneIDs)
            {
                // Get lane details
                var            laneShape     = conn.do_job_get(Lane.getShape(id));
                List <Vector3> laneShapeList = HelperMethods.GetPoisitonsListFromSumoStringList(laneShape.ToString(), 0);

                double length = double.Parse(conn.do_job_get(Lane.getLength(id)).ToString());
                double width  = double.Parse(conn.do_job_get(Lane.getWidth(id)).ToString());

                var           allowedVehicles    = (SumoStringList)conn.do_job_get(Lane.getAllowed(id));
                List <string> allowedVehicleList = new List <string>();
                if (allowedVehicles.size() > 0)
                {
                    // do allowed vehicle parse here
                    // future use -- method not implemented
                    allowedVehicleList = HelperMethods.GetAllowedVehiclesListFromSumoStringList(allowedVehicles);
                }

                GameObject lane = DrawLane(laneShapeList[0], laneShapeList[1], (float)width);
                lane.AddComponent <LaneContainer>();
                lane.GetComponent <LaneContainer>().SetLaneProperties(id, laneShapeList[0], laneShapeList[1], length, width, allowedVehicleList);
                lane.transform.parent = laneParent.transform;
                lanes.Add(lane);
            }
        }
        catch (Exception e) {
            Debug.Log("Read Lanes Exception : " + e.Message + " -- " + e.StackTrace);
            return;
        }
    }
Esempio n. 9
0
 public static SumoCommand SetRoute(string vehID, SumoStringList edgeList)
 {
     Object[] array = new Object[] { edgeList };
     return(new SumoCommand(Constants.CMD_SET_VEHICLE_VARIABLE, Constants.VAR_ROUTE, vehID, array));
 }
Esempio n. 10
0
    // Update is called once per frame
    void Update()
    {
        watchdog.Start();

        // Simulation step with realtime check
        if ((unity3DstartTime.ElapsedMilliseconds > stepLengthSeconds * 1000 * simStep) && (simStep < maxSimSteps))
        {
            // Update egoVehicle coordinates for forwarding them to SUMO
            double xEgo     = 0;;
            double yEgo     = 0;;
            double angleEgo = 0;;
            if (enableEgoVehicle)
            {
                egoVehicle = GameObject.Find("egoVehicle_Peugot_WASD(Clone)");
                if (egoVehicle == null)
                {
                    egoVehicle = GameObject.Find("egoVehicle_Peugot(Clone)");
                }

                xEgo     = egoVehicle.transform.position.x;
                yEgo     = egoVehicle.transform.position.z;
                angleEgo = egoVehicle.transform.rotation.eulerAngles.y;
            }

            // Only do next time step if it's necessary (not to fast)
            conn.Do_timestep();
            simStep++;

            if (enableEgoVehicle)
            {
                // Update egoVehicle
                conn.Do_job_set(Vehicle.MoveToVTD("egoVehicle", "0", 0, xEgo, yEgo, angleEgo, 2));
            }

            // Before updating all vehicles store the vehicles from last step for steering angle approximation (and prob. other interpolations)
            lastStepVehicles = vehicles.ToDictionary(i => i.Key, i => i.Value);


            // Get IDs of all vehicles in Simulation
            SumoStringList vehicleIDs = (SumoStringList)conn.Do_job_get(Vehicle.GetIDList());
            vehicles.Clear();

            foreach (string id in vehicleIDs.getList())
            {
                SumoPosition3D position = (SumoPosition3D)conn.Do_job_get(Vehicle.GetPosition3D(id));
                double         yawAngle = (double)conn.Do_job_get(Vehicle.GetAngle(id));
                vehicles.Add(id, new SUMOCombinedPositionOrientation(id, position, yawAngle));
            }

            // Update all 3D vehicle models
            update3DVehiclesInScene();

            // Update all traffic lights every refreshTimeTrafficLightsMS miliseconds
            if (trafficLightsUpdate.ElapsedMilliseconds > refreshTimeTrafficLightsMS)
            {
                updateAllTrafficLights();
                trafficLightsUpdate.Reset();
                trafficLightsUpdate.Start();
            }
        }

        // Watchdog
        long stopTime = watchdog.ElapsedMilliseconds;

        if (stopTime > stepLengthSeconds * 1000)
        {
            watchDogCount++;
            print("Warning: Stepwidth of " + stepLengthSeconds * 1000 + "ms is too short for calculation loop, needed " + stopTime +
                  "ms, Exceeded " + watchDogCount + " times, Current total offset: " + (unity3DstartTime.ElapsedMilliseconds - 1000 * simStep * stepLengthSeconds + stopTime) + " ms");
        }
        watchdog.Reset();
    }
Esempio n. 11
0
 public static SumoCommand SetDisallowed(string laneID, SumoStringList disallowedClasses)
 {
     return(new SumoCommand(Constants.CMD_SET_LANE_VARIABLE, Constants.LANE_DISALLOWED, laneID, disallowedClasses));
 }
Esempio n. 12
0
 public static SumoCommand setDisallowed(String laneID, SumoStringList paramSumoStringList)
 {
     return(new SumoCommand(Convert.ToInt32(195), Convert.ToInt32(53), laneID, paramSumoStringList));
 }
Esempio n. 13
0
 public static SumoCommand add(String routeID, SumoStringList edges)
 {
     return(new SumoCommand(Convert.ToInt32(198), Convert.ToInt32(128), routeID, edges));
 }
Esempio n. 14
0
        public SumoCommand(Object input1, Object input2, Object input3, Object[] array)
        {
            this.cmd    = new Command((int)input1);
            this.input1 = (int)input1;
            this.input2 = (int)input2;
            cmd.Content().WriteUnsignedByte((int)input2);
            cmd.Content().WriteStringASCII(input3.ToString());
            if ((int)input2 == Constants.VAR_COLOR)
            {
                cmd.Content().WriteUnsignedByte(Constants.TYPE_COLOR);
                for (int i = 0; i < array.Length; i++)
                {
                    Add_variable(array[i]);
                }
            }
            else if ((int)input2 == Constants.VAR_ROUTE)
            {
                cmd.Content().WriteUnsignedByte(Constants.TYPE_STRINGLIST);
                SumoStringList sl = (SumoStringList)array[0];
                cmd.Content().WriteInt(sl.getList().Count());
                foreach (string s in sl.getList())
                {
                    cmd.Content().WriteStringASCII(s);
                }
            }
            else if ((int)input2 == Constants.CMD_REROUTE_EFFORT || (int)input2 == Constants.CMD_REROUTE_TRAVELTIME || (int)input2 == Constants.CMD_RESUME)
            {
                cmd.Content().WriteUnsignedByte(Constants.TYPE_COMPOUND);
                cmd.Content().WriteInt(0);
            }
            else if ((int)input2 == Constants.VAR_VIEW_BOUNDARY)
            {
                cmd.Content().WriteUnsignedByte(Constants.TYPE_BOUNDINGBOX);
                for (int i = 0; i < array.Length; i++)
                {
                    Add_variable(array[i]);
                }
            }
            else if ((int)input2 == Constants.VAR_VIEW_OFFSET)
            {
                cmd.Content().WriteUnsignedByte(Constants.POSITION_2D);
                for (int i = 0; i < array.Length; i++)
                {
                    Add_variable(array[i]);
                }
            }
            else if ((int)input1 == Constants.CMD_SET_POLYGON_VARIABLE && (int)input2 == Constants.ADD)
            {
                cmd.Content().WriteUnsignedByte(Constants.TYPE_COMPOUND);
                cmd.Content().WriteInt(5);
                Add_type(array[3]);
                Add_variable(array[3]);
                Add_type(array[1]);
                Add_variable(array[1]);
                Add_type(array[2]);
                Add_variable(array[2]);
                Add_type(array[4]);
                Add_variable(array[4]);
                Add_type(array[0]);
                Add_variable(array[0]);
            }
            else if ((int)input1 == Constants.CMD_SET_POI_VARIABLE && (int)input2 == Constants.VAR_POSITION)
            {
                cmd.Content().WriteUnsignedByte(Constants.POSITION_2D);
                Add_variable(array[0]);
                Add_variable(array[1]);
            }
            else if ((int)input1 == Constants.CMD_SET_POI_VARIABLE && (int)input2 == Constants.ADD)
            {
                cmd.Content().WriteUnsignedByte(Constants.TYPE_COMPOUND);
                cmd.Content().WriteInt(4);
                Add_type(array[3]);
                Add_variable(array[3]);
                Add_type(array[2]);
                Add_variable(array[2]);
                Add_type(array[4]);
                Add_variable(array[4]);
                cmd.Content().WriteUnsignedByte(Constants.POSITION_2D);
                Add_variable(array[0]);
                Add_variable(array[1]);
            }
            else
            {
                cmd.Content().WriteUnsignedByte(Constants.TYPE_COMPOUND);
                cmd.Content().WriteInt(array.Length);
                for (int i = 0; i < array.Length; i++)
                {
                    Add_type(array[i]);
                    Add_variable(array[i]);
                }
            }

            this.raw = new LinkedList <Object>();
            this.raw.AddLast(input1);
            this.raw.AddLast(input2);
            this.raw.AddLast(input3);
            this.raw.AddLast(array);
        }
Esempio n. 15
0
 private void Add_variable(Object input)
 {
     if (input.GetType().Equals(typeof(int)))
     {
         this.cmd.Content().WriteInt((int)input);
     }
     else if (input.GetType().Equals(typeof(string)))
     {
         this.cmd.Content().WriteStringASCII((string)input);
     }
     else if (input.GetType().Equals(typeof(Double)))
     {
         this.cmd.Content().WriteDouble((Double)input);
     }
     else if (input.GetType().Equals(typeof(Byte)))
     {
         this.cmd.Content().WriteByte((Byte)input);
     }
     else if (input.GetType().Equals(typeof(bool)))
     {
         bool b = (bool)input;
         cmd.Content().WriteUnsignedByte(b ? 1 : 0);
     }
     else if (input.GetType().Equals(typeof(SumoColor)))
     {
         SumoColor sc = (SumoColor)input;
         this.cmd.Content().WriteByte(sc.r);
         this.cmd.Content().WriteByte(sc.g);
         this.cmd.Content().WriteByte(sc.b);
         this.cmd.Content().WriteByte(sc.a);
     }
     else if (input.GetType().Equals(typeof(SumoGeometry)))
     {
         SumoGeometry sg = (SumoGeometry)input;
         cmd.Content().WriteUnsignedByte(sg.coords.Count());
         foreach (SumoPosition2D pos in sg.coords)
         {
             cmd.Content().WriteDouble(pos.x);
             cmd.Content().WriteDouble(pos.y);
         }
     }
     else if (input.GetType().Equals(typeof(SumoPosition2D)))
     {
         SumoPosition2D pos = (SumoPosition2D)input;
         cmd.Content().WriteDouble(pos.x);
         cmd.Content().WriteDouble(pos.y);
     }
     else if (input.GetType().Equals(typeof(SumoTLSPhase)))
     {
         SumoTLSPhase stp = (SumoTLSPhase)input;
         this.cmd.Content().WriteUnsignedByte(Constants.TYPE_INTEGER);
         cmd.Content().WriteInt(stp.duration);
         this.cmd.Content().WriteUnsignedByte(Constants.TYPE_INTEGER);
         cmd.Content().WriteInt(stp.duration1);
         this.cmd.Content().WriteUnsignedByte(Constants.TYPE_INTEGER);
         cmd.Content().WriteInt(stp.duration2);
         this.cmd.Content().WriteUnsignedByte(Constants.TYPE_STRING);
         cmd.Content().WriteStringASCII(stp.phasedef);
     }
     else if (input.GetType().Equals(typeof(SumoStringList)))
     {
         SumoStringList sl = (SumoStringList)input;
         cmd.Content().WriteInt(sl.getList().Count());
         foreach (string s in sl.getList())
         {
             cmd.Content().WriteStringASCII(s);
         }
     }
 }
Esempio n. 16
0
 public static SumoCommand setShape(String polyID, SumoStringList shape)
 {
     return(new SumoCommand(Convert.ToInt32(200), Convert.ToInt32(78), polyID, shape));
 }
Esempio n. 17
0
 public static SumoCommand Add(string routeID, SumoStringList edges)
 {
     return(new SumoCommand(Constants.CMD_SET_ROUTE_VARIABLE, Constants.ADD, routeID, edges));
 }
Esempio n. 18
0
        public /*synchronized*/ Object do_job_get(SumoCommand sc)

        {
            Object            localObject1           = null;
            ResponseContainer localResponseContainer = queryAndVerifySingle(sc.cmd);
            Command           localCommand           = localResponseContainer.getResponse();

            verifyGetVarResponse(localCommand, sc.response, sc.input2, sc.input3);
            verify("", Convert.ToInt32(sc.output_type), Convert.ToInt32(localCommand.Content().readUnsignedByte()));
            if (sc.output_type == 9)
            {
                localObject1 = Convert.ToInt32(localCommand.Content().readInt());
            }
            else if (sc.output_type == 11)
            {
                localObject1 = Convert.ToDouble(localCommand.Content().readDouble());
            }
            else if (sc.output_type == 12)
            {
                localObject1 = localCommand.Content().readStringUTF8();
            }
            else
            {
                double d1;
                double d3;
                if (sc.output_type == 1)
                {
                    d1           = localCommand.Content().readDouble();
                    d3           = localCommand.Content().readDouble();
                    localObject1 = new SumoPosition2D(d1, d3);
                }
                else
                {
                    double d6;
                    if (sc.output_type == 3)
                    {
                        d1           = localCommand.Content().readDouble();
                        d3           = localCommand.Content().readDouble();
                        d6           = localCommand.Content().readDouble();
                        localObject1 = new SumoPosition3D(d1, d3, d6);
                    }
                    else if (sc.output_type == 14)
                    {
                        SumoStringList localSumoStringList = new SumoStringList();
                        int            k = localCommand.Content().readInt();
                        for (int i1 = 0; i1 < k; i1++)
                        {
                            localSumoStringList.add(localCommand.Content().readStringASCII());
                        }
                        localObject1 = localSumoStringList;
                    }
                    else if (sc.output_type == 5)
                    {
                        double d2 = localCommand.Content().readDouble();
                        double d4 = localCommand.Content().readDouble();
                        d6 = localCommand.Content().readDouble();
                        double d8 = localCommand.Content().readDouble();
                        localObject1 = new SumoBoundingBox(d2, d4, d6, d8);
                    }
                    else
                    {
                        Object localObject3;
                        if (sc.input2 == 181)
                        {
                            int i = localCommand.Content().readByte();
                            localObject3 = new SumoStopFlags((byte)i);
                            localObject1 = localObject3;
                            if (sc.info.Equals("isStopped"))
                            {
                                localObject1 = Convert.ToBoolean(((SumoStopFlags)localObject3).stopped);
                            }
                            if (sc.info.Equals("isStoppedTriggered"))
                            {
                                localObject1 = Convert.ToBoolean(((SumoStopFlags)localObject3).triggered);
                            }
                            if (sc.info.Equals("isAtContainerStop"))
                            {
                                localObject1 = Convert.ToBoolean(((SumoStopFlags)localObject3).isContainerStop);
                            }
                            if (sc.info.Equals("isStoppedParking"))
                            {
                                localObject1 = Convert.ToBoolean(((SumoStopFlags)localObject3).getID() == 12);
                            }
                            if (sc.info.Equals("isAtBusStop"))
                            {
                                localObject1 = Convert.ToBoolean(((SumoStopFlags)localObject3).isBusStop);
                            }
                        }
                        else
                        {
                            int i3;
                            if (sc.output_type == 15)
                            {
                                Object localObject2 = null;
                                int    i2;
                                int    i7;
                                int    i8;
                                Object localObject4;
                                if (sc.input2 == 39)
                                {
                                    localObject3 = new SumoLinkList();
                                    localCommand.Content().readUnsignedByte();
                                    localCommand.Content().readInt();
                                    i2           = localCommand.Content().readInt();
                                    localObject2 = new StringList[i2];
                                    for (int i4 = 0; i4 < i2; i4++)
                                    {
                                        localCommand.Content().readUnsignedByte();
                                        i7 = localCommand.Content().readInt();
                                        for (i8 = 0; i8 < i7; i8++)
                                        {
                                            localCommand.Content().readUnsignedByte();
                                            localCommand.Content().readInt();
                                            String str4 = localCommand.Content().readStringASCII();
                                            localObject4 = localCommand.Content().readStringASCII();
                                            String str5 = localCommand.Content().readStringASCII();
                                            ((SumoLinkList)localObject3).add(new SumoLink(str4, (String)localObject4, str5));
                                        }
                                    }
                                    localObject1 = localObject3;
                                }
                                else
                                {
                                    int m;
                                    int i9;
                                    int i10;
                                    if (sc.input2 == 43)
                                    {
                                        localCommand.Content().readUnsignedByte();
                                        localCommand.Content().readInt();
                                        m = localCommand.Content().readInt();
                                        for (i2 = 0; i2 < m; i2++)
                                        {
                                            localCommand.Content().readUnsignedByte();
                                            String str1 = localCommand.Content().readStringASCII();
                                            localCommand.Content().readUnsignedByte();
                                            i7 = localCommand.Content().readInt();
                                            localCommand.Content().readUnsignedByte();
                                            i8 = localCommand.Content().readInt();
                                            localCommand.Content().readUnsignedByte();
                                            i9           = localCommand.Content().readInt();
                                            localObject4 = new SumoTLSLogic(str1, i7, i8, i9);
                                            localCommand.Content().readUnsignedByte();
                                            i10 = localCommand.Content().readInt();
                                            for (int i11 = 0; i11 < i10; i11++)
                                            {
                                                localCommand.Content().readUnsignedByte();
                                                int i12 = localCommand.Content().readInt();
                                                localCommand.Content().readUnsignedByte();
                                                int i13 = localCommand.Content().readInt();
                                                localCommand.Content().readUnsignedByte();
                                                int i14 = localCommand.Content().readInt();
                                                localCommand.Content().readUnsignedByte();
                                                String str8 = localCommand.Content().readStringASCII();
                                                ((SumoTLSLogic)localObject4).add(new SumoTLSPhase(i12, i13, i14, str8));
                                            }
                                            localObject1 = localObject4;
                                        }
                                    }
                                    else
                                    {
                                        int i5;
                                        if (sc.input2 == 51)
                                        {
                                            localCommand.Content().readUnsignedByte();
                                            localCommand.Content().readInt();
                                            m = localCommand.Content().readInt();
                                            SumoLinkList localSumoLinkList = new SumoLinkList();
                                            for (i5 = 0; i5 < m; i5++)
                                            {
                                                localCommand.Content().readUnsignedByte();
                                                String str2 = localCommand.Content().readStringASCII();
                                                localCommand.Content().readUnsignedByte();
                                                String str3 = localCommand.Content().readStringASCII();
                                                localCommand.Content().readUnsignedByte();
                                                i9 = (byte)localCommand.Content().readUnsignedByte();
                                                localCommand.Content().readUnsignedByte();
                                                byte b = (byte)localCommand.Content().readUnsignedByte();
                                                localCommand.Content().readUnsignedByte();
                                                i10 = (byte)localCommand.Content().readUnsignedByte();
                                                localCommand.Content().readUnsignedByte();
                                                String str6 = localCommand.Content().readStringASCII();
                                                localCommand.Content().readUnsignedByte();
                                                String str7 = localCommand.Content().readStringASCII();
                                                localCommand.Content().readUnsignedByte();
                                                double d9 = localCommand.Content().readDouble();
                                                localSumoLinkList.add(new SumoLink(str2, str3, (byte)i9, b, (byte)i10, d9, str6, str7)); //CUIDADO
                                            }
                                            localObject1 = localSumoLinkList;
                                        }
                                        else
                                        {
                                            m = localCommand.Content().readInt();
                                            Object[] localObject5 = new Object[m];
                                            for (i3 = 0; i3 < m; i3++)
                                            {
                                                i5 = localCommand.Content().readUnsignedByte();
                                                localObject5[i3] = get_value(i5, localCommand);
                                            }
                                            localObject1 = localObject5;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                int j;
                                if (sc.output_type == 6)
                                {
                                    j = localCommand.Content().readUnsignedByte();
                                    SumoGeometry localSumoGeometry = new SumoGeometry();
                                    for (i3 = 0; i3 < j; i3++)
                                    {
                                        double d5 = Convert.ToDouble((Double)get_value(11, localCommand));
                                        double d7 = Convert.ToDouble((Double)get_value(11, localCommand));
                                        localSumoGeometry.add(new SumoPosition2D(d5, d7));
                                    }
                                    localObject1 = localSumoGeometry;
                                }
                                else if (sc.output_type == 17)
                                {
                                    j = localCommand.Content().readUnsignedByte();
                                    int n = localCommand.Content().readUnsignedByte();
                                    i3 = localCommand.Content().readUnsignedByte();
                                    int i6 = localCommand.Content().readUnsignedByte();
                                    localObject1 = new SumoColor(j, n, i3, i6);
                                }
                                else if (sc.output_type == 7)
                                {
                                    localObject1 = Convert.ToInt16(localCommand.Content().readUnsignedByte());
                                }
                            }
                        }
                    }
                }
            }
            return(localObject1);
        }
Esempio n. 19
0
        public virtual Object Do_job_get(SumoCommand sc)
        {
            lock (this)
            {
                Object            output = null;
                ResponseContainer rc     = QueryAndVerifySingle(sc.cmd);
                Command           resp   = rc.GetResponse();
                VerifyGetVarResponse(resp, sc.response, sc.input2, sc.input3);
                Verify("", sc.output_type, (int)resp.Content().ReadUnsignedByte());
                if (sc.output_type == Constants.TYPE_INTEGER)
                {
                    output = resp.Content().ReadInt();
                }
                else if (sc.output_type == Constants.TYPE_DOUBLE)
                {
                    output = resp.Content().ReadDouble();
                }
                else if (sc.output_type == Constants.TYPE_STRING)
                {
                    output = resp.Content().ReadStringUTF8();
                }
                else if (sc.output_type == Constants.POSITION_2D)
                {
                    double x = resp.Content().ReadDouble();
                    double y = resp.Content().ReadDouble();
                    output = new SumoPosition2D(x, y);
                }
                else if (sc.output_type == Constants.POSITION_3D)
                {
                    double x = resp.Content().ReadDouble();
                    double y = resp.Content().ReadDouble();
                    double z = resp.Content().ReadDouble();
                    output = new SumoPosition3D(x, y, z);
                }
                else if (sc.output_type == Constants.TYPE_STRINGLIST)
                {
                    SumoStringList ssl    = new SumoStringList();
                    int            laenge = resp.Content().ReadInt();
                    for (int i = 0; i < laenge; i++)
                    {
                        ssl.Add(resp.Content().ReadStringASCII());
                    }

                    output = ssl;
                }
                else if (sc.output_type == Constants.TYPE_BOUNDINGBOX)
                {
                    double min_x = resp.Content().ReadDouble();
                    double min_y = resp.Content().ReadDouble();
                    double max_x = resp.Content().ReadDouble();
                    double max_y = resp.Content().ReadDouble();
                    output = new SumoBoundingBox(min_x, min_y, max_x, max_y);
                }
                else if (sc.output_type == Constants.TYPE_COMPOUND)
                {
                    Object[] obj = null;
                    if (sc.input2 == Constants.TL_CONTROLLED_LINKS)
                    {
                        SumoLinkList sll = new SumoLinkList();
                        resp.Content().ReadUnsignedByte();
                        resp.Content().ReadInt();
                        int laenge = resp.Content().ReadInt();
                        obj = new StringList[laenge];
                        for (int i = 0; i < laenge; i++)
                        {
                            resp.Content().ReadUnsignedByte();
                            int anzahl = resp.Content().ReadInt();
                            for (int i1 = 0; i1 < anzahl; i1++)
                            {
                                resp.Content().ReadUnsignedByte();
                                resp.Content().ReadInt();
                                string from = resp.Content().ReadStringASCII();
                                string to   = resp.Content().ReadStringASCII();
                                string over = resp.Content().ReadStringASCII();
                                sll.Add(new SumoLink(from, to, over));
                            }
                        }

                        output = sll;
                    }
                    else if (sc.input2 == Constants.TL_COMPLETE_DEFINITION_RYG)
                    {
                        resp.Content().ReadUnsignedByte();
                        resp.Content().ReadInt();
                        int length = resp.Content().ReadInt();
                        for (int i = 0; i < length; i++)
                        {
                            resp.Content().ReadUnsignedByte();
                            string subID = resp.Content().ReadStringASCII();
                            resp.Content().ReadUnsignedByte();
                            int type = resp.Content().ReadInt();
                            resp.Content().ReadUnsignedByte();
                            int subParameter = resp.Content().ReadInt();
                            resp.Content().ReadUnsignedByte();
                            int          currentPhaseIndex = resp.Content().ReadInt();
                            SumoTLSLogic stl = new SumoTLSLogic(subID, type, subParameter, currentPhaseIndex);
                            resp.Content().ReadUnsignedByte();
                            int nbPhases = resp.Content().ReadInt();
                            for (int i1 = 0; i1 < nbPhases; i1++)
                            {
                                resp.Content().ReadUnsignedByte();
                                int duration = resp.Content().ReadInt();
                                resp.Content().ReadUnsignedByte();
                                int duration1 = resp.Content().ReadInt();
                                resp.Content().ReadUnsignedByte();
                                int duration2 = resp.Content().ReadInt();
                                resp.Content().ReadUnsignedByte();
                                string phaseDef = resp.Content().ReadStringASCII();
                                stl.Add(new SumoTLSPhase(duration, duration1, duration2, phaseDef));
                            }

                            output = stl;
                        }
                    }
                    else if (sc.input2 == Constants.LANE_LINKS)
                    {
                        resp.Content().ReadUnsignedByte();
                        resp.Content().ReadInt();
                        int          length = resp.Content().ReadInt();
                        SumoLinkList links  = new SumoLinkList();
                        for (int i = 0; i < length; i++)
                        {
                            resp.Content().ReadUnsignedByte();
                            string notInternalLane = resp.Content().ReadStringASCII();
                            resp.Content().ReadUnsignedByte();
                            string internalLane = resp.Content().ReadStringASCII();
                            resp.Content().ReadUnsignedByte();
                            byte hasPriority = (byte)resp.Content().ReadUnsignedByte();
                            resp.Content().ReadUnsignedByte();
                            byte isOpened = (byte)resp.Content().ReadUnsignedByte();
                            resp.Content().ReadUnsignedByte();
                            byte hasFoes = (byte)resp.Content().ReadUnsignedByte();
                            resp.Content().ReadUnsignedByte();
                            string state = resp.Content().ReadStringASCII();
                            resp.Content().ReadUnsignedByte();
                            string direction = resp.Content().ReadStringASCII();
                            resp.Content().ReadUnsignedByte();
                            double laneLength = resp.Content().ReadDouble();
                            links.Add(new SumoLink(notInternalLane, internalLane, hasPriority, isOpened, hasFoes, laneLength, state, direction));
                        }

                        output = links;
                    }
                    else
                    {
                        int laenge = resp.Content().ReadInt();
                        obj = new Object[laenge];
                        for (int i = 0; i < laenge; i++)
                        {
                            int k = resp.Content().ReadUnsignedByte();
                            obj[i] = this.Get_value(k, resp);
                        }

                        output = obj;
                    }
                }
                else if (sc.output_type == Constants.TYPE_POLYGON)
                {
                    int          laenge = resp.Content().ReadUnsignedByte();
                    SumoGeometry sg     = new SumoGeometry();
                    for (int i = 0; i < laenge; i++)
                    {
                        double x = (Double)this.Get_value(Constants.TYPE_DOUBLE, resp);
                        double y = (Double)this.Get_value(Constants.TYPE_DOUBLE, resp);
                        sg.Add(new SumoPosition2D(x, y));
                    }

                    output = sg;
                }
                else if (sc.output_type == Constants.TYPE_COLOR)
                {
                    int r = resp.Content().ReadUnsignedByte();
                    int g = resp.Content().ReadUnsignedByte();
                    int b = resp.Content().ReadUnsignedByte();
                    int a = resp.Content().ReadUnsignedByte();
                    output = new SumoColor(r, g, b, a);
                }
                else if (sc.output_type == Constants.TYPE_UBYTE)
                {
                    output = resp.Content().ReadUnsignedByte();
                }

                return(output);
            }
        }
Esempio n. 20
0
 public static SumoCommand SetShape(string polygonID, SumoStringList shape)
 {
     return(new SumoCommand(Constants.CMD_SET_POLYGON_VARIABLE, Constants.VAR_SHAPE, polygonID, shape));
 }
Esempio n. 21
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();
    }
Esempio n. 22
0
 public SumoCommand(Object commandID, Object paramObject2, Object paramObject3, Object[] array)
 {
     this.cmd    = new Command((Convert.ToInt32(commandID)));
     this.input1 = Convert.ToInt32(commandID);
     this.input2 = Convert.ToInt32(paramObject2);
     this.cmd.Content().writeUnsignedByte((Convert.ToInt32(paramObject2)));
     this.cmd.Content().writeStringASCII(Convert.ToString(paramObject3));
     if (Convert.ToInt32(paramObject2) == 69)
     {
         this.cmd.Content().writeUnsignedByte(17);
         for (int i = 0; i < array.Length; i++)
         {
             add_variable(array[i]);
         }
     }
     else if (Convert.ToInt32(paramObject2) == 87)
     {
         this.cmd.Content().writeUnsignedByte(14);
         SumoStringList localSumoStringList = (SumoStringList)array[0];
         this.cmd.Content().writeInt(localSumoStringList.Count);
         IEnumerator <String> localIterator = localSumoStringList.GetEnumerator();
         while (localIterator.MoveNext())
         {
             String str = (String)localIterator.Current;
             this.cmd.Content().writeStringASCII(str);
         }
     }
     else if (((Convert.ToInt32(paramObject2) == 145) || Convert.ToInt32(paramObject2) == 144) || (Convert.ToInt32(paramObject2) == 25))
     {
         this.cmd.Content().writeUnsignedByte(15);
         this.cmd.Content().writeInt(0);
     }
     else
     {
         int j;
         if (Convert.ToInt32(paramObject2) == 163)
         {
             this.cmd.Content().writeUnsignedByte(5);
             for (j = 0; j < array.Length; j++)
             {
                 add_variable(array[j]);
             }
         }
         else if (Convert.ToInt32(paramObject2) == 161)
         {
             this.cmd.Content().writeUnsignedByte(1);
             for (j = 0; j < array.Length; j++)
             {
                 add_variable(array[j]);
             }
         }
         else if ((Convert.ToInt32(commandID) == 200) && (Convert.ToInt32(paramObject2) == 128))
         {
             this.cmd.Content().writeUnsignedByte(15);
             this.cmd.Content().writeInt(5);
             add_type(array[3]);
             add_variable(array[3]);
             add_type(array[1]);
             add_variable(array[1]);
             add_type(array[2]);
             add_variable(array[2]);
             add_type(array[4]);
             add_variable(array[4]);
             add_type(array[0]);
             add_variable(array[0]);
         }
         else if ((Convert.ToInt32(commandID) == 199) && (Convert.ToInt32(paramObject2) == 66))
         {
             this.cmd.Content().writeUnsignedByte(1);
             add_variable(array[0]);
             add_variable(array[1]);
         }
         else if ((Convert.ToInt32(commandID) == 199) && (Convert.ToInt32(paramObject2) == 128))
         {
             this.cmd.Content().writeUnsignedByte(15);
             this.cmd.Content().writeInt(4);
             add_type(array[3]);
             add_variable(array[3]);
             add_type(array[2]);
             add_variable(array[2]);
             add_type(array[4]);
             add_variable(array[4]);
             this.cmd.Content().writeUnsignedByte(1);
             add_variable(array[0]);
             add_variable(array[1]);
         }
         else
         {
             this.cmd.Content().writeUnsignedByte(15);
             this.cmd.Content().writeInt(array.Length);
             for (j = 0; j < array.Length; j++)
             {
                 add_type(array[j]);
                 add_variable(array[j]);
             }
         }
     }
     this.raw = new List <Object>();
     this.raw.Add(commandID);
     this.raw.Add(paramObject2);
     this.raw.Add(paramObject3);
     this.raw.Add(array);
 }
Esempio n. 23
0
 public static SumoCommand setRoute(String vehID, SumoStringList edgeList)
 {
     Object[] arrayOfObject = { edgeList };
     return(new SumoCommand(Convert.ToInt32(196), Convert.ToInt32(87), vehID, arrayOfObject));
 }