private async void _Timer_Tick(object sender, object e)
        {
            UpdateDisplay();

            await _droneClient.ConnectAsync();

            if (!_droneClient.IsActive)
            {
                await Task.Delay(5000);
            }
        }
Ejemplo n.º 2
0
        private async void _Timer_Tick(object sender, object e)
        {
            SetConnectionStatus();

            if (_droneClient.IsActive)
            {
                return;
            }

            try
            {
                await _droneClient.ConnectAsync();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            finally
            {
                SetConnectionStatus();
            }

            if (!_droneClient.IsActive)
            {
                await Task.Delay(5000);
            }
            else
            {
                await ConnectToFtpAsync();
            }
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (await _droneClient.ConnectAsync())
            {
                int altitudeMax = _droneClient.Configuration.Control.AltitudeMax;
                AltitudeMax.Value = altitudeMax / 1000;
            }
        }
Ejemplo n.º 4
0
        public async Task <bool> Connect()
        {
            if (!enabled)
            {
                return(false);
            }
            Logger.WriteLine("Drone.Connect()");
            bool connected = await droneClient.ConnectAsync();

            return(connected);
        }
Ejemplo n.º 5
0
        public async void Update()
        {
            float pitch = 0, roll = 0, yaw = 0, gaz = 0;

            if (_DroneClient == null || _Controller == null)
            {
                return;
            }
            if (!_Controller.IsConnected || !_Controller.GetState(out _ControllerState))
            {
                _FailCounter++;
                if (_FailCounter > _FailCounterMax)
                {
                    DroneClient.InputState.Update(0, 0, 0, 0);
                    //Avoid overflow
                    _FailCounter = _FailCounterMax;
                }
                return;
            }
            if (_ControllerState.PacketNumber <= _ControllerPreviousState.PacketNumber)
            {
                return;
            }
            //Thumbs
            var leftThumb = NormalizeInput(_ControllerState.Gamepad.LeftThumbX, _ControllerState.Gamepad.LeftThumbY, Convert.ToInt16(SharpDX.XInput.Gamepad.LeftThumbDeadZone * 1.1), _JoystickRange);

            if (leftThumb.NormalizedMagnitude > 0)
            {
                roll  = (float)_ControllerState.Gamepad.LeftThumbX * _RollThrottle / _JoystickRange;
                pitch = (float)_ControllerState.Gamepad.LeftThumbY * _PitchThrottle / _JoystickRange;
            }
            var rightThumb = NormalizeInput(_ControllerState.Gamepad.RightThumbX, _ControllerState.Gamepad.RightThumbY, Convert.ToInt16(SharpDX.XInput.Gamepad.RightThumbDeadZone * 1.1), _JoystickRange);

            if (rightThumb.NormalizedMagnitude > 0)
            {
                yaw = (float)_ControllerState.Gamepad.RightThumbX * _YawThrottle / _JoystickRange;
                Debug.WriteLine(yaw);
                gaz = (float)_ControllerState.Gamepad.RightThumbY * _GazThrottle / _JoystickRange;
            }

            _FailCounter = 0;
            DroneClient.InputState.Update(roll, -pitch, yaw, gaz);
            //Debug.WriteLine("InputState=" + DroneClient.InputState.ToString());

            //Buttons
            var buttons = _ControllerState.Gamepad.Buttons;

            if (buttons.HasFlag(GamepadButtonFlags.Start))
            {
                if (await DroneClient.ConnectAsync())
                {
                    if (DroneClient.NavigationData.State.HasFlag(NavigationState.Landed))
                    {
                        DroneClient.TakeOff();
                    }
                    else
                    {
                        DroneClient.Land();
                    }
                }
            }
            if (buttons.HasFlag(GamepadButtonFlags.Back))
            {
                DroneClient.Emergency();
            }
            if (buttons.HasFlag(GamepadButtonFlags.Y))
            {
                DroneClient.ResetEmergency();
            }
            if (buttons.HasFlag(GamepadButtonFlags.X))
            {
                DroneClient.ExecuteFlatTrim();
            }
            if (buttons.HasFlag(GamepadButtonFlags.A))
            {
                DroneClient.TakePicture();
            }
            if (buttons.HasFlag(GamepadButtonFlags.B))
            {
                if (DroneClient.IsRecording())
                {
                    DroneClient.StopRecordingVideo();
                }
                else
                {
                    DroneClient.StartRecordingVideo();
                }
            }
            if (buttons.HasFlag(GamepadButtonFlags.DPadLeft))
            {
                DroneClient.PlayAnimation(FlightAnimationType.FlipLeft);
            }
            if (buttons.HasFlag(GamepadButtonFlags.DPadUp))
            {
                DroneClient.PlayAnimation(FlightAnimationType.FlipAhead);
            }
            if (buttons.HasFlag(GamepadButtonFlags.DPadRight))
            {
                DroneClient.PlayAnimation(FlightAnimationType.FlipRight);
            }
            if (buttons.HasFlag(GamepadButtonFlags.DPadDown))
            {
                DroneClient.PlayAnimation(FlightAnimationType.FlipBehind);
            }

            _ControllerPreviousState = _ControllerState;
        }
Ejemplo n.º 6
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (await _droneClient.ConnectAsync())
            {
                TakeOffButton.IsEnabled = true;

                await Task.Run(async() =>
                {
                    try
                    {
                        if (_speechRecognizer == null)
                        {
                            _speechRecognizer = new SpeechRecognizer();
                            _speechRecognizer.Grammars.AddGrammarFromList("DroneCommands", new List <string>
                            {
                                "Take off", "Take off the drone", "Take the drone off",
                                "Land", "Land the drone"
                            });
                        }
                        try
                        {
                            while (true)
                            {
                                Dispatcher.BeginInvoke(() =>
                                {
                                    if (TextRecognizer.Text != "Voice: listening...")
                                    {
                                        TextRecognizer.Foreground = new SolidColorBrush(Colors.Green);
                                        TextRecognizer.Text       = "Voice: listening...";
                                    }
                                });

                                var result = await _speechRecognizer.RecognizeAsync();

                                //if (result.TextConfidence == SpeechRecognitionConfidence.High)
                                if (result.Text.Length > 0)
                                {
                                    Dispatcher.BeginInvoke(() =>
                                    {
                                        switch (result.Text)
                                        {
                                        case "Take off":
                                        case "Take off the drone":
                                        case "Take the drone off":
                                            _droneClient.TakeOff();
                                            break;

                                        case "Land":
                                        case "Land the drone":
                                            _droneClient.Land();
                                            break;
                                        }
                                    });
                                    await Task.Delay(1000);
                                }
                                else
                                {
                                    await Task.Delay(500);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex);
                        }

                        Dispatcher.BeginInvoke(() =>
                        {
                            TextRecognizer.Foreground = new SolidColorBrush(Colors.Red);
                            TextRecognizer.Text       = "Voice: unknown";
                        });
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex);
                    }
                });
            }
        }
