Exemplo n.º 1
0
 private void OnInputReceived(float input1, float input2)
 {
     if (!useController)
     {
         lastInput1 = input1;
         lastInput2 = input2;
         float normalizedInput1 = CalibrationSettings.GetNormalizedValue(Side.Left, input1);
         float normalizedInput2 = CalibrationSettings.GetNormalizedValue(Side.Right, input2);
         lastNormalizedInput1 = normalizedInput1;
         lastNormalizedInput2 = normalizedInput2;
         //Open/Close
         Squeezing(normalizedInput1, normalizedInput2);
     }
 }
Exemplo n.º 2
0
 public void onIPSConnected(NetMQMessage m)
 {
     index = 0;
     CalibrationSettings.ClearAnchorData();
     //UnityEngine.Debug.Log("onIPSConnected");
     //Only start receiving IPS data if the the user is in the calibration (normal claibration of anchors) or in the tags configuration scene(use last configuration)
     if (GeneralSceneManager.sceneState != GeneralSceneManager.SceneState.Calibration && GeneralSceneManager.sceneState != GeneralSceneManager.SceneState.TagsConfiguration)
     {
         return;
     }
     if (!clientUnity.client.SendCommand((byte)Modules.POSITIONING_MODULE, (byte)PositioningCommandType.IPS_DISCOVER))
     {
         UnityEngine.Debug.Log("Error. Could not send IPS_UPDATE_SETTINGS command to the server. Check the log for more information");
     }
 }
