Esempio n. 1
0
        public void RunFrame()
        {
            connectionState = Tello.connectionState;
            //Frame info
            telloFrameCount++;
            timeSinceLastUpdate = Time.time - prevDeltaTime;
            prevDeltaTime       = Time.time;
            var deltaTime1 = (int)(timeSinceLastUpdate * 1000);

            telloDeltaTime = new System.TimeSpan(0, 0, 0, 0, (deltaTime1));
            //inputs
            var  inputs        = inputController.CheckFlightInputs();
            bool receivedInput = true;

            if (inputs.w == 0 & inputs.x == 0 & inputs.y == 0 & inputs.z == 0)
            {
                receivedInput = false;
            }
            if (receivedInput & autoPilot.enabled)
            {
                Debug.Log("AutoPilot disabled due to user input");
                ToggleAutoPilot(false);
            }
            //if we are flying the tello
            if (sceneType != SceneType.SimOnly)
            {
                switch (flightStatus)
                {
                case FlightStatus.Launching:
                    telloManager.CheckForLaunchComplete();
                    break;

                case FlightStatus.Flying:
                    bool validFrame = telloManager.SetTelloPosition();
                    if (!validFrame & autoPilot.enabled)
                    {
                        Debug.Log("AutoPilot disabled because Tello Lost Tracking");
                        ToggleAutoPilot(false);
                    }
                    break;
                }
            }
            if (autoPilot.enabled)
            {
                inputs = autoPilot.RunAutoPilot(telloDeltaTime);
            }
            finalInputs = CalulateFinalInputs(inputs.x, inputs.y, inputs.z, inputs.w);
            yaw         = finalInputs.x;
            elv         = finalInputs.y;
            roll        = finalInputs.z;
            pitch       = finalInputs.w;
        }
Esempio n. 2
0
        public void RunFrame()
        {
            connectionState = Tello.connectionState;
            //Frame info
            telloFrameCount++;
            timeSinceLastUpdate = Time.time - prevDeltaTime;
            prevDeltaTime       = Time.time;
            var deltaTime1 = (int)(timeSinceLastUpdate * 1000);

            telloDeltaTime = new System.TimeSpan(0, 0, 0, 0, (deltaTime1));
            //inputs
            var  inputs        = inputController.CheckFlightInputs();
            bool receivedInput = true;

            if (inputs.w == 0 & inputs.x == 0 & inputs.y == 0 & inputs.z == 0)
            {
                receivedInput = false;
            }
            if (receivedInput & autoPilot.enabled)
            {
                Debug.Log("AutoPilot disabled due to user input");
                ToggleAutoPilot(false);
            }
            //if we are flying the tello
            if (sceneType != SceneType.SimOnly)
            {
                switch (flightStatus)
                {
                case FlightStatus.Launching:
                    telloManager.CheckForLaunchComplete();
                    break;

                case FlightStatus.Flying:
                    bool validFrame = telloManager.SetTelloPosition();
                    if (!validFrame & autoPilot.enabled)
                    {
                        Debug.Log("AutoPilot disabled because Tello Lost Tracking");
                        ToggleAutoPilot(false);
                    }
                    break;
                }
            }
            if (autoPilot.enabled)
            {
                inputs = autoPilot.RunAutoPilot(telloDeltaTime);
            }
            finalInputs = CalulateFinalInputs(inputs.x, inputs.y, inputs.z, inputs.w);
            yaw         = finalInputs.x;
            elv         = finalInputs.y;
            roll        = finalInputs.z;
            pitch       = finalInputs.w;

            //yaw = inputs.x;
            //elv = inputs.y;
            //roll = inputs.z;
            //pitch = inputs.w;

            //switch (sceneType)
            //{
            //    case SceneType.FlyOnly:
            //        telloManager.SendTelloInputs(finalInputs);
            //        break;
            //    case SceneType.SimOnly:

            //        break;
            //}

            //if()

            //if (Input.GetKeyDown(KeyCode.Q))
            //{
            //    inputController.ToggleAutoPilot(!inputController.autoPilotActive);
            //}
            //if (Input.GetKeyDown(KeyCode.E))
            //{
            //    inputController.BeginFlightPath(FindObjectOfType<FlightPath>());
            //}

            //if (Tello.connected & sceneType != SceneType.SimOnly)
            //{
            //    if (Input.GetKeyDown(KeyCode.T))
            //    {
            //        telloManager.OnTakeOff();
            //    }
            //    else if (Input.GetKeyDown(KeyCode.V))
            //    {
            //        telloManager.StartProps();
            //    }
            //    else if (Input.GetKeyDown(KeyCode.L))
            //    {
            //        telloManager.OnLand();
            //    }
            //    else if (Input.GetKeyDown(KeyCode.Joystick1Button0) || Input.GetKeyDown(KeyCode.Space))
            //        BeginTracking();

            //    telloManager.CustomUpdate();
            //}
            //if (sceneType != SceneType.FlyOnly)
            //{
            //    simulator.CustomUpdate();
            //}
        }