Example #1
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;
        }
Example #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);
            }
        }