Example #1
0
        public void run()
        {
            Loop10Ms();

            //if (_gamepad.GetConnectionStatus() == CTRE.UsbDeviceConnection.Connected) // check if gamepad is plugged in OR....
            if (_gamepad.GetButton(kEnableButton)) // check if bottom left shoulder buttom is held down.
            {
                /* then enable motor outputs*/
                CTRE.Watchdog.Feed();
            }
        }
Example #2
0
        public static void Main()
        {
            CTRE.UsbHostDevice.GetInstance().SetSelectableXInputFilter(CTRE.UsbHostDevice.SelectableXInputFilter.BothDInputAndXInput);
            /* loop forever */
            while (true)
            {
                /* get buttons */
                for (uint i = 1; i < 20; ++i)
                {
                    Buttons[i].last = Buttons[i].now;
                    Buttons[i].now  = _gamepad.GetButton(i);
                }

                /* if button one was pressed, toggles field oriented*/
                FieldOriented1 = Buttons[0].WasPressed() ? !FieldOriented1 : FieldOriented1;

                /* kills drivetrain if button 2 is pressed or held */
                if (Buttons[1].now)
                {
                    motorA.Set(0);
                    motorB.Set(0);
                    motorC.Set(0);
                    motorA.ConfigNeutralMode(CTRE.TalonSrx.NeutralMode.Brake);
                    motorB.ConfigNeutralMode(CTRE.TalonSrx.NeutralMode.Brake);
                    motorC.ConfigNeutralMode(CTRE.TalonSrx.NeutralMode.Brake);
                    EStop = true;
                }

                /* turns off estop mode if button 10 was pressed*/
                if (Buttons[9].WasPressed())
                {
                    EStop = false;
                    motorA.ConfigNeutralMode(motorAInitialNeutralMode);
                    motorB.ConfigNeutralMode(motorBInitialNeutralMode);
                    motorC.ConfigNeutralMode(motorCInitialNeutralMode);
                }

                /* resets yaw if button six was pressed*/
                if (Buttons[5].WasPressed())
                {
                    try
                    {
                        Pidgy.SetYaw(0);
                    }
                    catch (Exception) { }
                }

                /* adjust orientation by 120 degrees if button three was pressed*/
                Orientation += Buttons[2].WasPressed() ? (float)System.Math.PI * 2 / 3 : 0;

                /*adjust orientation back by 120 degrees if button four was pressed*/
                Orientation -= Buttons[3].WasPressed() ? (float)System.Math.PI * 2 / 3 : 0;

                /* adjust orientation by 180 degrees if button five was pressed*/
                Orientation += Buttons[4].WasPressed() ? (float)System.Math.PI : 0;

                /* drive robot using gamepad */
                Drive();
                /* print whatever is in our string builder */
                Debug.Print(stringBuilder.ToString());
                stringBuilder.Clear();
                /* feed watchdog to keep Talon's enabled */
                CTRE.Watchdog.Feed();
                /* run this task every 20ms */
                Thread.Sleep(20);
            }
        }