Exemplo n.º 3
0
        private void Calibrate()
        {
            CalibrationCorners[] samples =
                _viewModel.Samples.Where(_ => _.IsCornersInitialized).Select(_ => _.Corners).ToArray();
            var settings = new CalibrationSettings
            {
                ChessboardHeight = _viewModel.ChessboardHeight,
                ChessboardWidth  = _viewModel.ChessboardWidth,
                CellHeight       = _viewModel.CellHeight,
                CellWidth        = _viewModel.CellWidth,
                Count            = _viewModel.Samples.Count(_ => _.IsCornersInitialized),
                ImageSize        = _viewModel.Samples[0].StereoImage.LeftImage.Size
            };

            _viewModel.CalibrationResult = StereoCalibration.Calibrate(settings, samples);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Processing loop, captures an image and processes it
        /// </summary>
        private void Application_Idle()
        {
            while (true)
            {
                try
                {
                    Image <Bgr, byte> tempFrame = captured_frame = CameraManager.GetImage();
                    if (CaptureSettings.Instance().DEFAULT_DILATATION != 0)
                    {
                        tempFrame._Dilate((int)CaptureSettings.Instance().DEFAULT_DILATATION);
                    }
                    if (CaptureSettings.Instance().DEFAULT_ERODE != 0)
                    {
                        tempFrame._Erode((int)CaptureSettings.Instance().DEFAULT_ERODE);
                    }
                    if (CaptureSettings.Instance().DEFAULT_GAMMA != 1)
                    {
                        tempFrame._GammaCorrect((double)CaptureSettings.Instance().DEFAULT_GAMMA);
                    }
                    if (CaptureSettings.Instance().DEFAULT_INVERT_ENABLED)
                    {
                        tempFrame._Not();
                    }
                    if (CaptureSettings.Instance().DEFAULT_NORMALIZE_ENABLED)
                    {
                        tempFrame._EqualizeHist();
                    }

                    // fix rotation
                    if (CalibrationSettings.Instance().CALIBRATION_ROTATION != 0)
                    {
                        tempFrame = tempFrame.Rotate(CalibrationSettings.Instance().CALIBRATION_ROTATION, new Bgr(0, 0, 0), true);
                    }

                    processor.ProcessImage(tempFrame);
                    if (interactiveWindow != null && interactiveWindow.IsVisible)
                    {
                        interactiveWindow.DrawImage(tempFrame, processor);
                    }
                    InputLogic();
                }
                catch {
                    // no-op here
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the HestonCalibrator class.
        /// </summary>
        /// <param name="parameters">Heston Model Parameters</param>
        /// <param name="marketOptions">Observed Option prices</param>
        /// <param name="calibrationSettings">Calibration settings</param>
        public HestonCalibrator(HestonModelParameters parameters,
                                LinkedList <OptionMarketData <EuropeanOption> > marketOptions,
                                CalibrationSettings calibrationSettings)
        {
            // Heston Model Params
            _RiskFreeRate      = parameters.RiskFreeRate;
            _InitialStockPrice = parameters.InitialStockPrice;

            // Copy market data
            marketOptionsList = new LinkedList <OptionMarketData <EuropeanOption> >(marketOptions);

            // Calibration Settings
            accuracy      = calibrationSettings.Accuracy;
            maxIterations = calibrationSettings.MaximumNumberOfIterations;

            // Set default guess parameters
            calibratedParams = parameters.CalibrationParamsToArray();
        }
Exemplo n.º 6
0
        public void Task_2_5()
        {
            // Variance Process Values
            double Kappa = 1.5768;
            double Theta = 0.398;
            double Sigma = 0.5751;
            double V0    = 0.0175;
            double Rho   = -0.5711;

            // Heston Model Params
            double InitialStockPrice = 100;
            double RiskFreeRate      = 0.025;

            // Callibration Settings
            double accuracy = 0.001;
            int    maxIter  = 1000;

            VarianceProcessParameters varParams =
                new VarianceProcessParameters(Kappa, Theta, Sigma, V0, Rho);

            HestonModelParameters hestonModel =
                new HestonModelParameters(InitialStockPrice, RiskFreeRate, varParams);

            CalibrationSettings calibrationSettings = new CalibrationSettings(accuracy, maxIter);

            // Market Data
            LinkedList <OptionMarketData <EuropeanOption> > observedOptions =
                new LinkedList <OptionMarketData <EuropeanOption> >();

            EuropeanOption eu1 = new EuropeanOption(80, PayoffType.Call, 1);
            OptionMarketData <EuropeanOption> marketData1 =
                new OptionMarketData <EuropeanOption>(eu1, 25.72);

            observedOptions.AddLast(marketData1);

            EuropeanOption eu2 = new EuropeanOption(90, PayoffType.Call, 1);
            OptionMarketData <EuropeanOption> marketData2 =
                new OptionMarketData <EuropeanOption>(eu2, 18.93);

            observedOptions.AddLast(marketData2);

            EuropeanOption eu3 = new EuropeanOption(80, PayoffType.Call, 2);
            OptionMarketData <EuropeanOption> marketData3 =
                new OptionMarketData <EuropeanOption>(eu3, 30.49);

            observedOptions.AddLast(marketData3);

            EuropeanOption eu4 = new EuropeanOption(100, PayoffType.Call, 2);
            OptionMarketData <EuropeanOption> marketData4 =
                new OptionMarketData <EuropeanOption>(eu4, 19.36);

            observedOptions.AddLast(marketData4);

            EuropeanOption eu5 = new EuropeanOption(100, PayoffType.Call, 1.5);
            OptionMarketData <EuropeanOption> marketData5 =
                new OptionMarketData <EuropeanOption>(eu5, 16.58);

            observedOptions.AddLast(marketData5);

            // Heston Calibrator
            HestonCalibrator calibrator = new HestonCalibrator(hestonModel, observedOptions, calibrationSettings);

            calibrator.Calibrate();

            double             error   = 0;
            CalibrationOutcome outcome = CalibrationOutcome.NotStarted;

            calibrator.GetCalibrationStatus(ref outcome, ref error);
            Console.WriteLine("Calibration outcome: {0} and error: {1}", outcome, error);
        }
Exemplo n.º 7
0
 public FlowControl(IDictionary <string, object> calibrationSettings)
     : this()
 {
     CalibrationSettings.Add(FlowControlGpioPinNumberSetting, (calibrationSettings.ContainsKey(FlowControlGpioPinNumberSetting)) ? calibrationSettings[FlowControlGpioPinNumberSetting] as string : "");
 }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a new CalibrationWindow.
        /// </summary>
        /// <param name="autoStart">Whether or not to automatically begin calibration.</param>
        /// <param name="autoSave">Whether or not to save the calibration settings using Extended Weak Reference.</param>
        public CalibrationWindow(bool autoStart, bool autoSave)
        {
            _autoStart = autoStart;
            _autoSave  = autoSave;

            Settings = new CalibrationSettings();

            Name      = "calibrationWindow";
            Width     = Glide.LCD.Width;
            Height    = Glide.LCD.Height;
            BackColor = Colors.White;
            Graphics  = new Graphics(Width, Height);

            int yPos = (Height / 2) - 50;

            _text1           = new TextBlock("text1", 255, (Glide.LCD.Width - 300) / 2, yPos, 300, 50);
            _text1.Font      = FontManager.GetFont(FontManager.FontType.droid_reg12);
            _text1.TextAlign = HorizontalAlignment.Center;
            AddChild(_text1);

            yPos += 50 + 5;

            _startBtn           = new Button("startBtn", 255, (Width - 200) / 2, yPos, 122, 32);
            _startBtn.Text      = "Recalibrate";
            _startBtn.TapEvent += new OnTap(_startBtn_TapEvent);
            _startBtn.Visible   = false;
            AddChild(_startBtn);

            _exitBtn           = new Button("exitBtn", 255, _startBtn.X + _startBtn.Width + 10, yPos, 68, 32);
            _exitBtn.Text      = "Done";
            _exitBtn.TapEvent += new OnTap(_exitBtn_TapEvent);
            _exitBtn.Visible   = false;
            AddChild(_exitBtn);

            _canvas = new Canvas();
            AddChild(_canvas);

            if (_autoStart)
            {
                _text1.FontColor = Colors.Black;
                _text1.Text      = "Touch the crosshair location.";
                Start();
            }
            else
            {
                if (GlideTouch.Calibrated)
                {
                    _text1.FontColor = Colors.Red;
                    _text1.Text      = "Touch is already calibrated.";

                    _exitBtn.Visible  = true;
                    _startBtn.Visible = true;
                }
                else
                {
                    _text1.FontColor = Colors.Black;
                    _text1.Text      = "Touch the screen to start.";

                    TapEvent += new OnTap(CalibrationWindow_TapEvent);
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates a new CalibrationWindow.
        /// </summary>
        /// <param name="autoStart">Whether or not to automatically begin calibration.</param>
        /// <param name="autoSave">Whether or not to save the calibration settings using Extended Weak Reference.</param>
        public CalibrationWindow(bool autoStart, bool autoSave)
        {
            _autoStart = autoStart;
            _autoSave = autoSave;

            Settings = new CalibrationSettings();

            Name = "calibrationWindow";
            Width = Glide.LCD.Width;
            Height = Glide.LCD.Height;
            BackColor = Colors.White;
            Graphics = new Graphics(Width, Height);

            int yPos = (Height / 2) - 50;

            _text1 = new TextBlock("text1", 255, (Glide.LCD.Width - 300) / 2, yPos, 300, 50);
            _text1.Font = FontManager.GetFont(FontManager.FontType.droid_reg12);
            _text1.TextAlign = HorizontalAlignment.Center;
            AddChild(_text1);

            yPos += 50 + 5;

            _startBtn = new Button("startBtn", 255, (Width - 200) / 2, yPos, 122, 32);
            _startBtn.Text = "Recalibrate";
            _startBtn.TapEvent += new OnTap(_startBtn_TapEvent);
            _startBtn.Visible = false;
            AddChild(_startBtn);

            _exitBtn = new Button("exitBtn", 255, _startBtn.X + _startBtn.Width + 10, yPos, 68, 32);
            _exitBtn.Text = "Done";
            _exitBtn.TapEvent += new OnTap(_exitBtn_TapEvent);
            _exitBtn.Visible = false;
            AddChild(_exitBtn);

            _canvas = new Canvas();
            AddChild(_canvas);

            if (_autoStart)
            {
                _text1.FontColor = Colors.Black;
                _text1.Text = "Touch the crosshair location.";
                Start();
            }
            else
            {
                if (GlideTouch.Calibrated)
                {
                    _text1.FontColor = Colors.Red;
                    _text1.Text = "Touch is already calibrated.";

                    _exitBtn.Visible = true;
                    _startBtn.Visible = true;
                }
                else
                {
                    _text1.FontColor = Colors.Black;
                    _text1.Text = "Touch the screen to start.";

                    TapEvent += new OnTap(CalibrationWindow_TapEvent);
                }
            }
        }
Exemplo n.º 10
0
        public static void Task6()
        {
            Console.WriteLine("********Task 6*********");
            // Variance Process Values
            double Kappa = 1.5768;
            double Theta = 0.398;
            double Sigma = 0.5751;
            double V0    = 0.0175;
            double Rho   = -0.5711;

            // Heston Model Params
            double InitialStockPrice = 100;
            double RiskFreeRate      = 0.025;

            // Callibration Settings
            double accuracy = 1.0e-3;
            int    maxIter  = 1000;

            VarianceProcessParameters varParams =
                new VarianceProcessParameters(Kappa, Theta, Sigma, V0, Rho);

            HestonModelParameters hestonModel =
                new HestonModelParameters(InitialStockPrice, RiskFreeRate, varParams);

            HestonModelParameters guess =
                new HestonModelParameters(InitialStockPrice, RiskFreeRate,
                                          new VarianceProcessParameters(1.55, 0.88, 1.5999, 0.4, -0.55));

            CalibrationSettings calibrationSettings = new CalibrationSettings(accuracy, maxIter);

            // Market Data
            LinkedList <IOptionMarketData <IEuropeanOption> > observedOptions =
                new LinkedList <IOptionMarketData <IEuropeanOption> >();

            EuropeanOption        eu1     = new EuropeanOption(80, PayoffType.Call, 1);
            EuropeanOptionFormula eu1Form = new EuropeanOptionFormula(hestonModel, eu1);
            OptionMarketData <IEuropeanOption> marketData1 =
                new OptionMarketData <IEuropeanOption>(eu1, eu1Form.Price());

            observedOptions.AddLast(marketData1);

            EuropeanOption        eu2     = new EuropeanOption(90, PayoffType.Call, 1);
            EuropeanOptionFormula eu2Form = new EuropeanOptionFormula(hestonModel, eu2);
            OptionMarketData <IEuropeanOption> marketData2 =
                new OptionMarketData <IEuropeanOption>(eu2, eu2Form.Price());

            observedOptions.AddLast(marketData2);

            EuropeanOption        eu3     = new EuropeanOption(80, PayoffType.Call, 2);
            EuropeanOptionFormula eu3Form = new EuropeanOptionFormula(hestonModel, eu3);
            OptionMarketData <IEuropeanOption> marketData3 =
                new OptionMarketData <IEuropeanOption>(eu3, eu3Form.Price());

            observedOptions.AddLast(marketData3);

            EuropeanOption        eu4     = new EuropeanOption(100, PayoffType.Call, 2);
            EuropeanOptionFormula eu4Form = new EuropeanOptionFormula(hestonModel, eu4);
            OptionMarketData <IEuropeanOption> marketData4 =
                new OptionMarketData <IEuropeanOption>(eu4, eu4Form.Price());

            observedOptions.AddLast(marketData4);

            EuropeanOption        eu5     = new EuropeanOption(100, PayoffType.Call, 1.5);
            EuropeanOptionFormula eu5Form = new EuropeanOptionFormula(hestonModel, eu5);
            OptionMarketData <IEuropeanOption> marketData5 =
                new OptionMarketData <IEuropeanOption>(eu5, eu5Form.Price());

            observedOptions.AddLast(marketData5);

            HestonCalibrationResult result;

            result = (HestonCalibrationResult)
                     Heston.CalibrateHestonParameters(guess, observedOptions, calibrationSettings);

            Console.WriteLine("Calibration outcome: {0} and error: {1}", result.MinimizerStatus, result.PricingError);
        }
Exemplo n.º 11
0
        public static void Task5()
        {
            // Variance Process Values
            double Kappa = 1.5768;
            double Theta = 0.398;
            double Sigma = 0.5751;
            double V0    = 1.0175;
            double Rho   = -0.5711;

            // Heston Model Params
            double InitialStockPrice = 100;
            double RiskFreeRate      = 0.025;

            // Callibration Settings
            double accuracy = 0.001;
            int    maxIter  = 1000;

            VarianceProcessParameters varParams =
                new VarianceProcessParameters(Kappa, Theta, Sigma, V0, Rho);

            HestonModelParameters hestonModel =
                new HestonModelParameters(InitialStockPrice, RiskFreeRate, varParams);

            CalibrationSettings calibrationSettings = new CalibrationSettings(accuracy, maxIter);

            // Market Data
            LinkedList <IOptionMarketData <IEuropeanOption> > observedOptions =
                new LinkedList <IOptionMarketData <IEuropeanOption> >();

            EuropeanOption eu1 = new EuropeanOption(80, PayoffType.Call, 1);
            OptionMarketData <IEuropeanOption> marketData1 =
                new OptionMarketData <IEuropeanOption>(eu1, 25.72);

            observedOptions.AddLast(marketData1);

            EuropeanOption eu2 = new EuropeanOption(90, PayoffType.Call, 1);
            OptionMarketData <IEuropeanOption> marketData2 =
                new OptionMarketData <IEuropeanOption>(eu2, 18.93);

            observedOptions.AddLast(marketData2);

            EuropeanOption eu3 = new EuropeanOption(80, PayoffType.Call, 2);
            OptionMarketData <IEuropeanOption> marketData3 =
                new OptionMarketData <IEuropeanOption>(eu3, 30.49);

            observedOptions.AddLast(marketData3);

            EuropeanOption eu4 = new EuropeanOption(100, PayoffType.Call, 2);
            OptionMarketData <IEuropeanOption> marketData4 =
                new OptionMarketData <IEuropeanOption>(eu4, 19.36);

            observedOptions.AddLast(marketData4);

            EuropeanOption eu5 = new EuropeanOption(100, PayoffType.Call, 1.5);
            OptionMarketData <IEuropeanOption> marketData5 =
                new OptionMarketData <IEuropeanOption>(eu5, 16.58);

            observedOptions.AddLast(marketData5);

            HestonCalibrationResult result;

            result = (HestonCalibrationResult)
                     Heston.CalibrateHestonParameters(hestonModel, observedOptions, calibrationSettings);

            Console.WriteLine("Calibration outcome: {0} and error: {1}", result.MinimizerStatus, result.PricingError);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Takes all detected contours, transforms their positions into the coordinate system of the table,
        /// taking also into accoutn perspective distortion. At last, it creates descriptors of detected
        /// stones and passes everything to the merging processor that will increase the simulation step
        /// </summary>
        private void InputLogic()
        {
            foundRocks.Clear();

            if (tableManager.IsRunning)
            {
                foreach (FoundTemplateDesc found in processor.foundTemplates)
                {
                    System.Drawing.Rectangle foundRect = found.sample.contour.SourceBoundingRect;

                    #region hledani transformovaneho bodu

                    try
                    {
                        double found_pos_x = foundRect.Left + foundRect.Size.Width / 2;
                        double found_pos_y = foundRect.Top + foundRect.Size.Height / 2;

                        double mx = found_pos_x;                                          // X-axis coord in the trapezoid
                        double my = captured_frame.Height - found_pos_y;                  // Y-axis coord in the trapezoid

                        double ax = CalibrationSettings.Instance().CALIBRATION_POINT_A.X; // X-axis coord of A-point in trapezoid

                        // estimation of other points according to ( a = (2*r1r2)/(r1+1))
                        double r1 = CalibrationSettings.Instance().CALIBRATION_PERSPECTIVE;
                        double r2 = CalibrationSettings.Instance().CALIBRATION_POINT_C.X - CalibrationSettings.Instance().CALIBRATION_POINT_A.X;
                        double bx = ax + (2 * (r1 * r2)) / (r1 + 1);                                              // X-axis coord of B-point in trapezoid
                        double cx = CalibrationSettings.Instance().CALIBRATION_POINT_C.X;                         // X-axis coord of C-point in trapezoid
                        double dx = ax + bx - cx;                                                                 // X-axis coord of D-point in trapezoid

                        double cy = captured_frame.Height - CalibrationSettings.Instance().CALIBRATION_POINT_C.Y; // Y-axis coord of C-point in trapezoid
                        double ay = captured_frame.Height - CalibrationSettings.Instance().CALIBRATION_POINT_A.Y; // Y-axis coord of A-point in trapezoid

                        double pom  = (my - ay) / (cy - ay);                                                      // ratio between the bottom base and the upper base
                        double r1m  = mx - (ax + (dx - ax) * pom);                                                // distance of the M point from the left side
                        double r1r2 = pom * (cx - bx - dx + ax) + bx - ax;                                        // length of a line that crosses the M-point and both sides

                        double ab      = Math.Abs(bx - ax);                                                       // length of AB line
                        double cd      = Math.Abs(cx - dx);                                                       // length of CD line
                        double alfa    = r1r2 / ab;                                                               // perspective distortion
                        double maximum = captured_frame.Height / (cd / ab);                                       // max distortion
                        double real    = (captured_frame.Height) * (pom / alfa);                                  // relative distortion to the M-point

                        // projection to a rectangle the frame represents
                        double mxx = (ax < bx) ? captured_frame.Width * (r1m / r1r2) : captured_frame.Width - captured_frame.Width * r1m / r1r2;
                        double mxy = (ay > cy) ? (captured_frame.Height * real / maximum) : captured_frame.Height - (captured_frame.Height * real / maximum);


                        // recalculation from camera space to table space
                        mxx *= CommonAttribService.ACTUAL_TABLE_WIDTH / ((double)captured_frame.Width);
                        mxy *= CommonAttribService.ACTUAL_TABLE_HEIGHT / ((double)captured_frame.Height);
                        foundRocks.Add(CreateFoundRock(found.template.name, new FPoint(mxx - CommonAttribService.ACTUAL_TABLE_WIDTH / 2, CommonAttribService.ACTUAL_TABLE_HEIGHT / 2 - mxy), processor.templates, found.rate, found.scale, found.angle));
                    }
                    catch
                    {
                        MessageBox.Show("An error occurred during calibration. Try to set the calibration again!");
                        StopThread();
                    }
                    #endregion
                }
                // merge both systems between two time steps
                realTableManager.MergeSystems(foundRocks);
            }
        }
Exemplo n.º 13
0
    // Update is called once per frame
    void FixedUpdate()
    {
        switch (state)
        {
        case CalibrationState.IDLE:
            //The spinning wheel(throbber) rotates
            if (autocalibratingThrobber.activeInHierarchy)
            {
                autocalibratingThrobber.transform.Rotate(0, 0, -200 * Time.deltaTime);
            }
            break;

        case CalibrationState.DISCOVERING:
            searchingLabel.transform.GetChild(0).Rotate(0, 0, -200 * Time.deltaTime);
            break;

        case CalibrationState.RECEIVING_DISCOVER_ANCHORS:

            List <int> anchorsIDList = PozyxModule.GetAnchorList();
            {
                //UnityEngine.Debug.Log("ReadingAnchorList");
                dicoveredAnchors.text = "";
                for (int i = 0; i < anchorsIDList.Count; i++)
                {
                    //Writing the anchor list received inside the TextBoxes that can be clicked, with the HorizontalGroup name
                    //UnityEngine.Debug.Log("Reading Anchor List Element: " + i);
                    //anchorParent.transform.Find("Cube" + anchorID).position = anchorData.position;
                    //anchor1Pos = cam.WorldToScreenPoint(anchorData.position);
                    //transform.Find("Cube" + anchorID + "ID").GetComponent<RectTransform>().anchoredPosition = new Vector2(anchor1Pos.x - 40, anchor1Pos.y - Screen.height * 0.15f);
                    dicoveredAnchors.text += "Anchor: " + i + " ID: " + "0x" + anchorsIDList[i].ToString("x") + "\n";
                    anchorList.transform.Find("HorizontalGroup" + (i + 1)).GetChild(0).GetChild(0).GetComponent <Text>().text = "0x" + anchorsIDList[i].ToString("x");
                    anchorList.transform.Find("HorizontalGroup" + (i + 1)).GetChild(0).name = anchorsIDList[i].ToString();
                }

                //UnityEngine.Debug.Log("FinishedReadingAnchorList");
                //Activate the button that lets the user give the correct position to the anchors
                configAnchorsButton.GetComponent <Button>().interactable = true;
                configAnchorsButton.transform.GetChild(0).GetComponent <Text>().color = new Vector4(1, 1, 1, 1);
                //UnityEngine.Debug.Log("All anchors positioned");
                searchingLabel.SetActive(false);
                state = CalibrationState.RECEIVED_DISCOVER_ANCHORS;
            }
            break;

        case CalibrationState.RECEIVED_DISCOVER_ANCHORS:
            //Having done previously that, is this state necessary?
            if (PozyxModule.anchorsReceived)
            {
                PozyxModule.anchorsReceived = false;
                state = CalibrationState.DISCOVERED;
            }
            break;

        case CalibrationState.DISCOVERED:

            anchorReadCount = 0;
            for (int i = 0; i < 8; i++)
            {
                ServerMessages.IPSFrameAnchorData anchorData = CalibrationSettings.GetAnchorData(i);
                //anchorList.transform.Find("HorizontalGroup" + (anchorData.order + 1)).GetChild(0).GetChild(0).GetComponent<Text>().text = anchorData.id.ToString();
                //anchorList.transform.Find("HorizontalGroup" + (anchorData.order + 1)).GetChild(0).name = anchorData.id.ToString();

                //Writing the corresponding id of an anchor to a cube
                anchorCubeParent.transform.Find("Anchor" + (anchorData.order + 1) + "Cube").GetChild(0).GetComponent <TextMesh>().text = "0x" + anchorData.id.ToString("x");
                anchorCubeParent.transform.Find("Anchor" + (anchorData.order + 1) + "Cube").GetChild(1).localPosition = anchorData.position;
                for (int j = 1; j < 9; j++)
                {
                    //UnityEngine.Debug.Log(anchorData.order);
                    //Writing the received position of the anchors
                    if (anchorList.transform.Find("HorizontalGroup" + j).GetChild(0).name == anchorData.id.ToString())
                    {
                        anchorList.transform.Find("HorizontalGroup" + j).GetChild(1).GetComponent <InputField>().text = anchorData.position.x.ToString();
                        anchorList.transform.Find("HorizontalGroup" + j).GetChild(2).GetComponent <InputField>().text = anchorData.position.y.ToString();
                        anchorList.transform.Find("HorizontalGroup" + j).GetChild(3).GetComponent <InputField>().text = anchorData.position.z.ToString();
                        anchorList.transform.Find("HorizontalGroup" + j).GetChild(0).GetComponent <Image>().color     = new Vector4(0, 255, 0, 150);
                        anchorReadCount++;
                        //Writing the received position of the anchor list when autocalibration is pressed
                        if (autoCalib && (anchorData.order == 1 || anchorData.order == 5))
                        {
                            anchorList.transform.Find("HorizontalGroup" + j).GetChild(1).GetComponent <InputField>().text = "";
                            anchorList.transform.Find("HorizontalGroup" + j).GetChild(1).GetComponent <InputField>().placeholder.GetComponent <Text>().text = "AUTO";
                            anchorList.transform.Find("HorizontalGroup" + j).GetChild(1).GetComponent <InputField>().interactable = false;
                            anchorList.transform.Find("HorizontalGroup" + j).GetChild(2).GetComponent <InputField>().text         = "0";
                        }
                        else if (autoCalib && (anchorData.order == 3 || anchorData.order == 7))
                        {
                            anchorList.transform.Find("HorizontalGroup" + j).GetChild(1).GetComponent <InputField>().text = "0";
                            anchorList.transform.Find("HorizontalGroup" + j).GetChild(2).GetComponent <InputField>().text = "";
                            anchorList.transform.Find("HorizontalGroup" + j).GetChild(2).GetComponent <InputField>().placeholder.GetComponent <Text>().text = "AUTO";
                            anchorList.transform.Find("HorizontalGroup" + j).GetChild(2).GetComponent <InputField>().interactable = false;
                        }
                        else if (autoCalib && (anchorData.order == 2 || anchorData.order == 6))
                        {
                            anchorList.transform.Find("HorizontalGroup" + j).GetChild(1).GetComponent <InputField>().text = "";
                            anchorList.transform.Find("HorizontalGroup" + j).GetChild(1).GetComponent <InputField>().placeholder.GetComponent <Text>().text = "AUTO";
                            anchorList.transform.Find("HorizontalGroup" + j).GetChild(1).GetComponent <InputField>().interactable = false;
                            anchorList.transform.Find("HorizontalGroup" + j).GetChild(2).GetComponent <InputField>().text         = "";
                            anchorList.transform.Find("HorizontalGroup" + j).GetChild(2).GetComponent <InputField>().placeholder.GetComponent <Text>().text = "AUTO";
                            anchorList.transform.Find("HorizontalGroup" + j).GetChild(2).GetComponent <InputField>().interactable = false;
                        }
                        else if (autoCalib)
                        {
                            anchorList.transform.Find("HorizontalGroup" + j).GetChild(1).GetComponent <InputField>().text = "0";
                            anchorList.transform.Find("HorizontalGroup" + j).GetChild(2).GetComponent <InputField>().text = "0";
                        }
                    }
                }
            }

            //UnityEngine.Debug.Log("Anclas coincidentes: " + anchorReadCount);
            //Activates button to confirm configuration
            if (anchorReadCount == 8)
            {
                UnityEngine.Debug.Log("PozyxModuleAnchorsReady");
                confirmManual.interactable = true;
                confirmManual.transform.GetChild(0).GetComponent <Text>().color = new Vector4(255, 255, 255, 255);
            }

            state = CalibrationState.IDLE;

            //anchorParent.transform.Find("Cube" + anchorID).position = anchorData.position;
            //anchor1Pos = cam.WorldToScreenPoint(anchorData.position);
            //transform.Find("Cube" + anchorID + "ID").GetComponent<RectTransform>().anchoredPosition = new Vector2(anchor1Pos.x - 40, anchor1Pos.y - Screen.height * 0.15f);
            //dicoveredAnchors.text += "Tag: " + anchorID + " ID: " + anchorData.id + "\n";
            //anchorList.transform.Find("Anchor" + anchorID).GetChild(0).GetComponent<Text>().text = "Anchor ID: " + anchorData.id;
            //anchorList.transform.Find("Anchor" + anchorID).name = anchorData.id.ToString();

            //configAnchorsButton.GetComponent<Button>().interactable = true;
            //configAnchorsButton.transform.GetChild(0).GetComponent<Text>().color = new Vector4(1, 1, 1, 1);
            //UnityEngine.Debug.Log("All anchor data received and ready to be used");
            //searchingLabel.SetActive(false);
            //ipsCommandSent = false;
            break;

        case CalibrationState.MANUAL_ACCEPTED:
            //Sending the configuration and wait for positioning
            clientUnity.client.SendCommand((byte)Modules.POSITIONING_MODULE, (byte)PositioningCommandType.IPS_UPDATE_SETTINGS);
            state = CalibrationState.TRY_START_POSITIONING;
            break;

        case CalibrationState.AUTOCALIBRATION_RECEIVED:

            autocalibratingThrobber.transform.Rotate(0, 0, -200 * Time.deltaTime);
            anchorReadCount = 0;

            for (int i = 0; i < 8; i++)
            {
                ServerMessages.IPSFrameAnchorData anchorData = CalibrationSettings.GetAnchorData(i);
                //anchorList.transform.Find("HorizontalGroup" + (anchorData.order + 1)).GetChild(0).GetChild(0).GetComponent<Text>().text = anchorData.id.ToString();
                //anchorList.transform.Find("HorizontalGroup" + (anchorData.order + 1)).GetChild(0).name = anchorData.id.ToString();


                anchorCubeParent.transform.Find("Anchor" + (anchorData.order + 1) + "Cube").GetChild(0).GetComponent <TextMesh>().text = "0x" + anchorData.id.ToString("x");
                anchorCubeParent.transform.Find("Anchor" + (anchorData.order + 1) + "Cube").GetChild(1).localPosition = anchorData.position;
                //Receiving the anchors position from autocalibration
                for (int j = 1; j < 9; j++)
                {
                    if (anchorList.transform.Find("HorizontalGroup" + j).GetChild(0).name == anchorData.id.ToString())
                    {
                        anchorList.transform.Find("HorizontalGroup" + j).GetChild(1).GetComponent <InputField>().text         = anchorData.position.x.ToString();
                        anchorList.transform.Find("HorizontalGroup" + j).GetChild(2).GetComponent <InputField>().text         = anchorData.position.y.ToString();
                        anchorList.transform.Find("HorizontalGroup" + j).GetChild(3).GetComponent <InputField>().text         = anchorData.position.z.ToString();
                        anchorList.transform.Find("HorizontalGroup" + j).GetChild(0).GetComponent <Button>().interactable     = false;
                        anchorList.transform.Find("HorizontalGroup" + j).GetChild(1).GetComponent <InputField>().interactable = false;
                        anchorList.transform.Find("HorizontalGroup" + j).GetChild(2).GetComponent <InputField>().interactable = false;
                        anchorList.transform.Find("HorizontalGroup" + j).GetChild(3).GetComponent <InputField>().interactable = false;
                        anchorList.transform.Find("HorizontalGroup" + j).GetChild(0).GetComponent <Image>().color             = new Vector4(0, 255, 0, 150);
                        anchorReadCount++;
                        //Painting orange the autocalibrated anchors
                        if (anchorData.order == 1 || anchorData.order == 2 || anchorData.order == 5 || anchorData.order == 6)
                        {
                            ColorBlock cb = anchorList.transform.Find("HorizontalGroup" + j).GetChild(1).GetComponent <InputField>().colors;
                            cb.disabledColor    = new Vector4(1.0f, 0.6f, 0.0f, 0.4f);
                            cb.normalColor      = new Vector4(1.0f, 0.8f, 0.4f, 1.0f);
                            cb.highlightedColor = new Vector4(1.0f, 0.9f, 0.7f, 1.0f);
                            anchorList.transform.Find("HorizontalGroup" + j).GetChild(1).GetComponent <InputField>().colors = cb;
                        }
                        if (anchorData.order == 2 || anchorData.order == 3 || anchorData.order == 6 || anchorData.order == 7)
                        {
                            ColorBlock cb = anchorList.transform.Find("HorizontalGroup" + j).GetChild(2).GetComponent <InputField>().colors;
                            cb.disabledColor    = new Vector4(1.0f, 0.6f, 0.0f, 0.4f);
                            cb.normalColor      = new Vector4(1.0f, 0.8f, 0.4f, 1.0f);
                            cb.highlightedColor = new Vector4(1.0f, 0.9f, 0.7f, 1.0f);
                            anchorList.transform.Find("HorizontalGroup" + j).GetChild(2).GetComponent <InputField>().colors = cb;
                        }
                    }
                }
            }

            if (anchorReadCount == 8)
            {
                //Habilitating the three buttons
                //UnityEngine.Debug.Log("AnchorsAutocalibratedReady");
                // ## Se puede sacar fuera del if todo
                confirmManual.gameObject.SetActive(false);
                editConfig.gameObject.SetActive(true);
                redoAutocalibration.gameObject.SetActive(true);
                confirmAuto.gameObject.SetActive(true);
                editConfig.interactable = true;
                editConfig.transform.GetChild(0).GetComponent <Text>().color = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
                redoAutocalibration.interactable = true;
                redoAutocalibration.transform.GetChild(0).GetComponent <Text>().color = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
                confirmAuto.interactable = true;
                confirmAuto.transform.GetChild(0).GetComponent <Text>().color = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
                //acceptConfig.interactable = true;
                //acceptConfig.transform.GetChild(0).GetComponent<Text>().color = new Vector4(255, 255, 255, 255);
            }

            state = CalibrationState.AUTOCALIBRATION_FINNISHED;

            break;

        case CalibrationState.AUTOCALIBRATION_ACCEPTED:
            autocalibratingThrobber.transform.Rotate(0, 0, -200 * Time.deltaTime);
            // Used to check the current state
            break;

        case CalibrationState.AUTOCALIBRATION_FINNISHED:
            // Used to check the current state
            autocalibratingThrobber.transform.parent.gameObject.SetActive(false);
            break;

        case CalibrationState.CALIBRATION_PREVIEW:
            //Nobody uses this state ??
            ServerMessages.IPSFrameData frameData = DroneModule.DequeueIPSDronFrame();
            if (frameData != null)
            {
                //UnityEngine.Debug.Log("Position: " + frameData.position);
                //UnityEngine.Debug.Log("Rotation: " + frameData.rotation);
                drone.transform.position = frameData.position;
                drone.transform.rotation = Quaternion.Euler(frameData.rotation);
            }

            anchor1Pos = cam.WorldToScreenPoint(anchor1GO.transform.position);
            anchor2Pos = cam.WorldToScreenPoint(anchor2GO.transform.position);
            anchor3Pos = cam.WorldToScreenPoint(anchor3GO.transform.position);
            anchor4Pos = cam.WorldToScreenPoint(anchor4GO.transform.position);
            anchor5Pos = cam.WorldToScreenPoint(anchor5GO.transform.position);
            anchor6Pos = cam.WorldToScreenPoint(anchor6GO.transform.position);
            anchor7Pos = cam.WorldToScreenPoint(anchor7GO.transform.position);
            anchor8Pos = cam.WorldToScreenPoint(anchor8GO.transform.position);

            // ## TODO: Incluir en el if de arriba buscando cada anchorID según el ID actual y asociar su posición
            anchor1ID.anchoredPosition = new Vector2(anchor1Pos.x - 40, anchor1Pos.y - Screen.height * 0.15f);
            anchor2ID.anchoredPosition = new Vector2(anchor2Pos.x - 40, anchor2Pos.y - Screen.height * 0.15f);
            anchor3ID.anchoredPosition = new Vector2(anchor3Pos.x - 40, anchor3Pos.y - Screen.height * 0.15f);
            anchor4ID.anchoredPosition = new Vector2(anchor4Pos.x - 40, anchor4Pos.y - Screen.height * 0.15f);
            anchor5ID.anchoredPosition = new Vector2(anchor5Pos.x - 40, anchor5Pos.y - Screen.height * 0.15f);
            anchor6ID.anchoredPosition = new Vector2(anchor6Pos.x - 40, anchor6Pos.y - Screen.height * 0.15f);
            anchor7ID.anchoredPosition = new Vector2(anchor7Pos.x - 40, anchor7Pos.y - Screen.height * 0.15f);
            anchor8ID.anchoredPosition = new Vector2(anchor8Pos.x - 40, anchor8Pos.y - Screen.height * 0.15f);
            break;

        case CalibrationState.TRY_START_POSITIONING:
            //Check for positioning
            if (PozyxModule.positiningIsValid)
            {
                firstPositionTry = true;
                state            = CalibrationState.POSITIONING_CONFIRMED;
            }
            else
            {
                if (firstPositionTry)
                {
                    autocalibratingThrobber.transform.parent.GetComponent <Text>().text = "Waiting for positioning";
                    autocalibratingThrobber.transform.parent.gameObject.SetActive(true);
                    firstPositionTry = false;
                }
                autocalibratingThrobber.transform.Rotate(0, 0, -200 * Time.deltaTime);
            }
            break;

        case CalibrationState.POSITIONING_CONFIRMED:
            //Change scene, positioning received
            state = CalibrationState.IDLE;
            autocalibratingThrobber.transform.parent.gameObject.SetActive(false);
            //UnityEngine.Debug.Log(GeneralSceneManager.appState);
            //You can access the scene from both buttons, as calibrating is always necessary, that is way there is a button to use last calibration and skip the process
            if (GeneralSceneManager.appState == GeneralSceneManager.ApplicationState.Mapping)
            {
                SceneManager.LoadScene("Mapping");
            }
            else if (GeneralSceneManager.appState == GeneralSceneManager.ApplicationState.Recording)
            {
                SceneManager.LoadScene("PlanSelection");
            }
            break;

        case CalibrationState.LAST_REQ_FAILED:
            UnityEngine.Debug.Log("LastReqFailed");
            if (discoverPanel.activeInHierarchy)
            {     // Something failed discovering anchors, retry
                UnityEngine.Debug.Log("DiscoverFailed");
                dicoveredAnchors.text = PozyxModule.errorMsg;
                state = CalibrationState.DISCOVERING;
            }
            else
            {     // Something failed with anchors configuration, let the user change the config and try again
                UnityEngine.Debug.Log("ConfigFailed");
                state = CalibrationState.IDLE;
                autocalibratingThrobber.transform.parent.gameObject.SetActive(false);
                if (confirmManual.gameObject.activeInHierarchy)
                {
                    confirmManual.interactable = true;
                    confirmManual.transform.GetChild(0).GetComponent <Text>().color = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
                }
                else if (confirmAuto.gameObject.activeInHierarchy)
                {
                    confirmAuto.interactable = true;
                    confirmAuto.transform.GetChild(0).GetComponent <Text>().color = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
                    editConfig.interactable = true;
                    editConfig.transform.GetChild(0).GetComponent <Text>().color = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
                    redoAutocalibration.interactable = true;
                    redoAutocalibration.transform.GetChild(0).GetComponent <Text>().color = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
                }
            }
            //discoverButton.SetActive(true);
            //configAnchorsButton.SetActive(false);
            //startingLabel.SetActive(true);
            //searchingLabel.SetActive(false);

            break;
        }
    }