Exemplo n.º 1
0
 public AllData(RelayCannonsData cannons, FansData fans, CrafterData crafters, ItemObjectsData items, MinersData miners, OreData ores, InventoryData invents, UnPackagerData unPacks,
                PackagerData packs, EggData eggs, SplitterData splits, PumpsData pumps, ZapTowerData zaps, RocketData rock)
 {
     cannon  = cannons;
     fan     = fans;
     crafter = crafters;
     item    = items;
     miner   = miners;
     ore     = ores;
     invent  = invents;
     unPack  = unPacks;
     pack    = packs;
     egg     = eggs;
     split   = splits;
     pump    = pumps;
     zap     = zaps;
     roc     = rock;
 }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        RocketData d = ArduinoReceiver2020.instance.latestData;

        if (d != null)
        {
            rocketPart.batteryLevel = ArduinoReceiver2020.instance.latestData.GetFloatValue(batteryLevelSource);
            rocketPart.temperature  = ArduinoReceiver2020.instance.latestData.GetFloatValue(temperatureSource);
        }
        else
        {
            rocketPart.batteryLevel = 0;
            rocketPart.temperature  = 0;
        }
        // rocketPart.batteryLevel = ArduinoReciever.GetValue(batteryLevelSource);
        // rocketPart.temperature = ArduinoReciever.GetValue(temperatureSource);
        rocketPart.minMaxTemperatures = temperatureBounds;
    }
    private void UpdateBuffs()
    {
        RocketData rd = GameDataManager.instance.rocketData[selectedRocket];

        float engineBonus    = GameDataManager.instance.GetEngineBonus(selectedRocket) * 100f;
        float sheathingBonus = GameDataManager.instance.GetSheathingBonus(selectedRocket) * 100f;
        float frameBonus     = GameDataManager.instance.GetFrameBonus(selectedRocket) * 100f;

        enginePercent.text    = "- " + engineBonus.ToString() + "%";
        sheathingPercent.text = "+ " + sheathingBonus.ToString() + "%";
        framePercent.text     = "+ " + frameBonus.ToString() + "%";

        foreach (Transform child in engineTitle)
        {
            Destroy(child.gameObject);
        }

        foreach (Transform child in sheathingTitle)
        {
            Destroy(child.gameObject);
        }

        foreach (Transform child in frameTitle)
        {
            Destroy(child.gameObject);
        }

        for (int i = 0; i < rd.engineLevel; i++)
        {
            GameObject icon = Instantiate(engineIcon, engineTitle);
            icon.GetComponent <RectTransform>().Translate(new Vector3(icon.GetComponent <RectTransform>().localScale.x * 1.25f * i, 0f, 0f));
        }
        for (int i = 0; i < rd.sheathingLevel; i++)
        {
            GameObject icon = Instantiate(sheathingIcon, sheathingTitle);
            icon.GetComponent <RectTransform>().Translate(new Vector3(icon.GetComponent <RectTransform>().localScale.x * 1.25f * i, 0f, 0f));
        }
        for (int i = 0; i < rd.frameLevel; i++)
        {
            GameObject icon = Instantiate(frameIcon, frameTitle);
            icon.GetComponent <RectTransform>().Translate(new Vector3(icon.GetComponent <RectTransform>().localScale.x * 1.25f * i, 0f, 0f));
        }
    }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        _titleLabel.text = _title;


        if (dataSource != "inherit")
        {
            RocketData d = ArduinoReceiver2020.instance.latestData;
            if (d != null)
            {
                _value = d.GetFloatValue(dataSource).ToString();
            }
            else
            {
                _value = "NULL";
            }
        }
        _valueLabel.text = _value + _suffix;
    }
    void SerialLoop()
    {
        Debug.Log("Hello from the other thread!");
        // Open the serial port
        // TODO: re add support for setting baud rate and serial port
        serialPort              = new SerialPort("/dev/cu.usbserial-AK06RGGT", 57600);
        serialPort.ReadTimeout  = 50;
        serialPort.WriteTimeout = 0;
        serialPort.Parity       = Parity.None;
        serialPort.DataBits     = 8;
        serialPort.StopBits     = StopBits.One;
        serialPort.DtrEnable    = true;
        serialPort.RtsEnable    = true;
        //serialPort.Handshake = Handshake.None;
        serialPort.Encoding = System.Text.Encoding.BigEndianUnicode;
        try
        {
            Debug.Log("Gonna try to open the serial port...");
            serialPort.Open();
            Debug.Log("Success! I think?");
        }
        catch (IOException e)
        {
            Debug.LogError("Not opened");
            return;
        }


        // reading loop
        while (ThreadIsLooping())
        {
            Debug.Log("get new rocket data...");
            RocketData newRocketData = ReadRocketData();
            outputQueue.Enqueue(newRocketData);
        }

        Debug.Log("Broken out of thread loop");
        serialPort.Close();
        Debug.Log("Serial port has been closed :)");
    }
