Пример #1
0
        /// <summary>
        /// Sendet rohe IInputDevice Daten an die Drohne.
        /// </summary>
        /// <param name="data"></param>
        public void SendTargetData(TargetData data)
        {
            // Rohe Daten umwandeln in richtigen Interval
            data.Pitch           *= MaxPitch;
            data.Roll            *= MaxRoll;
            data.RotationalSpeed *= MaxRotationalSpeed;

            // Offset hinzufügen
            data.Pitch           += PitchOffset;
            data.Roll            += RollOffset;
            data.RotationalSpeed += RotationalOffset;

            data.Thrust *= MaxThrust;

            // Daten setzen und senden
            TargetData = data;
            if (OnTargetDataChanged != null)
            {
                OnTargetDataChanged(this, EventArgs.Empty);
            }

            if (drone.Data.State == DroneState.Armed || drone.Data.State == DroneState.Flying)
            {
                drone.SendMovementData(data.Pitch, data.Roll, data.RotationalSpeed, (int)data.Thrust);
            }
        }
Пример #2
0
        /// <summary>
        /// Sendet rohe IInputDevice Daten an die Drohne.
        /// </summary>
        /// <param name="data"></param>
        public void SendTargetData(TargetData data)
        {
            RawTargetData = data;

            data.Roll   = (float)MapInputOneToOne(data.Roll, 0.5, RollExp);
            data.Pitch  = (float)MapInputOneToOne(data.Pitch, 0.5, PitchExp);
            data.Yaw    = (float)MapInputOneToOne(data.Yaw, 0.5, YawExp);
            data.Thrust = (float)MapThrust(data.Thrust);

            data.Roll  *= RollScale;
            data.Pitch *= PitchScale;
            data.Yaw   *= YawScale;

            data.Roll   *= 500;
            data.Pitch  *= 500;
            data.Yaw    *= 200;
            data.Thrust *= ThrustMax;

            // Daten setzen und senden
            TargetData = data;
            OnTargetDataChanged?.Invoke(this, EventArgs.Empty);

            if (drone.Data.State.AreMotorsRunning())
            {
                drone.SendMovementData((short)data.Roll, (short)data.Pitch, (short)data.Yaw, (short)data.Thrust);
            }
        }
Пример #3
0
        public void Update(InputManager manager)
        {
            try
            {
                if (!IsConnected)
                {
                    return;
                }

                currentState = controller.GetState();

                if (CheckButtonPressed(GamepadButtonFlags.A))
                {
                    manager.SendClear();
                }

                if (CheckButtonPressed(GamepadButtonFlags.B))
                {
                    manager.StopDrone();
                }

                if (CheckButtonPressed(GamepadButtonFlags.Y))
                {
                    manager.ToogleArmStatus();
                }

                float deadZone = 0.075f;
                if (!manager.DeadZone)
                {
                    deadZone = 0;
                }

                TargetData target = new TargetData();
                target.Roll   = DeadZone.Compute(currentState.Gamepad.RightThumbX, short.MaxValue, deadZone);
                target.Pitch  = -DeadZone.Compute(currentState.Gamepad.RightThumbY, short.MaxValue, deadZone);
                target.Yaw    = DeadZone.Compute(currentState.Gamepad.LeftThumbX, short.MaxValue, deadZone);
                target.Thrust = DeadZone.Compute(currentState.Gamepad.LeftThumbY + short.MaxValue, short.MaxValue * 2, deadZone);

                float x = GetButtonValue(GamepadButtonFlags.DPadRight) - GetButtonValue(GamepadButtonFlags.DPadLeft);
                float y = -GetButtonValue(GamepadButtonFlags.DPadDown) - GetButtonValue(GamepadButtonFlags.DPadUp);
                target.Roll  += x * 0.1f;
                target.Pitch += y * 0.1f;


                manager.SendTargetData(target);

                lastState   = currentState;
                firstUpdate = false;

                HasError = false;
            }
            catch (Exception e)
            {
                HasError = true;
                Log.Error(e);
            }
        }
