Exemple #1
0
        void GestureDetection_RightHandBackForwardsChanged(object sender, HandPositionChangedArgs args)
        {
            switch (args.Position)
            {
            case HandPosition.Center:
                break;

            case HandPosition.Backwards:


            {
                _client.Progress(FlightMode.Progressive, pitch: 0.1f);
                DroneCommandChanged(_client, new DroneCommandChangedEventArgs {
                        CommandText = "Backwards"
                    });
            }
            break;

            case HandPosition.Forwards:


            {
                _client.Progress(FlightMode.Progressive, pitch: -0.1f);
                DroneCommandChanged(_client, new DroneCommandChangedEventArgs {
                        CommandText = "Forwards"
                    });
            }
            break;
            }
        }
Exemple #2
0
        private void ReceiverOnCommandReceived(object sender, CommandEventArgs eventArgs)
        {
            Log(eventArgs.Command);
            if (!_executeCommands)
            {
                return;
            }
            switch (eventArgs.Command)
            {
            case "takeoff":
                _client.Takeoff();
                break;

            case "land":
                _client.Land();
                break;

            case "hover":
                _client.Hover();
                break;

            case "up":
                _client.Progress(FlightMode.Progressive, gaz: 0.25f);
                break;

            case "turnleft":
                _client.Progress(FlightMode.Progressive, yaw: 0.25f);
                break;

            case "forward":
                _client.Progress(FlightMode.Progressive, pitch: -0.5f);
                break;

            case "turnright":
                _client.Progress(FlightMode.Progressive, yaw: -0.25f);
                break;

            case "down":
                _client.Progress(FlightMode.Progressive, gaz: -0.25f);
                break;

            case "left":
                _client.Progress(FlightMode.Progressive, yaw: 0.25f);
                break;

            case "right":
                _client.Progress(FlightMode.Progressive, roll: 0.05f);
                break;

            case "back":
                _client.Progress(FlightMode.Progressive, pitch: 0.5f);
                break;

            default:
                Debug.WriteLine("Unknown Command: " + eventArgs.Command);
                break;
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            var droneClient = new DroneClient("192.168.1.1");

            SleepAndPaint(droneClient);

            droneClient.Start();

            SleepAndPaint(droneClient);

            droneClient.Takeoff();

            SleepAndPaint(droneClient);


            droneClient.Progress(FlightMode.Progressive, yaw: -0.05f);

            System.Console.WriteLine("Yaw -0.05");
            SleepAndPaint(droneClient);

            droneClient.Hover();
            SleepAndPaint(droneClient);

            droneClient.Land();

            SleepAndPaint(droneClient);

            droneClient.Stop();

            SleepAndPaint(droneClient);

            System.Console.ReadLine();

            droneClient.Dispose();
        }
Exemple #4
0
        static void FlyDroneJoystick()
        {
            var joystick = new JoystickDevice();

            joystick.Initialize("/dev/input/js0");

            while (true)
            {
                joystick.ProcessEvents();
                var pitch = -joystick.AxisValues[0];
                var roll  = joystick.AxisValues[1];
                var gaz   = joystick.AxisValues[2];
                var yaw   = joystick.AxisValues[3];

                drone.Progress(FlightMode.Progressive, roll, pitch, yaw, gaz);
                Thread.Sleep(200);
            }
        }
        private void DroneControls_KeyDown(object sender, KeyEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine(e.Key);
            switch (e.Key)
            {
            case Key.Left:
                droneClient.Progress(FlightMode.Progressive, roll: -0.05f);
                break;

            case Key.Up:
                droneClient.Progress(FlightMode.Progressive, gaz: 0.25f);
                break;

            case Key.Right:
                droneClient.Progress(FlightMode.Progressive, roll: 0.05f);
                break;

            case Key.Down:
                droneClient.Progress(FlightMode.Progressive, gaz: -0.25f);
                break;

            case Key.A:
                droneClient.Progress(FlightMode.Progressive, yaw: 0.25f);
                break;

            case Key.D:
                droneClient.Progress(FlightMode.Progressive, yaw: -0.25f);
                break;

            case Key.S:
                droneClient.Progress(FlightMode.Progressive, pitch: 0.05f);
                break;

            case Key.W:
                droneClient.Progress(FlightMode.Progressive, pitch: -0.05f);
                break;

            case Key.I:
                droneClient.Takeoff();
                break;

            case Key.O:
                droneClient.Land();
                break;

            default:
                break;
            }
        }
Exemple #6
0
 /// <summary>
 /// Pitches the drone forwards
 /// </summary>
 /// <returns>Boolean Value whether the command works properly</returns>
 public bool PitchForward()
 {
     try
     {
         _client.Progress(flightMode, pitch: PITCHVAL);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemple #7
0
        /// <summary>
        /// Sends the command with its parameters to a provided DroneClient
        /// </summary>
        /// <param name="aDroneClient">Drone client to the the command to</param>
        public void Send(DroneClient aDroneClient)
        {
            switch (Command)
            {
            case Type.Progress: aDroneClient.Progress(ProgressMode, roll: Roll, pitch: Pitch, yaw: Yaw, gaz: Gaz); break;

            case Type.Takeoff: aDroneClient.Takeoff(); break;

            case Type.Hover: aDroneClient.Hover(); break;

            case Type.Land: aDroneClient.Land(); break;

            case Type.Emergency: aDroneClient.Emergency(); break;

            case Type.ResetEmergency: aDroneClient.ResetEmergency(); break;

            case Type.FlatTrim: aDroneClient.FlatTrim(); break;
            }
        }
Exemple #8
0
        void flyToObjective()
        {
            if (calculator == null)
            {
                calculator = new ControllerCalculations(analyzer.FovSize);
            }
            bool flight = true;
            var  state  = droneClient.NavigationData.State;

            if (state.HasFlag(NavigationState.Emergency))
            {
                return;
            }

            if (flight && state.HasFlag(NavigationState.Landed))
            {
                analyzer.ResultingCommand = "takeof";
                analyzer.Navigation.SetMovement(Movements.TakeOff);
                droneClient.Takeoff();
                return;
            }
            if (analyzer.Detected)
            {
                if (droneClient.NavigationData.Altitude > 0.6 || !flight)
                {
                    var width  = analyzer.FovSize.Width / 2f;
                    var change = width - analyzer.Center.X;

                    var distance = calculator.GetDistance(new System.Drawing.Size(analyzer.Width, analyzer.Height));
                    analyzer.Distance = distance;
                    analyzer.Change   = change;
                    var diff = calculator.GetDiff(distance); // (analyzer.Distance / analyzer.FovSize.Width) * 7.5f;

                    var yaw  = config.SpaceConfig.TurnSpeed * 2f / 3f;
                    var roll = config.SpaceConfig.TurnSpeed / 3f;

                    if (change > diff)
                    {
                        if (flight)
                        {
                            droneClient.Progress(FlightMode.Progressive, roll: 0 - roll, yaw: 0 - yaw);
                        }
                        analyzer.ResultingCommand = $"left {change} {diff}";
                        analyzer.Navigation.SetMovement(Movements.Left);
                    }
                    else if (change < (0 - diff))
                    {
                        if (flight)
                        {
                            droneClient.Progress(FlightMode.Progressive, roll: roll, yaw: yaw);
                        }
                        analyzer.ResultingCommand = $"right {change} {diff}";
                        analyzer.Navigation.SetMovement(Movements.Right);
                    }
                    else
                    {
                        if (distance > config.SpaceConfig.MaxDistance)
                        {
                            analyzer.ResultingCommand = $"pitch {change}";
                            analyzer.Navigation.SetMovement(Movements.Ahead);

                            if (flight)
                            {
                                droneClient.Progress(FlightMode.Progressive, pitch: -0.05f);
                            }
                        }
                        else
                        {
                            analyzer.ResultingCommand = "hover";
                            analyzer.Navigation.SetMovement(Movements.Hover);

                            step = 1;
                            Logger.LogInfo("Step 1");
                        }
                    }
                }
                else
                {
                    analyzer.Navigation.SetMovement(Movements.Up);

                    droneClient.Progress(FlightMode.Progressive, gaz: 0.25f);
                    analyzer.ResultingCommand = $"altitude {droneClient.NavigationData.Altitude}";
                }
            }
            else
            {
                analyzer.ResultingCommand = "seek";

                if (flight)
                {
                    droneClient.Progress(FlightMode.Progressive, yaw: 0.10f);
                }
            }
        }
Exemple #9
0
 /// <summary>
 /// Lets the drone fly forward
 /// </summary>
 public void Forward()
 {
     _droneClient.Progress(FlightMode.Progressive, pitch: -this.Speed);
 }
Exemple #10
0
    // Update is called once per frame
    void Update()
    {
        convertCameraData();

        updateGamepadState();

        moveStick();

        // Start or land the drone
        if (state.Buttons.Start.Equals(ButtonState.Pressed) && !startButtonPressed)
        {
            if (isLanded)
            {
                droneClient.Takeoff();
            }
            else
            {
                droneClient.Land();
            }
            isLanded           = !isLanded;
            startButtonPressed = true;
        }
        if (!state.Buttons.Start.Equals(ButtonState.Pressed))
        {
            startButtonPressed = false;
        }

        // exit application
        if (Input.GetKey("escape") || state.Buttons.Back.Equals(ButtonState.Pressed))
        {
            Application.Quit();
        }

        // Move the drone
        var pitch = -state.ThumbSticks.Left.Y;
        var roll  = state.ThumbSticks.Left.X;
        var gaz   = state.Triggers.Right - state.Triggers.Left;
        var yaw   = state.ThumbSticks.Right.X;

        droneClient.Progress(AR.Drone.Client.Command.FlightMode.Progressive, pitch: pitch, roll: roll, gaz: gaz, yaw: yaw);

        // Switch drone camera
        if (CameraForSwitchCheck.rotation.x >= SwitchRotation)
        {
            if (SecondaryRenderer.material.mainTexture != cameraTexture)
            {
                MainRenderer.material.mainTexture      = blackTexture;
                SecondaryRenderer.material.mainTexture = cameraTexture;
                switchDroneCamera(AR.Drone.Client.Configuration.VideoChannelType.Vertical);
            }
        }
        else
        {
            if (MainRenderer.material.mainTexture != cameraTexture)
            {
                SecondaryRenderer.material.mainTexture = blackTexture;
                MainRenderer.material.mainTexture      = cameraTexture;
                switchDroneCamera(AR.Drone.Client.Configuration.VideoChannelType.Horizontal);
            }
        }

        // set status text
        if (navigationData != null)
        {
            StatusText.text = string.Format("Battery: {0} % \nYaw: {1:f} \nPitch: {2:f} \nRoll: {3:f} \nAltitude: {4} m",
                                            navigationData.Battery.Percentage, navigationData.Yaw, navigationData.Pitch,
                                            navigationData.Roll, navigationData.Altitude);
        }

        // determine wifi strength
        determineWifiStrength();
    }
Exemple #11
0
 private void btnUp_Click(object sender, EventArgs e)
 {
     _droneClient.Progress(FlightMode.Progressive, gaz: 0.25f);
 }
Exemple #12
0
 private void btnUp_Click(object sender, EventArgs e)
 {
     _droneClient.Progress(ProgressiveMode.CombinedYaw, gaz: 0.25f);
 }
Exemple #13
0
 // pitch ++
 private void button5_Click(object sender, EventArgs e)
 {
     // const float PITCHVAL = 0.05f;
     _droneClient.Progress(AR.Drone.Client.Command.FlightMode.Progressive, pitch: PITCHVAL);
 }
Exemple #14
0
 public void Roll(float roll)
 {
     _droneClient.Progress(ProgressiveMode.CombinedYaw, roll);
 }
Exemple #15
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
        }
Exemple #16
0
        //head dx, sx, up, down
        private void OculusHandle()
        {
            oculusXText = "On Hold";
            oculusYText = "On Hold";
            var cameraPositionNew = OculusClient.GetOrientation();
            var delta             = headPositionStart.X - cameraPositionNew.X;
            var compare           = delta;

            if (delta < 0)
            {
                delta *= -1;
            }
            if (delta >= xThreshold)
            {
                if (compare > 0)
                {
                    oculusXText = "Right";
                    if (lastCommandSent != CommandType.TurnRight)
                    {
                        lastCommandSent = CommandType.TurnRight;
                        droneClient.Progress(Drone.Commands.FlightMode.Progressive, yaw: 0.4f);
                    }
                }
                else
                {
                    oculusXText = "Left";
                    if (lastCommandSent != CommandType.TurnLeft)
                    {
                        lastCommandSent = CommandType.TurnLeft;
                        droneClient.Progress(Drone.Commands.FlightMode.Progressive, yaw: -0.4f);
                    }
                }
                return;
            }
            delta   = headPositionStart.Y - cameraPositionNew.Y;
            compare = delta;
            if (delta < 0)
            {
                delta *= -1;
            }
            if (delta >= yThreshold)
            {
                if (compare > 0)
                {
                    oculusYText = "Up";
                    if (lastCommandSent != CommandType.GoUp)
                    {
                        lastCommandSent = CommandType.GoUp;
                        droneClient.Progress(Drone.Commands.FlightMode.Progressive, gaz: 0.4f);
                    }
                }
                else
                {
                    oculusYText = "Down";
                    if (lastCommandSent != CommandType.GoDown)
                    {
                        lastCommandSent = CommandType.GoDown;
                        droneClient.Progress(Drone.Commands.FlightMode.Progressive, gaz: -0.4f);
                    }
                }
            }
        }
Exemple #17
0
 public void MoveLeft()
 {
     droneClient.Progress(FlightMode.Progressive, yaw: 0.25f);
 }