Exemplo n.º 6
0
    // Update is called once per frame
    void Update()
    {
        RocketData latestData = ArduinoReceiver2020.instance.latestData;

        if (latestData == null)
        {
            return;
        }

        Vector3 gps = latestData.position;

        // Calculates the distance and heading to the rocket
        targetPosition = new Vector2(gps.x, gps.y);
        Vector2 rocketPosition   = targetPosition;
        float   distanceToRocket = GlobeMath.Haversine(ourPosition, rocketPosition);
        float   bearingToRocket  = GlobeMath.BearingToPoint(ourPosition, rocketPosition);

        distanceItem.Value = distanceToRocket.ToString("F1");
        bearingItem.Value  = bearingToRocket.ToString("F1");

        overheadMap.UpdateMap(new Mapbox.Utils.Vector2d(gps.x, gps.y));
    }
    public void BuyRocket()
    {
        RocketData rd = GameDataManager.instance.rocketData[selectedRocket];

        if (GameDataManager.instance.ConsumeMetal(rd.price))
        {
            mt.DisplayMessage(
                LocalizationManager.instance.GetLocalizedValue("hangar_rocket_purchase_1") +
                LocalizationManager.instance.GetLocalizedValue("rocket_" + (selectedRocket + 1).ToString() + "_title") +
                LocalizationManager.instance.GetLocalizedValue("hangar_rocket_purchase_2"),
                3f,
                MessageText.ScreenPosition.TOP
                );

            rd.purchased = true;

            buyButton.interactable    = false;
            selectButton.interactable = true;
        }
        else
        {
            mt.DisplayMessage(LocalizationManager.instance.GetLocalizedValue("hangar_not_enough_metal"), MessageText.ScreenPosition.TOP);
        }
    }
    public void UpdateUpgradeInfo(int upgID)
    {
        selectedUpgrade = upgID;

        int   level     = 0;
        float oldBonus  = 0.0f;
        float newBonus  = 0.0f;
        int   resPerUpg = 0;

        RocketData rd = GameDataManager.instance.rocketData[selectedRocket];

        switch (upgID)
        {
        case 1:     // Engine
            level     = rd.engineLevel;
            oldBonus  = GameDataManager.instance.GetEngineBonus(selectedRocket) * 100f;
            newBonus  = GameDataManager.instance.GetEngineBonus(selectedRocket, rd.engineLevel + 1) * 100f;
            resPerUpg = GameDataManager.instance.resPerEngineUpg;

            upgradeTitle.text = LocalizationManager.instance.GetLocalizedValue("hangar_engine_upg_question");
            upgradeLevel.text = LocalizationManager.instance.GetLocalizedValue("hangar_current_upgrade") +
                                (rd.engineLevel < 5 ? rd.engineLevel.ToString() : LocalizationManager.instance.GetLocalizedValue("hangar_maximum_upgrade"));
            upgradeDescription.text = LocalizationManager.instance.GetLocalizedValue("hangar_engine_upg_description");

            if (rd.engineLevel >= GameDataManager.instance.maxRocketUpgradeLevel)
            {
                agreeBtn.interactable = false;
                upgradePrice.text     = LocalizationManager.instance.GetLocalizedValue("hangar_maximum_upgrade");
            }

            break;

        case 2:     // Sheathing
            level     = rd.sheathingLevel;
            oldBonus  = GameDataManager.instance.GetSheathingBonus(selectedRocket) * 100f;
            newBonus  = GameDataManager.instance.GetSheathingBonus(selectedRocket, rd.sheathingLevel + 1) * 100f;
            resPerUpg = GameDataManager.instance.resPerSheathingUpg;

            upgradeTitle.text = LocalizationManager.instance.GetLocalizedValue("hangar_sheathing_upg_question");
            upgradeLevel.text = LocalizationManager.instance.GetLocalizedValue("hangar_current_upgrade") +
                                (rd.sheathingLevel < 5 ? rd.sheathingLevel.ToString() : LocalizationManager.instance.GetLocalizedValue("hangar_maximum_upgrade"));
            upgradeDescription.text = LocalizationManager.instance.GetLocalizedValue("hangar_sheathing_upg_description");

            if (rd.sheathingLevel >= GameDataManager.instance.maxRocketUpgradeLevel)
            {
                agreeBtn.interactable = false;
                upgradePrice.text     = LocalizationManager.instance.GetLocalizedValue("hangar_maximum_upgrade");
            }

            break;

        case 3:     // Frame
            level     = rd.frameLevel;
            oldBonus  = GameDataManager.instance.GetFrameBonus(selectedRocket) * 100f;
            newBonus  = GameDataManager.instance.GetFrameBonus(selectedRocket, rd.frameLevel + 1) * 100f;
            resPerUpg = GameDataManager.instance.resPerFrameUpg;

            upgradeTitle.text = LocalizationManager.instance.GetLocalizedValue("hangar_frame_upg_question");
            upgradeLevel.text = LocalizationManager.instance.GetLocalizedValue("hangar_current_upgrade") +
                                (rd.frameLevel < 5 ? rd.frameLevel.ToString() : LocalizationManager.instance.GetLocalizedValue("hangar_maximum_upgrade"));
            upgradeDescription.text = LocalizationManager.instance.GetLocalizedValue("hangar_frame_upg_description");

            if (rd.frameLevel >= GameDataManager.instance.maxRocketUpgradeLevel)
            {
                agreeBtn.interactable = false;
                upgradePrice.text     = LocalizationManager.instance.GetLocalizedValue("hangar_maximum_upgrade");
            }

            break;
        }

        upgradeImage.sprite = upgradeSprites[upgID - 1];

        upgradePrice.text   = ((level + selectedRocket + 1) * resPerUpg).ToString();
        upgradeOldBuff.text = (upgID == 1 ? "- " : "+ ") + oldBonus.ToString() + "%";
        upgradeNewBuff.text = (upgID == 1 ? "- " : "+ ") + newBonus.ToString() + "%";
    }