Пример #4
0
        public void Update(InputManager manager)
        {
            try
            {
                if (!UpdateState())
                {
                    return;
                }

                if (CheckButtonPressed(2))
                {
                    manager.SendClear();
                }

                if (CheckButtonPressed(1))
                {
                    manager.StopDrone();
                }

                if (CheckButtonPressed(0))
                {
                    manager.ArmDrone();
                }

                if (CheckButtonReleased(0))
                {
                    manager.DisarmDrone();
                }

                float deadZone = 0.075f;
                if (!manager.DeadZone)
                {
                    deadZone = 0;
                }

                const int  maxValue = UInt16.MaxValue / 2;
                TargetData target   = new TargetData();
                target.Roll   = DeadZone.Compute(currentState.X - maxValue, maxValue, deadZone);
                target.Pitch  = DeadZone.Compute(currentState.Y - maxValue, maxValue, deadZone);
                target.Yaw    = DeadZone.Compute(currentState.RotationZ - maxValue, maxValue, deadZone);
                target.Thrust = DeadZone.Compute(UInt16.MaxValue - currentState.Z, UInt16.MaxValue, deadZone);

                manager.SendTargetData(target);

                lastState = currentState;
                HasError  = false;
            }
            catch (Exception e)
            {
                HasError = true;
                Log.Error(e);
            }
        }
Пример #5
0
        public void Update(InputManager manager)
        {
            if (!IsConnected)
                return;

            currentState = controller.GetState();

            if (CheckButtonPressed(GamepadButtonFlags.A))
                manager.SendClear();

            if (CheckButtonPressed(GamepadButtonFlags.B))
                manager.StopDrone();

            if (CheckButtonPressed(GamepadButtonFlags.Y))
                manager.ToogleArmStatus();

            float deadZone = 0.075f;
            if (!manager.DeadZone)
                deadZone = 0;

            TargetData target = new TargetData();
            target.Roll = DeadZone.Compute(currentState.Gamepad.LeftThumbX, short.MaxValue, deadZone);
            target.Pitch = -DeadZone.Compute(currentState.Gamepad.LeftThumbY, short.MaxValue, deadZone);
            target.RotationalSpeed = DeadZone.Compute(currentState.Gamepad.RightThumbX, short.MaxValue, deadZone);
            target.Thrust = DeadZone.Compute(currentState.Gamepad.RightThumbY + short.MaxValue, short.MaxValue * 2, deadZone);

            float x = GetButtonValue(GamepadButtonFlags.DPadRight) - GetButtonValue(GamepadButtonFlags.DPadLeft);
            float y = -GetButtonValue(GamepadButtonFlags.DPadDown) - GetButtonValue(GamepadButtonFlags.DPadUp);
            target.Roll += x * 0.1f;
            target.Pitch += y * 0.1f;


            manager.SendTargetData(target);

            lastState = currentState;
            firstUpdate = false;
        }
Пример #6
0
        public void Update(InputManager manager)
        {
            if (!UpdateState())
                return;

            if (CheckButtonPressed(2))
                manager.SendClear();

            if (CheckButtonPressed(1))
                manager.StopDrone();

            if (CheckButtonPressed(0))
                manager.ArmDrone();

            if (CheckButtonReleased(0))
                manager.DisarmDrone();

            float deadZone = 0.075f;
            if (!manager.DeadZone)
                deadZone = 0;

            const int maxValue = UInt16.MaxValue / 2;
            TargetData target = new TargetData();
            target.Roll = DeadZone.Compute(currentState.X - maxValue, maxValue, deadZone);
            target.Pitch = DeadZone.Compute(currentState.Y - maxValue, maxValue, deadZone);
            target.RotationalSpeed = DeadZone.Compute(currentState.RotationZ - maxValue, maxValue, deadZone);
            target.Thrust = DeadZone.Compute(UInt16.MaxValue - currentState.Z, UInt16.MaxValue, deadZone);

            manager.SendTargetData(target);

            lastState = currentState;
        }
Пример #7
0
        /// <summary>
        /// Sendet rohe IInputDevice Daten an die Drohne.
        /// </summary>
        /// <param name="data"></param>
        public void SendTargetData(TargetData data)
        {
            // Rohe Daten umwandeln in richtigen Interval
            data.Pitch *= MaxPitch;
            data.Roll *= MaxRoll;
            data.RotationalSpeed *= MaxRotationalSpeed;

            // Offset hinzufügen
            data.Pitch += PitchOffset;
            data.Roll += RollOffset;
            data.RotationalSpeed += RotationalOffset;

            data.Thrust *= MaxThrust;

            // Daten setzen und senden
            TargetData = data;
            if (OnTargetDataChanged != null)
                OnTargetDataChanged(this, EventArgs.Empty);

            if (drone.Data.State == DroneState.Armed || drone.Data.State == DroneState.Flying)
                drone.SendMovementData(data.Pitch, data.Roll, data.RotationalSpeed, (int)data.Thrust);
        }