Beispiel #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);
            }
        }
Beispiel #2
0
 public void DisplayInit()
 {
     if (displayModeRefresh == false)
     {
         image = display.AddResourceImageSprite(Properties.Resources.ResourceManager, Properties.Resources.BinaryResources.img, Bitmap.BitmapImageType.Jpeg, 44, 16);
         title = display.AddLabelSprite(ninaB, DisplayModule.Color.White, 36, 99, 100, 30);
         title.SetText("TAS Robotics");
         displayModeRefresh = true;
     }
 }
        /* main functions */
        private static void runForever() //runs forever
        {
            byte [] readData = new byte[4];
            eeprom.ReadBytes(eepromAddr, readData, 4);
            uint selectedAuton = (uint)(readData[0] % autonList.Length);                                      //inialize the selected auton to 0
            uint lastSelect    = 0;                                                                           //last selected auton
            bool pressed       = false;                                                                       //button debounce stuff
            bool lastPress     = false;                                                                       //button debounce stuff

            DisplayModule.LabelSprite header = displayModule.AddLabelSprite(SMALLFONT, WHITE, 5, 5, 118, 16); //Makes text object for headers
            header.SetText("Selected              Actual");                                                   //spaces for spacing
            DisplayModule.LabelSprite[] list = new DisplayModule.LabelSprite[autonList.Length];               //array of text objects
            for (int i = 0; i < autonList.Length; i++)
            {
                list[i] = displayModule.AddLabelSprite(SMALLFONT, WHITE, 18, 26 + 13 * i, 91, 13); //Makes text object for list of autons
                list[i].SetText(autonList[i]);                                                     //sets text to the string on top
            }

            check = displayModule.AddResourceImageSprite(Properties.Resources.ResourceManager,
                                                         Properties.Resources.BinaryResources._checked,
                                                         Bitmap.BitmapImageType.Jpeg, 5, 29 + 13 * (int)selectedAuton); //generates a cursor arrow
            retcheck = displayModule.AddResourceImageSprite(Properties.Resources.ResourceManager,
                                                            Properties.Resources.BinaryResources.green_check,
                                                            Bitmap.BitmapImageType.Jpeg, 110, 29 + 13 * (int)selectedAuton); //generates a green check from RIO

            while (true)                                                                                                     //loop forever
            {
                pressed = HeroButton.Read();                                                                                 //checks for button press
                if (pressed != lastPress && pressed == true)
                {
                    selectedAuton++;                                   //move to next auton
                    selectedAuton = selectedAuton % (uint)list.Length; //wraps the cursor around
                    byte [] toWrite = new byte[4];
                    toWrite[0] = (byte)selectedAuton;
                    eeprom.WriteBytes(eepromAddr, toWrite, 4);
                }
                lastPress = pressed;                //debounce

                sendAuton(selectedAuton, 1, 100);   //send 1 byte every 100ms, 0-255 auton mode
                uint rioAuton = (uint)loadAuton(1); //get 1 byte for RIO auton return

                disp(list, selectedAuton, lastSelect, rioAuton);
                lastSelect = selectedAuton;
            }
        }
        public static void Main()
        {
            // Game Controller
            GameController gamepad = new GameController(UsbHostDevice.GetInstance());

            // NinaB Font
            Font ninaB = Properties.Resources.GetFont(Properties.Resources.FontResources.NinaB);

            // Initializing a display module: DisplayModule(port, orientation)
            DisplayModule displayModule = new DisplayModule(CTRE.HERO.IO.Port8, DisplayModule.OrientationType.Landscape);

            while (true)
            {
                // Connect the game controller first so that the sprites show up
                if (gamepad.GetConnectionStatus() == UsbDeviceConnection.Connected)
                {
                    // Erases everything on the display
                    displayModule.Clear();

                    // Adding labels: [Display Module Name].AddLabelSprite(font, colour, x_pos, y_pos, width, height)
                    DisplayModule.LabelSprite title   = displayModule.AddLabelSprite(ninaB, DisplayModule.Color.White, 27, 17, 120, 15);
                    DisplayModule.LabelSprite x_label = displayModule.AddLabelSprite(ninaB, DisplayModule.Color.White, 80, 65, 80, 15);
                    DisplayModule.LabelSprite y_label = displayModule.AddLabelSprite(ninaB, DisplayModule.Color.White, 80, 85, 80, 15);

                    // Adding rectangles: [Display Module Name].AddRectSprite(colour, x_pos, y_pos, width, height)
                    DisplayModule.RectSprite x_rect = displayModule.AddRectSprite(DisplayModule.Color.White, 20, 55, 18, 55);
                    DisplayModule.RectSprite y_rect = displayModule.AddRectSprite(DisplayModule.Color.White, 47, 55, 18, 55);

                    // Everything gets cleared when the game controller is unplugged
                    while (gamepad.GetConnectionStatus() == UsbDeviceConnection.Connected)
                    {
                        // Declares and resets the joystick
                        double x_value = gamepad.GetAxis(0);
                        double y_value = -gamepad.GetAxis(1);
                        if (x_value < 0.05 && x_value > -0.05)
                        {
                            x_value = 0;
                        }
                        if (y_value < 0.05 && y_value > -0.05)
                        {
                            y_value = 0;
                        }

                        // Changes the color of the rectangle (x-value of the left joystick): [Rectangle Name].SetColor(colour)
                        if (x_value > 0.05)
                        {
                            x_rect.SetColor(DisplayModule.Color.Green);
                        }
                        else if (x_value < -0.05)
                        {
                            x_rect.SetColor(DisplayModule.Color.Red);
                        }
                        else
                        {
                            x_rect.SetColor(DisplayModule.Color.White);
                        }

                        // Changes the color of the rectangle (y-value of the left joystick): [Rectangle Name].SetColor(colour)
                        if (y_value > 0.05)
                        {
                            y_rect.SetColor(DisplayModule.Color.Green);
                        }
                        else if (y_value < -0.05)
                        {
                            y_rect.SetColor(DisplayModule.Color.Red);
                        }
                        else
                        {
                            y_rect.SetColor(DisplayModule.Color.White);
                        }

                        // Sets the text that the label displays: [Label Name].SetText(text: string)
                        title.SetText("Joystick Control");
                        x_label.SetText("X: " + x_value.ToString());
                        y_label.SetText("Y: " + y_value.ToString());
                    }
                }
                else
                {
                    // Erases everything on the display
                    displayModule.Clear();

                    // Adding images: [Display Module Name].AddResourceImageSprite(resource_manager, img_ID, img_type, x_pos, y_pos)
                    DisplayModule.ResourceImageSprite image = displayModule.AddResourceImageSprite(Properties.Resources.ResourceManager, Properties.Resources.BinaryResources.img, Bitmap.BitmapImageType.Jpeg, 44, 16);

                    // Adding labels: [Display Module Name].AddLabelSprite(font, colour, x_pos, y_pos, width, height)
                    DisplayModule.LabelSprite text = displayModule.AddLabelSprite(ninaB, DisplayModule.Color.White, 36, 99, 100, 30);

                    // Sets the text that the label displays: [Label Name].SetText(text: string)
                    text.SetText("TAS Robotics");

                    // Keeps the image and text while the gamepad is unplugged
                    while (gamepad.GetConnectionStatus() == UsbDeviceConnection.NotConnected)
                    {
                    }
                }
                System.Threading.Thread.Sleep(100);
            }
        }
