Ejemplo n.º 1
0
        private async void Controller_InputReceived(object sender, GameControllerValues args)
        {
            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {

                double X1, Y1;

                LeftReadout.Text = string.Format("X Axis {0}\nY Axis {1}\n Direction {2}\n Magnitude {3}",
                        args.LeftStick.coordinates.XAxis.ToString(),
                        args.LeftStick.coordinates.YAxis.ToString(),
                        args.LeftStick.vector.direction.ToString(),
                        args.LeftStick.vector.magnitude.ToString());
                getXY(args.LeftStick.vector, out X1, out Y1);

                MoveEyeBall(LeftEye, LeftPupil, X1, Y1);

                if (args.ButtonRBPressed)
                {
                    RightReadout.Text = string.Format("X Axis {0}\nY Axis {1}\n Direction {2}\n Magnitude {3}",
                            args.RightStick.coordinates.XAxis.ToString(),
                            args.RightStick.coordinates.YAxis.ToString(),
                            args.RightStick.vector.direction.ToString(),
                            args.RightStick.vector.magnitude.ToString());
                    getXY(args.RightStick.vector, out X1, out Y1);
                }


                MoveEyeBall(RightEye, RightPupil, X1, Y1);

            });
        }
Ejemplo n.º 2
0
        private void CarSteering(object sender, GameControllerValues e)
        {

            double LeftWheel = 0;
            double RightWheel = 0;

            LeftWheel = GetYVelocity(e.RightStick.vector);
            RightWheel = GetYVelocity(e.RightStick.vector);

            double VelocityAdjustment = GetXVelocity(e.LeftStick.vector);
            LeftWheel += VelocityAdjustment;
            RightWheel -= VelocityAdjustment;


            if (LeftWheel > 4096) { LeftWheel = 4096; }
            if (LeftWheel < -4096) { LeftWheel = -4096; }


            if (RightWheel > 4096) { RightWheel = 4096; }
            if (RightWheel < -4096) { RightWheel = -4096; }


            double maxrange = 255;
            double leftVelocity = (LeftWheel / 4096) * (maxrange);
            double rightVelocity = (RightWheel / 4096) * (maxrange);



            int leftForwards = 255, leftBackwards = 255;
            int rightForwards = 255, rightBackwards = 255;

            if (leftVelocity > 0) { leftForwards = (255 - (int)leftVelocity) - 255; }
            if (leftVelocity < 0) { leftBackwards = (int)leftVelocity; }


            if (rightVelocity > 0) { rightForwards = (255 - (int)rightVelocity) - 255; }
            if (rightVelocity < 0) { rightBackwards = (int)rightVelocity; }



            LEDDriver.SetPin(3, leftForwards);
            LEDDriver.SetPin(5, leftBackwards);

            LEDDriver.SetPin(18, rightForwards);
            LEDDriver.SetPin(16, rightBackwards);





            //double maxrange = 255;
            //leftVelocity = (leftVelocity / 4096) * (maxrange);
            //rightVelocity = (rightVelocity / 4096) * (maxrange);


            //Debug.WriteLine("left Wheel: {0}", LeftWheel.ToString());


        }
Ejemplo n.º 3
0
        private async void InputReceived(object sender, GameControllerValues args)
        {
            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                LeftStick.Text = string.Format("Left Analogue Stick\nX Axis: {0}\nY Axis :{1}", args.LeftStick.coordinates.XAxis.ToString(), args.LeftStick.coordinates.YAxis.ToString());
                RightStick.Text = string.Format("Right Analogue Stick\nX Axis: {0}\nY Axis :{1}", args.RightStick.coordinates.XAxis.ToString(), args.RightStick.coordinates.YAxis.ToString());
            });

            // We've received 

        }
