Example #1
0
        public void updateConnected(bool connected)
        {
            String value = connected ? "Connected" : "No Gamepad";

            if (cd_connected.valueChanged(value))
            {
                _labelConnected.SetText(value);
                _labelConnected.SetColor(connected ? DisplayModule.Color.Green : DisplayModule.Color.Red);
            }
        }
Example #2
0
        public static void Main()
        {
            /* Initialize Display Module elements */
            InitDisplayModule();

            /* Initialize Talon and Victor with various configurations */
            InitMotors();

            /* LED Variables */
            float   _Brightness = 0.25f; /* Default LED Brightness */
            Boolean On          = true;  /* Color Flashing state */
            byte    i           = 0;     /* Color Duration track variable for flashing */
            int     colorDelay  = 0;     /* Color Duration track variable for Sequence speed */

            /* State variables */
            DriveState MotionState    = DriveState.MotionMagicTalon;
            LEDState   OperationState = LEDState.Pigeon;

            /* Buttons and boolean for motor control */
            Boolean lastButton1 = false;
            Boolean lastButton2 = false;
            Boolean lastButton3 = false;
            Boolean lastbutton4 = false;

            while (true)
            {
                /* Check gamepad connection */
                if (_Gamepad.GetConnectionStatus() == CTRE.Phoenix.UsbDeviceConnection.Connected)
                {
                    OperationState = LEDState.Controller;
                }
                else
                {
                    OperationState = LEDState.Pigeon;
                }

                if (OperationState == LEDState.Controller)
                {
                    CTRE.Phoenix.Watchdog.Feed();

                    if (_Battery.IsLow())
                    {
                        _labelTitle.SetText("Low voltage");
                        _labelTitle.SetColor(DisplayModule.Color.Red);
                    }
                    else
                    {
                        _labelTitle.SetText("Controller");
                        _labelTitle.SetColor(DisplayModule.Color.Green);
                    }

                    /* Get gamepad values */
                    float LeftX  = _Gamepad.GetAxis(0);
                    float LeftY  = _Gamepad.GetAxis(1);
                    float RightY = _Gamepad.GetAxis(5);
                    float RightX = _Gamepad.GetAxis(2);

                    /* Deadband gamepad values */
                    CTRE.Phoenix.Util.Deadband(ref LeftX);
                    CTRE.Phoenix.Util.Deadband(ref LeftY);
                    CTRE.Phoenix.Util.Deadband(ref RightX);
                    CTRE.Phoenix.Util.Deadband(ref RightY);

                    /* Update Guages */
                    UpdateGauge(_leftX, LeftX);
                    UpdateGauge(_leftY, LeftY);
                    UpdateGauge(_rightX, RightX);
                    UpdateGauge(_rightY, RightY);

                    /* Update Crosshairs */
                    _leftCrossHair.SetPosition((int)(30 + 15 * LeftX), 100 + (int)(15 * LeftY));
                    _rightCrossHair.SetPosition((int)(100 + 15 * RightX), 100 + (int)(15 * RightY));

                    /* Get single button presses to control MotionState */
                    Boolean Button1 = _Gamepad.GetButton(1);
                    Boolean Button2 = _Gamepad.GetButton(2);
                    Boolean Button3 = _Gamepad.GetButton(3);
                    Boolean Button4 = _Gamepad.GetButton(4);
                    if (Button1 && !lastButton1)
                    {
                        MotionState = DriveState.MotionMagicTalon;
                    }
                    else if (Button2 && !lastButton2)
                    {
                        MotionState = DriveState.PercentOutputBoth;
                    }
                    else if (Button3 && !lastButton3)
                    {
                        MotionState = DriveState.MotionMagicVictor;
                    }
                    else if (Button4 && !lastbutton4)
                    {
                        MotionState = DriveState.SensorReset;
                    }
                    lastButton1 = Button1;
                    lastButton2 = Button2;
                    lastButton3 = Button3;
                    lastbutton4 = Button4;

                    /* Controls Motoroutput based on MotionState */
                    MotorDriveControl(-LeftY, MotionState);


                    if (LeftX != 0 || LeftY != 0)
                    {
                        /** Left joystick in use, stop color cycling and give user control */

                        /* Grab brightness from the right joystick ([-1,1] + 1 * 0.5 => [0,1]) */
                        float Brightness = (RightY - 1f) * -0.5f;
                        _Brightness = Brightness;

                        /* Update LED strip with left joystick, right joystick, and brightness */
                        UpdateLedStrip(Brightness, LeftX, LeftY);
                    }
                    else
                    {
                        /** Left joystick not in use, start color cycling */

                        /* You can change the sequence in ColorSequencer.cs by ordering the premade colors or creating your own values */
                        colorDelay++;
                        if (colorDelay >= 3)
                        {
                            _ColorSequencer.Process();
                            colorDelay = 0;
                        }

                        /* Go through a color sequence at half brightness when idle */
                        UpdateLedStrip(_Brightness, _ColorSequencer.Red, _ColorSequencer.Green, _ColorSequencer.Blue);
                    }
                }
                else if (OperationState == LEDState.Pigeon)
                {
                    if (_Battery.IsLow())
                    {
                        _labelTitle.SetText("Low Batt...");
                        _labelTitle.SetColor(DisplayModule.Color.Red);
                    }
                    else
                    {
                        _labelTitle.SetText("Pigeon");
                        _labelTitle.SetColor(DisplayModule.Color.Magenta);
                    }

                    /* Check status of Pigeon to see if it is connected */
                    CTRE.Phoenix.Sensors.PigeonState _PigeonState = _Pigeon.GetState();
                    if (_PigeonState == CTRE.Phoenix.Sensors.PigeonState.Ready)
                    {
                        /** Pigeon connected, giver user tilt control */

                        /* Pull Yaw, Pitch, and Roll from Pigeon */
                        float[] YPR = new float[3];
                        _Pigeon.GetYawPitchRoll(YPR);
                        float Pitch = YPR[1];
                        float Roll  = YPR[2];

                        CTRE.Phoenix.Util.Cap(Pitch, 90);
                        CTRE.Phoenix.Util.Cap(Roll, 90);

                        float Brightness = 0.5f;

                        /* Update LED strip */
                        UpdateLedStrip(Brightness, Pitch / 90, Roll / 90, true);
                    }
                    else
                    {
                        /* Pigeon is not Ready/Available, so flash us */
                        i++;
                        if (i >= 100)
                        {
                            On = !On;
                            i  = 0;
                        }

                        /* Decide if strip is white or off */
                        if (On == true)
                        {
                            UpdateLedStrip(1, 255, 255, 255);   /* White */
                        }
                        else if (On == false)
                        {
                            UpdateLedStrip(1, 0, 0, 0);                 /* Off */
                        }
                    }
                }

                int idx = GetFirstButton(_Gamepad);
                if (idx < 0)
                {
                    _labelRow1.SetColor((DisplayModule.Color) 0xA0A0A0); // gray RGB
                    _labelRow2.SetColor((DisplayModule.Color) 0xA0A0A0); // gray RGB
                    _labelRow3.SetColor((DisplayModule.Color) 0xA0A0A0); // gray RGB

                    float[] ypr = new float[3];
                    _Pigeon.GetYawPitchRoll(ypr);
                    _labelRow1.SetText("Yaw:" + ypr[0]);
                    _labelRow2.SetText("Pitch:" + ypr[1]);
                    _labelRow3.SetText("Roll:" + ypr[2]);
                }
                else
                {
                    switch (idx % 4)
                    {
                    case 0: _labelRow1.SetColor(DisplayModule.Color.Cyan); break;

                    case 1: _labelRow1.SetColor(DisplayModule.Color.Green); break;

                    case 2: _labelRow1.SetColor(DisplayModule.Color.Red); break;

                    case 3: _labelRow1.SetColor(DisplayModule.Color.Yellow); break;
                    }

                    _labelRow1.SetText("Pressed Button " + idx);
                    _labelRow2.SetText("");
                    _labelRow3.SetText("");
                }

                /* Let he program to sleep for a little */
                Thread.Sleep(5);
            }
        }