Exemplo n.º 9
0
 void ISetupRocket.RocketData(RocketData rocketData)
 {
     this.rocketData = rocketData;
 }
    RocketData ReadRocketData()
    {
        RocketData newData = new RocketData();

        try
        {
            // READ ROCKET DATA

            byte[] buf = new byte[lengthOfData];

            serialPort.Read(buf, 0, lengthOfData);

            Stream stream = new MemoryStream(buf);
            reader = new BinaryReader(stream, Encoding.GetEncoding("iso-8859-1"));


            // Start marker "STR"
            char[] startMarker = reader.ReadChars(3);

            // Confirm that start marker is correct
            if (new string(startMarker) != "STR")
            {
                Debug.LogErrorFormat("Error - Expected start marker was \"STR\", got \"{0}\"", startMarker);
            }

            // We made it here, so let's get rocket data
            // First is the GPS coordinates
            Vector3 gps = new Vector3(ReadDoubleAsFloat(), ReadDoubleAsFloat(), ReadDoubleAsFloat());

            // Next is acceleration
            Vector3 accel = new Vector3(ReadDoubleAsFloat(), ReadDoubleAsFloat(), ReadDoubleAsFloat());

            // Rotation
            Quaternion rot = new Quaternion(ReadDoubleAsFloat(), ReadDoubleAsFloat(), ReadDoubleAsFloat(), ReadDoubleAsFloat());

            // and all the other stuff
            double aaAngle = ReadDoubleAsFloat();

            double tPayload  = ReadDoubleAsFloat();
            double tAvionics = ReadDoubleAsFloat();
            double tAmbient  = ReadDoubleAsFloat();

            bool parachuteOut = reader.ReadBoolean();

            double bPayload   = ReadDoubleAsFloat();
            double bAvionics  = ReadDoubleAsFloat();
            double bAirbrakes = ReadDoubleAsFloat();

            uint            sentEpochTime = reader.ReadUInt32();
            System.DateTime sentTime      = UnixTime(sentEpochTime);

            // Now let's package this all into the RocketData object
            newData.position          = gps;
            newData.acceleration      = accel;
            newData.rotation          = rot;
            newData.airbrakesAngle    = aaAngle;
            newData.payloadTemp       = tPayload;
            newData.avionicsTemp      = tAvionics;
            newData.ambientTemp       = tAmbient;
            newData.parachuteDeployed = parachuteOut;
            newData.payloadBattery    = bPayload;
            newData.avionicsBattery   = bAvionics;
            newData.airbrakesBattery  = bAirbrakes;
            newData.sentTime          = sentTime;
            newData.receivedTime      = System.DateTime.Now;
            newData.status            = RocketDataStatus.Success;
        }

        catch (System.TimeoutException e)
        {
            Debug.Log("timed out");
            newData.status = RocketDataStatus.Error;
        }
        return(newData);
    }
