예제 #1
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);
            }
        }
예제 #2
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);
            }
        }