Beispiel #5
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);
            }
        }
Beispiel #6
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);
            }
        }
Beispiel #7
0
        public static void Main()
        {
            /* Start the compressor */
            _pcm.StartCompressor();

            /* Tracking variables */
            bool lastCompState  = false;
            bool CompState      = false;
            int  compStartCount = 0;

            long now = DateTime.Now.Ticks;

            /* Display Module Elements */
            DisplayModule.LabelSprite _labelTitle = _displayModule.AddLabelSprite(_bigFont, DisplayModule.Color.White, 0, 0, 120, 16);
            DisplayModule.LabelSprite _labelCnt   = _displayModule.AddLabelSprite(_bigFont, DisplayModule.Color.White, 0, 16, 120, 16);

            while (true)
            {
                /* Always enable actuators during this test */
                CTRE.Phoenix.Watchdog.Feed();

                /* Simple gamepad control */
                if (_gamepad.GetButton(2))
                {
                    _talon.Set(ControlMode.PercentOutput, -1.0f);
                }
                else if (_gamepad.GetButton(4))
                {
                    _talon.Set(ControlMode.PercentOutput, +1.0f);
                }
                else
                {
                    float y = _gamepad.GetAxis(1);
                    CTRE.Phoenix.Util.Deadband(ref y);
                    _talon.Set(ControlMode.PercentOutput, y);
                }

#if false
                //Switch the compressor on/off
                //now = DateTime.Now.Ticks;
                //switch (switchState)
                //{
                //    case true:
                //        if (now - lastSwitch > kOnTime)
                //        {
                //            switchState = false;
                //            lastSwitch = now;
                //        }
                //        break;
                //    case false:
                //        if (now - lastSwitch > kOffTime)
                //        {
                //            switchState = true;
                //            lastSwitch = now;
                //        }
                //        break;
                //    default:
                //        break;
                //}
                //_pcm.SetSolenoidOutput(0, switchState);
#endif
                /* Compressor Control */
                _pcm.SetSolenoidOutput(0, _pcm.GetPressureSwitchValue());
                //Debug.Print("" + _pcm.GetPressureSwitchValue());

                /* Compressor Check */
                _pcm.GetLowLevelObject().GetCompressorOn(out CompState);
                if (CompState && !lastCompState)
                {
                    compStartCount++;
                }
                lastCompState = CompState;

                /* Display Module Output */
                _labelTitle.SetText("Comp Start Count:");
                _labelCnt.SetText("" + compStartCount);

                Thread.Sleep(5);
            }
        }
