コード例 #1
0
        /** Singleton instance and entry into while loop that runs the desired program*/
        public static void Main()
        {
            /* Tracking gamepad buttons states for single press captures*/
            bool LastBtn2 = false;
            bool LastBtn3 = false;

            /* Forword/Backward Scalor */
            const float kScalarX = 0.50f;
            /* Left/Right Scalor */
            const float kScalarY = 0.50f;
            /* Turning Scalor */
            const float kScalarTwist = 0.30f;
            /* Ramp Rate */
            const float kVoltageRampSec = 0.2f;

            /* Configure Talons to operate in percentage VBus mode, and Ramp Up Voltage*/
            foreach (CTRE.TalonSrx temp in Talons)
            {
                temp.SetControlMode(TalonSrx.ControlMode.kPercentVbus);
                temp.SetVoltageRampRate(12.0f / kVoltageRampSec);
            }

            /* Clear DisplayModule */
            LCDDisplay.ClearSprites();
            /* Fill the screen with the target object (Top half magenta, bottom half green) */
            LCDDisplay.AddRectSprite(CTRE.HERO.Module.DisplayModule.Color.Magenta, 0, 0, 160 / 2, 128);
            LCDDisplay.AddRectSprite(CTRE.HERO.Module.DisplayModule.Color.Green, 160 / 2, 0, 160 / 2, 128);

            while (true)
            {
                /* Keep robot enabled if gamepad is connected and in 'D' mode */
                if (GamePad.GetConnectionStatus() == CTRE.UsbDeviceConnection.Connected)
                {
                    CTRE.Watchdog.Feed();
                }

                /* Allow user to enable/disable Display Module backlight
                 * Button 2 (A) Disables the backlight
                 * Button 3 (B) Enables the backlight */
                bool Btn2 = GamePad.GetButton(2);
                bool Btn3 = GamePad.GetButton(3);
                if (Btn2 & !LastBtn2)
                {
                    LCDDisplay.BacklightEnable = false;
                }
                else if (Btn3 & !LastBtn3)
                {
                    LCDDisplay.BacklightEnable = true;
                }
                LastBtn2 = Btn2;
                LastBtn3 = Btn3;

                /* Regular mecanum drive that is scaled and Gamepad joysticks have been adjusted */
                float X = GamePad.GetAxis(0);
                /* Invert gamepad so forward is truly forward */
                float Y     = -1 * GamePad.GetAxis(1);
                float Twist = GamePad.GetAxis(2);
                MecanumDrive(Y * kScalarY, X * kScalarX, Twist * kScalarTwist);
            }
        }
コード例 #2
0
        /** Singleton instance and entry into while loop that runs the desired program*/
        public static void Main()
        {
            /* Tracking gamepad buttons states for single press captures*/
            bool LastBtn1 = false;
            bool LastBtn3 = false;
            bool LastBtn2 = false;

            /* Forword/Backward Scalor */
            const float kScalarX = 0.50f;
            /* Left/Right Scalor */
            const float kScalarY = 0.50f;
            /* Turning Scalor */
            const float kScalarTwist = 0.30f;
            /* Ramp Rate */
            const float kVoltageRampSec = 0.25f;

            /* Configure Talons to operate in percentage VBus mode, and Ramp Up Voltage*/
            foreach (TalonSRX temp in Talons)
            {
                temp.Set(ControlMode.PercentOutput, 0);
                temp.ConfigOpenloopRamp(kVoltageRampSec);
            }

            /* Clear DisplayModule */
            LCDDisplay.ClearSprites();
            LCDDisplay.BacklightEnable = false;
            /* Fill the screen with the target object (Top half magenta, bottom half green) */
            LCDDisplay.AddRectSprite(DisplayModule.Color.Magenta, 0, 0, 160 / 2, 128);
            LCDDisplay.AddRectSprite(DisplayModule.Color.Green, 160 / 2, 0, 160 / 2, 128);

            int     colorDelay = 0;
            int     i          = 0;
            Boolean On         = false;
            Boolean LEDEnable  = true;

            while (true)
            {
                /* Keep robot enabled if gamepad is connected and in 'D' mode */
                if (gamepad.GetConnectionStatus() == CTRE.Phoenix.UsbDeviceConnection.Connected)
                {
                    CTRE.Phoenix.Watchdog.Feed();
                }

                /* Allow user to enable/disable Display Module backlight
                 * Button 2 (A) Disables the backlight
                 * Button 3 (B) Enables the backlight */
                bool Btn1 = gamepad.GetButton(1);
                bool Btn3 = gamepad.GetButton(3);
                if (Btn1 & !LastBtn1)
                {
                    LCDDisplay.BacklightEnable = false;
                }
                else if (Btn3 & !LastBtn3)
                {
                    LCDDisplay.BacklightEnable = true;
                }
                LastBtn1 = Btn1;
                LastBtn3 = Btn3;

                /* Enable/Disable LED's */
                bool Btn2 = gamepad.GetButton(2);
                if (Btn2 & !LastBtn2)
                {
                    LEDEnable = !LEDEnable;
                }
                LastBtn2 = Btn2;

                if (gamepad.GetConnectionStatus() == CTRE.Phoenix.UsbDeviceConnection.Connected)
                {
                    if (LEDEnable)
                    {
                        colorDelay++;
                        if (colorDelay >= 15)
                        {
                            _ColorSequencer.Process();
                            /* You can change the sequence in ColorSequencer.cs by ordering the premade colors or creating your own values */
                            _LEDStripController.Red  = _ColorSequencer.Red;
                            _LEDStripController.Blue = _ColorSequencer.Blue;
                            _LEDStripController.Grn  = _ColorSequencer.Green;
                            colorDelay = 0;
                        }
                    }
                    else
                    {
                        _LEDStripController.Red  = 0;
                        _LEDStripController.Blue = 0;
                        _LEDStripController.Grn  = 0;
                    }
                }

                if (gamepad.GetConnectionStatus() == CTRE.Phoenix.UsbDeviceConnection.NotConnected || _Battery.IsLow())
                {
                    /* Flash RED ??? */
                    i++;
                    if (i >= 200)
                    {
                        On = !On;
                        i  = 0;
                    }
                    /* Decide if strip is white or off */
                    if (On == true)
                    {
                        _LEDStripController.Red  = 1;
                        _LEDStripController.Blue = 0;
                        _LEDStripController.Grn  = 0;
                    }
                    else if (On == false)
                    {
                        _LEDStripController.Red  = 0;
                        _LEDStripController.Blue = 0;
                        _LEDStripController.Grn  = 0;
                    }
                }

                _LEDStripController.Process();

                /* Regular mecanum drive that is scaled and Gamepad joysticks have been adjusted */
                float X = gamepad.GetAxis(0);
                /* Invert gamepad so forward is truly forward */
                float Y     = -1 * gamepad.GetAxis(1);
                float Twist = gamepad.GetAxis(2);
                MecanumDrive(Y * kScalarY, X * kScalarX, Twist * kScalarTwist);
            }
        }