Exemplo n.º 11
0
 private void CreateRocketDataObject()
 {
     rocketInfo = new RocketData();
 }
Exemplo n.º 12
0
        //sample message format
        //$3:0.706,0,-3,-1,21.74,961.71,-96,-32,7856,4104.5615,N,08130.8343,W
        public static RocketData ParseData(string message)
        {
            var data = message.Split(',');
            var time = data[0].TrimStart(new char[] { '$' });

            if (!int.TryParse(time.Split(':')[0], out int Min))
            {
                Min = 0;
            }

            time = time.Split(':')[1];

            if (!int.TryParse(time.Split('.')[0], out int Sec))
            {
                Sec = 0;
            }

            if (!int.TryParse(time.Split('.')[1], out int Msec))
            {
                Msec = 0;
            }

            //TODO: check if the length is long enough
            if (!double.TryParse(data[9], out double Lat))
            {
                Lat = 0;
            }

            if (!char.TryParse(data[10], out char LatHemi))
            {
                LatHemi = '\0';
            }

            if (!double.TryParse(data[11], out double Long))
            {
                Long = 0;
            }

            if (!char.TryParse(data[12], out char LongHemi))
            {
                LongHemi = '\0';
            }

            if (!double.TryParse(data[13], out double gLat))
            {
                Lat = 0;
            }

            if (!char.TryParse(data[14], out char gLatHemi))
            {
                LatHemi = '\0';
            }

            if (!double.TryParse(data[15], out double gLong))
            {
                Long = 0;
            }

            if (!char.TryParse(data[16], out char gLongHemi))
            {
                LongHemi = '\0';
            }

            //we can ignore the other data for this application

            RocketData parsedData = new RocketData(Min, Sec, Msec, Lat, LatHemi, Long, LongHemi, gLat, gLatHemi, gLong, gLongHemi);

            return(parsedData);
        }
Exemplo n.º 13
0
        //sample message format
        //$3:0.706,0,-3,-1,21.74,961.71,-96,-32,7856,4104.5615,N,08130.8343,W
        public static RocketData ParseData(string message)
        {
            var data = message.Split(',');
            var time = data[0].TrimStart(new char[] { '$' });

            if (!int.TryParse(time.Split(':')[0], out int Min))
            {
                Min = 0;
            }

            time = time.Split(':')[1];

            if (!int.TryParse(time.Split('.')[0], out int Sec))
            {
                Sec = 0;
            }

            if (!int.TryParse(time.Split('.')[1], out int Msec))
            {
                Msec = 0;
            }

            if (!int.TryParse(data[1], out int GyroX))
            {
                GyroX = 0;
            }

            if (!int.TryParse(data[2], out int GyroY))
            {
                GyroY = 0;
            }

            if (!int.TryParse(data[3], out int GyroZ))
            {
                GyroZ = 0;
            }

            if (!double.TryParse(data[4], out double Temp))
            {
                Temp = 0.0;
            }

            if (!double.TryParse(data[5], out double Pressure))
            {
                Pressure = 0.0;
            }

            if (!int.TryParse(data[6], out int AccelX))
            {
                AccelX = 0;
            }

            if (!int.TryParse(data[7], out int AccelY))
            {
                AccelY = 0;
            }

            if (!int.TryParse(data[8], out int AccelZ))
            {
                AccelZ = 0;
            }

            //we can ignore the gps data for this application

            RocketData parsedData = new RocketData(Min, Sec, Msec, GyroX, GyroY, GyroZ, Pressure, Temp, AccelX, AccelY, AccelZ);

            return(parsedData);
        }
