public bool TakeOff() { if (!enabled) { return(false); } if (droneClient.IsActive && !droneClient.IsFlying) { Logger.WriteLine("TakeOff"); if (detectFlyStatusTimer != null) { detectFlyStatusTimer.Stop(); } detectFlyStatusTimer = new DispatcherTimer(); detectFlyStatusTimer.Interval = TimeSpan.FromMilliseconds(200); detectFlyStatusTimer.Tick += (object sender, EventArgs e) => { if (droneClient.IsFlying) { if (OnFlyStopStart != null) { OnFlyStopStart(true); } detectFlyStatusTimer.Stop(); } }; detectFlyStatusTimer.Start(); droneClient.TakeOff(); // commandTimer.Start(); return(true); } return(false); }
private void TakeOffLandButton_Click(object sender, RoutedEventArgs e) { if (_droneClient.IsFlying) { _droneClient.Land(); } else { _droneClient.TakeOff(); } UpdateDisplay(); }
private void TakeOff_Click(object sender, RoutedEventArgs e) { if (_droneClient.IsFlying()) { _droneClient.Land(); TakeOffButton.Content = "Take off"; } else { _droneClient.TakeOff(); TakeOffButton.Content = "Land"; } }
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; }
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); } }); } }