Example #3
0
        public void RunForever()
        {
            _leftY  = new VerticalGauge(_displayModule, 5, 5, 30, 10, DisplayModule.Color.Cyan, DisplayModule.Color.Blue);
            _rightY = new VerticalGauge(_displayModule, 135, 5, 30, 10, DisplayModule.Color.Yellow, DisplayModule.Color.Red);


            _leftX  = new HorizGauge(_displayModule, 35, 30, 10, 30, DisplayModule.Color.Green, DisplayModule.Color.Magenta);
            _rightX = new HorizGauge(_displayModule, 85, 30, 10, 30, DisplayModule.Color.Blue, DisplayModule.Color.Orange);

            _leftCrossHair = _displayModule.AddResourceImageSprite(
                DisplayModule_Example.Properties.Resources.ResourceManager,
                DisplayModule_Example.Properties.Resources.BinaryResources.ch2,
                Bitmap.BitmapImageType.Jpeg,
                30, 100);

            _rightCrossHair = _displayModule.AddResourceImageSprite(
                DisplayModule_Example.Properties.Resources.ResourceManager,
                DisplayModule_Example.Properties.Resources.BinaryResources.ch2,
                Bitmap.BitmapImageType.Jpeg,
                100, 100);

            _labelTitle = _displayModule.AddLabelSprite(_bigFont, DisplayModule.Color.White, 40, 0, 80, 16);

            _labelBtn = _displayModule.AddLabelSprite(_smallFont, DisplayModule.Color.White, 30, 50, 100, 15);

            while (true)
            {
                UpdateGauge(_leftX, _gamepad.GetAxis(0));
                UpdateGauge(_leftY, _gamepad.GetAxis(1));
                UpdateGauge(_rightX, _gamepad.GetAxis(2));
                UpdateGauge(_rightY, _gamepad.GetAxis(5));

                _leftCrossHair.SetPosition((int)(30 + 15 * _gamepad.GetAxis(0)), 100 + (int)(15 * _gamepad.GetAxis(1)));
                _rightCrossHair.SetPosition((int)(100 + 15 * _gamepad.GetAxis(2)), 100 + (int)(15 * _gamepad.GetAxis(5)));

                if (_gamepad.GetConnectionStatus() == UsbDeviceConnection.Connected)
                {
                    _labelTitle.SetText("Connected");
                    _labelTitle.SetColor(DisplayModule.Color.Green);
                }
                else
                {
                    _labelTitle.SetText("No Gamepad");
                    _labelTitle.SetColor(DisplayModule.Color.Red);
                }

                int idx = GetFirstButton(_gamepad);
                if (idx < 0)
                {
                    _labelBtn.SetColor((DisplayModule.Color) 0xA0A0A0); // gray RGB
                    _labelBtn.SetText("No Buttons");
                }
                else
                {
                    switch (idx % 4)
                    {
                    case 0: _labelBtn.SetColor(DisplayModule.Color.Cyan); break;

                    case 1: _labelBtn.SetColor(DisplayModule.Color.Green); break;

                    case 2: _labelBtn.SetColor(DisplayModule.Color.Red); break;

                    case 3: _labelBtn.SetColor(DisplayModule.Color.Yellow); break;
                    }
                    _labelBtn.SetText("Pressed Button " + idx);
                }

                Thread.Sleep(10);
            }
        }