Exemplo n.º 14
0
        private static void Update()
        {
            while (true)
            {
                if (_selectedPath != String.Empty)
                {
                    tempPlot.Series[0] = new LineSeries {
                        LineStyle = LineStyle.Solid
                    };                                                                  //Remove old data
                    pressurePlot.Series[0] = new LineSeries {
                        LineStyle = LineStyle.Solid
                    };
                    altPlot.Series[0] = new LineSeries {
                        LineStyle = LineStyle.Solid
                    };
                    accelXPlot.Series[0] = new LineSeries {
                        LineStyle = LineStyle.Solid
                    };
                    //accelYPlot.Series[0] = new LineSeries { LineStyle = LineStyle.Solid };
                    //accelZPlot.Series[0] = new LineSeries { LineStyle = LineStyle.Solid };

                    var wh  = new AutoResetEvent(false);
                    var fsw = new FileSystemWatcher(".");
                    fsw.Filter = _selectedPath;
                    fsw.EnableRaisingEvents = true;
                    fsw.Changed            += (s, e) => wh.Set();
                    _continue = true;

                    var fs = new FileStream(_selectedPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                    using (var sr = new StreamReader(fs))
                    {
                        var message = "";
                        while (_continue)
                        {
                            message = sr.ReadLine();
                            if (message != null && message[0] == '$')
                            {
                                RocketData rd             = MainViewModel.ParseData(message);
                                var        tempSeries     = (LineSeries)tempPlot.Series[0];
                                var        pressureSeries = (LineSeries)pressurePlot.Series[0];
                                var        altitudeSeries = (LineSeries)altPlot.Series[0];
                                var        accelXSeries   = (LineSeries)accelXPlot.Series[0];
                                //var accelYSeries = (LineSeries)accelYPlot.Series[0];
                                //var accelZSeries = (LineSeries)accelZPlot.Series[0];

                                int milliseconds = rd.Min * 60 + rd.Sec + rd.Msec / 1000;

                                count++;

                                tempSum     += rd.Temp;
                                pressureSum += rd.Pressure;

                                //h - meters
                                //p - pressure at altitude (need units in inHg)
                                double pressureHg = rd.Pressure * 0.02952998751; //convert mBar to inHg

                                if (P0 == 0)
                                {
                                    P0 = pressureHg; //set first reference pressure
                                }
                                //P0 is the pressure at the reference level h0
                                //double P0 = 29.6; // inHg
                                //double h0 = 307.848; //meters % Akron
                                double h0 = 0; //TODO: try detecting altitude change for now
                                //convert C to Kelvin
                                //T = Temperature at altitude h(need units in Kelvin)
                                double tempKelvin = rd.Temp + 273.15;

                                const double g = 9.80665;   //m / s ^ 2(Gravitational Acceleration Due To Earth)
                                const double M = 0.0289644; //kg / mol % M is the molar mass of Air
                                const double R = 8.31432;   //N * m / (mol * K) % Univeral Gas Constant

                                //Barometric Formula:
                                //P = P0 * exp(-g * M * (h - h0) / (R * tempKelvin));

                                double h = 0;
                                if (P0 != 0 && pressureHg / P0 > 0) //TODO: I think this can only pick up on altitude changes....
                                {
                                    h = ((Math.Log(pressureHg / P0)) * (R * tempKelvin) / (-g * M)) * 3.28084 + h0;
                                }

                                tempSeries.Points.Add(new DataPoint(milliseconds, rd.Temp));
                                tempPlot.Series[0] = tempSeries;

                                pressureSeries.Points.Add(new DataPoint(milliseconds, rd.Pressure));
                                pressurePlot.Series[0] = pressureSeries;

                                altitudeSeries.Points.Add(new DataPoint(milliseconds, h)); //convert to feet
                                altPlot.Series[0] = altitudeSeries;

                                accelXSeries.Points.Add(new DataPoint(milliseconds, rd.AccelX));
                                accelXPlot.Series[0] = accelXSeries;

                                //accelYSeries.Points.Add(new DataPoint(milliseconds, rd.AccelY));
                                //accelYPlot.Series[0] = accelYSeries;

                                //accelZSeries.Points.Add(new DataPoint(milliseconds, rd.AccelZ));
                                //accelZPlot.Series[0] = accelZSeries;

                                if (h > maxAlt)
                                {
                                    maxAlt = h;
                                }
                            }
                            else
                            {
                                wh.WaitOne(1000);
                            }
                        }
                    }
                    wh.Close();
                }
            }
        }