Ejemplo n.º 7
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (await _droneClient.ConnectAsync())
            {
                TakeOffButton.IsEnabled        = true;
                ResetEmergencyButton.IsEnabled = true;
                FlatTrimButton.IsEnabled       = true;
                TakePictureButton.IsEnabled    = true;
                RecordVideoButton.IsEnabled    = true;
                FlipButton.IsEnabled           = true;

                RollPitchJoystick.StartJoystick();
                YawGazJoystick.StartJoystick();

                //Outlined to avoid unwanted takoff during debug
                //await Task.Run(async () =>
                //{
                //    try
                //    {
                //        if (_speechRecognizer == null)
                //        {
                //            _speechRecognizer = new SpeechRecognizer();
                //            _speechRecognizer.Grammars.AddGrammarFromList("DroneCommands", new List<string>
                //            {
                //                "Take off", "Take off the drone", "Take the drone off",
                //                "Land", "Land the drone"
                //            });
                //        }
                //        try
                //        {
                //            while (true)
                //            {
                //                Dispatcher.BeginInvoke(() =>
                //                {
                //                    if (TextRecognizer.Text != "Voice: listening...")
                //                    {
                //                        TextRecognizer.Foreground = new SolidColorBrush(Colors.Green);
                //                        TextRecognizer.Text = "Voice: listening...";
                //                    }
                //                });

                //                var result = await _speechRecognizer.RecognizeAsync();

                //                //if (result.TextConfidence == SpeechRecognitionConfidence.High)
                //                if (result.Text.Length > 0)
                //                {
                //                    Dispatcher.BeginInvoke(() =>
                //                    {
                //                        switch (result.Text)
                //                        {
                //                            case "Take off":
                //                            case "Take off the drone":
                //                            case "Take the drone off":
                //                                _droneClient.TakeOff();
                //                                break;
                //                            case "Land":
                //                            case "Land the drone":
                //                                _droneClient.Land();
                //                                break;
                //                        }
                //                    });
                //                    await Task.Delay(1000);
                //                }
                //                else
                //                    await Task.Delay(500);
                //            }
                //        }
                //        catch (Exception ex)
                //        {
                //            Debug.WriteLine(ex);
                //        }

                //        Dispatcher.BeginInvoke(() =>
                //        {
                //            TextRecognizer.Foreground = new SolidColorBrush(Colors.Red);
                //            TextRecognizer.Text = "Voice: unknown";
                //        });

                //    }
                //    catch (Exception ex)
                //    {
                //        Debug.WriteLine(ex);
                //    }
                //});
            }
        }