Beispiel #8
0
        public void DisplayOutput()
        {
            if (displayModeRefresh == false)
            {
                title              = display.AddLabelSprite(ninaB, DisplayModule.Color.White, 34, 17, 120, 15);
                label1             = display.AddLabelSprite(ninaB, DisplayModule.Color.White, 80, 56, 80, 15);
                label2             = display.AddLabelSprite(ninaB, DisplayModule.Color.White, 80, 76, 80, 15);
                label3             = display.AddLabelSprite(ninaB, DisplayModule.Color.White, 80, 96, 80, 15);
                rect1              = display.AddRectSprite(DisplayModule.Color.White, 20, 55, 18, 55);
                rect2              = display.AddRectSprite(DisplayModule.Color.White, 47, 55, 18, 55);
                displayModeRefresh = true;
            }
            if (title == null || label1 == null || label2 == null || label3 == null || rect1 == null || rect2 == null)
            {
                display.Clear();
                title  = display.AddLabelSprite(ninaB, DisplayModule.Color.White, 34, 17, 120, 15);
                label1 = display.AddLabelSprite(ninaB, DisplayModule.Color.White, 80, 55, 80, 15);
                label2 = display.AddLabelSprite(ninaB, DisplayModule.Color.White, 80, 75, 80, 15);
                label3 = display.AddLabelSprite(ninaB, DisplayModule.Color.White, 80, 95, 80, 15);
                rect1  = display.AddRectSprite(DisplayModule.Color.White, 20, 55, 18, 55);
                rect2  = display.AddRectSprite(DisplayModule.Color.White, 47, 55, 18, 55);
            }

            string colorStringX = "0x00";
            string colorStringY = "0x00";
            string redX, blueX, greenX;
            string redY, blueY, greenY;
            int    colorIntX = (int)System.Math.Round(xAxisA * 100);
            int    colorIntY = (int)System.Math.Round(yAxisA * 100);

            if (colorIntX > 0)
            {
                blueX  = (100 - colorIntX).ToString("X2");
                greenX = "ff";
                redX   = (100 - colorIntX).ToString("X2");
            }
            else if (colorIntX < 0)
            {
                blueX  = (100 + colorIntX).ToString("X2");
                greenX = (100 + colorIntX).ToString("X2");
                redX   = "ff";
            }
            else
            {
                blueX  = "ff";
                greenX = "ff";
                redX   = "ff";
            }
            if (colorIntY > 0)
            {
                blueY  = (100 - colorIntY).ToString("X2");
                greenY = "ff";
                redY   = (100 - colorIntY).ToString("X2");
            }
            else if (colorIntY < 0)
            {
                blueY  = (100 + colorIntY).ToString("X2");
                greenY = (100 + colorIntY).ToString("X2");
                redY   = "ff";
            }
            else
            {
                blueY  = "ff";
                greenY = "ff";
                redY   = "ff";
            }
            colorStringX = colorStringX + blueX + greenX + redX;
            colorStringY = colorStringY + blueY + greenY + redY;
            rect1.SetColor((DisplayModule.Color)Convert.ToInt32(colorStringX, 16));
            rect2.SetColor((DisplayModule.Color)Convert.ToInt32(colorStringY, 16));

            label1.SetText("X: " + xAxisA.ToString());
            label2.SetText("Y: " + yAxisA.ToString());
            label3.SetText("Angle: " + ((int)System.Math.Round(angle)).ToString());
            title.SetText("Motor Control");
        }