Ejemplo n.º 1
0
 private void btnReset_Click(object sender, EventArgs e)
 {
     _droneClient.ResetEmergency();
 }
Ejemplo n.º 2
0
 private void buttonResetEmergency_Click(object sender, EventArgs e)
 {
     droneClient.ResetEmergency();
 }
Ejemplo n.º 3
0
 private void ResetEmergency_Click(object sender, RoutedEventArgs e)
 {
     _droneClient.ResetEmergency();
     UpdateDisplay();
 }
Ejemplo n.º 4
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.º 5
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            InitializeLocationManager();

            SetContentView(Resource.Layout.Main);

            FindViewById <Button>(Resource.Id.MyButtonLand).Click    += LandButtonClick;
            FindViewById <Button>(Resource.Id.ButtonEmergency).Click += EmergencyButtonClicked;
            FindViewById <Button>(Resource.Id.buttonReset).Click     += (sender, args) => _client.ResetEmergency();
            _checkBox = FindViewById <CheckBox>(Resource.Id.executeCommandsCheckBox);
            _checkBox.CheckedChange += CheckBoxOnCheckedChange;

            _logTextView       = FindViewById <TextView>(Resource.Id.logTextView);
            _dronStateTextView = FindViewById <TextView>(Resource.Id.droneStateTextView);
            _websocketTextView = FindViewById <TextView>(Resource.Id.serviceStateTextView);

            _client = new DroneClient("192.168.1.248");
            _client.Start();

            //_client.NavigationDataAcquired += ClientOnNavigationDataAcquired;

            _receiver = new CommandReceiver();
            _receiver.CommandReceived       += ReceiverOnCommandReceived;
            _receiver.WebSocketStateChanged += ReceiverOnWebSocketStateChanged;
            _receiver.Start();

            var droneConnectionChecker = new Thread(ConnectionCheckRunner)
            {
                Name = "Drone Checker"
            };

            droneConnectionChecker.Start();
        }
Ejemplo n.º 6
0
 public void ResetEmergency()
 {
     _droneClient.ResetEmergency();
 }
Ejemplo n.º 7
0
        void DroneControl(object sender)
        {
            int  expiration = Properties.Settings.Default.AutoPilotExpiration;
            bool useQ       = Properties.Settings.Default.UseAutoPilot;

            _autopilot.Active = useQ;

            float _lrfb = Properties.Settings.Default.DefaultLRFBSpeed;
            float _yaw  = Properties.Settings.Default.DefaultYawSpeed;
            float _gaz  = Properties.Settings.Default.DefaultGazSpeed;

            #region // engine
            if (sender == "v")
            {
                _droneClient.FlatTrim();
                _autopilot.ClearObjectives();

                _droneClient.Takeoff();
            }
            ;
            if (sender == "n")
            {
                _autopilot.ClearObjectives();
                _droneClient.Emergency();
            }
            ;
            if (sender == "m")
            {
                _droneClient.ResetEmergency();
            }
            ;
            if (sender == "b")
            {
                _autopilot.ClearObjectives();
                _droneClient.Land();
            }
            ;
            #endregion

            _autopilot.Active = true;

            // navigation
            #region left right up down and hover
            //if (sender == btnLeft || sender == btnRight)
            //{
            //    if (useQ)
            //    {
            //        _autopilot.EnqueueObjective(Objective.Create(expiration, new SetRoll(
            //            (sender == btnLeft ? -_lrfb : _lrfb)
            //        )));
            //    }
            //    else
            //    {
            //        _droneClient.Progress(FlightMode.Progressive,
            //            roll: (sender == btnLeft ? -_lrfb : _lrfb)
            //        );
            //    }
            //}

            if (sender == "a")
            {
                if (useQ)
                {
                    _autopilot.EnqueueObjective(Objective.Create(expiration, new SetRoll(-_lrfb)));
                }
                else
                {
                    _droneClient.Progress(FlightMode.Progressive, roll: -_lrfb);
                }
            }
            ;
            if (sender == "d")
            {
                if (useQ)
                {
                    _autopilot.EnqueueObjective(Objective.Create(expiration, new SetRoll(_lrfb)));
                }
                else
                {
                    _droneClient.Progress(FlightMode.Progressive, roll: _lrfb);
                }
            }
            ;
            if (sender == "w")
            {
                if (useQ)
                {
                    _autopilot.EnqueueObjective(Objective.Create(expiration, new SetPitch(-_lrfb)));
                }
                else
                {
                    _droneClient.Progress(FlightMode.Progressive, pitch: -_lrfb);
                }
            }
            ;
            if (sender == "s")
            {
                if (useQ)
                {
                    _autopilot.EnqueueObjective(Objective.Create(expiration, new SetPitch(_lrfb)));
                }
                else
                {
                    _droneClient.Progress(FlightMode.Progressive, pitch: _lrfb);
                }
            }
            ;

            if (sender == "x")
            {
                if (useQ)
                {
                    _autopilot.EnqueueObjective(
                        Objective.Create(expiration,
                                         new VelocityX(0.0f),
                                         new VelocityY(0.0f),
                                         new Altitude(1.0f)
                                         ));
                }
                else
                {
                    _droneClient.Hover();
                }
            }
            #endregion

            #region yaw left and right
            if (sender == "j")
            {
                if (useQ)
                {
                    _autopilot.EnqueueObjective(Objective.Create(expiration, new SetYaw(-_yaw)));
                }
                else
                {
                    _droneClient.Progress(FlightMode.Progressive, yaw: -_yaw);
                }
            }
            ;
            if (sender == "l")
            {
                if (useQ)
                {
                    _autopilot.EnqueueObjective(Objective.Create(expiration, new SetYaw(_yaw)));
                }
                else
                {
                    _droneClient.Progress(FlightMode.Progressive, yaw: _yaw);
                }
            }
            ;
            #endregion

            #region gaz up and down
            if (sender == "i")
            {
                if (useQ)
                {
                    _autopilot.EnqueueObjective(Objective.Create(expiration, new SetGaz(_gaz)));
                }
                else
                {
                    _droneClient.Progress(FlightMode.Progressive, gaz: _gaz);
                }
                //_droneClient.Hover();
            }
            ;
            if (sender == "k")
            {
                if (useQ)
                {
                    _autopilot.EnqueueObjective(Objective.Create(expiration, new SetGaz(-_gaz)));
                }
                else
                {
                    _droneClient.Progress(FlightMode.Progressive, gaz: -_gaz);
                }
            }
            ;
            #endregion
        }
Ejemplo n.º 8
0
 public void ResetEmergency()
 {
     _client.ResetEmergency();
 }