Ejemplo n.º 4
0
        private void InputReceived(object sender, GameControllerValues e)
        {
            //TankSteering(sender, e);
            CarSteering(sender, e);
            //BikeStearing(sender, e);




            SoundHorn(e);

            LEDDriver.CommitAllPins();

        }
        private async void Controller_InputReceived(object sender, GameControllerValues args)
        {
            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {

                double X1, X2;

                LeftReadout.Text = string.Format("X Axis {0}\nY Axis {1}\n Direction {2}\n Magnitude {3}",
                        args.LeftStick.coordinates.XAxis.ToString(),
                        args.LeftStick.coordinates.YAxis.ToString(),
                        args.LeftStick.vector.direction.ToString(),
                        args.LeftStick.vector.magnitude.ToString());
                getXY(args.LeftStick.vector, out X1, out X2);
                LeftAnalogueIndicator.X1 = X1;
                LeftAnalogueIndicator.Y1 = X2;





                RightReadout.Text = string.Format("X Axis {0}\nY Axis {1}\n Direction {2}\n Magnitude {3}",
                        args.RightStick.coordinates.XAxis.ToString(),
                        args.RightStick.coordinates.YAxis.ToString(),
                        args.RightStick.vector.direction.ToString(),
                        args.RightStick.vector.magnitude.ToString());
                getXY(args.RightStick.vector, out X1, out X2);
                RightAnalogueIndicator.X1 = X1;
                RightAnalogueIndicator.Y1 = X2;



                // Convert Range to negative and positive
                // Negative values are braking values
                // Positive values are throttle values
                double adjustedRudder = args.Rudder - 32768;
                double throttle = 0;
                double brake = 0;


                if (adjustedRudder > 0)
                {
                    brake = (adjustedRudder / 32768) * 4095;
                }
                else if (adjustedRudder < 0)
                {
                    throttle = 4095 - (((adjustedRudder / 32768) * 4095) + 4095);
                }

                double Forwards = 300, Backwards = 300;

                if (brake > 0) { Backwards = (brake / 4096) * 300; } else { Backwards = 0; }
                if (throttle > 0) { Forwards = (throttle / 4096) * 300; } else { Forwards = 0; }

                Throttle.Y2 = 300-Forwards;
                Brake.Y2 = 300-Backwards;

                ThrottleReadout.Text = string.Format("Rudder Value {0}\nThrottle Value {1}\nBrake Value {2}", args.Rudder.ToString(), throttle.ToString(), brake.ToString());


                CalculateVelocities_Track(args);
                //CalculateVelocities_Mix(args);

            });
        }
        private void CalculateVelocities_Track(GameControllerValues args)
        {
            LeftWheelVelocity.Value = GetYVelocity(args.LeftStick.vector);
            RightWheelVelocity.Value = GetYVelocity(args.RightStick.vector); 

        }
        private void CalculateVelocities_Mix(GameControllerValues args)
        {

            //double xAxisVelocity = 0;
            //double rotationalVelocity = 0;

            double LeftWheel = 0;
            double RightWheel = 0;

            LeftWheel = GetYVelocity(args.RightStick.vector);
            RightWheel = GetYVelocity(args.RightStick.vector);

            double VelocityAdjustment = GetXVelocity(args.LeftStick.vector);
            LeftWheel += VelocityAdjustment;
            RightWheel -= VelocityAdjustment;

            ///double maxMag = 4095;
            //double maxMag = 2095;
            //LeftWheel = (LeftWheel > 0) ? Math.Max(LeftWheel, maxMag) : Math.Min(LeftWheel, 0-maxMag);
            ///RightWheel = (RightWheel > 0) ? Math.Max(RightWheel, maxMag) : Math.Min(RightWheel, 0-maxMag);

            LeftWheelVelocity.Value = LeftWheel;
            RightWheelVelocity.Value = RightWheel;

        }
Ejemplo n.º 8
0
 private void SoundHorn(GameControllerValues e)
 {
     if (e.ButtonBPressed)
     {
         LEDDriver.SetPin(1, 127);
     }
     else
     {
         LEDDriver.SetPin(1, 0);
     }
 }
Ejemplo n.º 9
0
        private void TankSteering(object sender, GameControllerValues e)
        {
            double leftVelocity = GetYVelocity(e.LeftStick.vector);
            double rightVelocity = GetYVelocity(e.RightStick.vector);


            double maxrange = 255;
            leftVelocity = (leftVelocity / 4096) * (maxrange);
            rightVelocity = (rightVelocity / 4096) * (maxrange);

            //Debug.WriteLine("Left Wheel: {0}. Right Wheel: {1}", leftVelocity.ToString(), rightVelocity.ToString());

            int leftForwards = 255, leftBackwards = 255;
            int rightForwards = 255, rightBackwards = 255;

            if (leftVelocity > 0) { leftForwards = (255 - (int)leftVelocity) - 255; }
            if (leftVelocity < 0) { leftBackwards = (int)leftVelocity; }


            if (rightVelocity > 0) { rightForwards = (255 - (int)rightVelocity) - 255; }
            if (rightVelocity < 0) { rightBackwards = (int)rightVelocity; }


            //Debug.WriteLine("Left Wheel Forwards: {0}. Left Wheel Backwards: {1}. Right Wheel Forwards: {2}. Right Wheel Backwards: {3}",  leftForwards.ToString(), leftBackwards.ToString(), rightForwards.ToString(), rightBackwards.ToString());

            LEDDriver.SetPin(3, leftForwards);
            LEDDriver.SetPin(5, leftBackwards);

            LEDDriver.SetPin(18, rightForwards);
            LEDDriver.SetPin(16, rightBackwards);

        }
Ejemplo n.º 10
0
        private void CalculateVelocities_Mix(GameControllerValues args)
        {

            //double xAxisVelocity = 0;
            //double rotationalVelocity = 0;



            ///double maxMag = 4095;
            //double maxMag = 2095;
            //LeftWheel = (LeftWheel > 0) ? Math.Max(LeftWheel, maxMag) : Math.Min(LeftWheel, 0-maxMag);
            ///RightWheel = (RightWheel > 0) ? Math.Max(RightWheel, maxMag) : Math.Min(RightWheel, 0-maxMag);

            //LeftWheelVelocity.Value = LeftWheel;
            //RightWheelVelocity.Value = RightWheel;

        }