/** Initialize Display Module elements */ static void InitDisplayModule() { _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( Hero_DisplayBoard.Properties.Resources.ResourceManager, Hero_DisplayBoard.Properties.Resources.BinaryResources.ch2, Bitmap.BitmapImageType.Jpeg, 30, 100); _rightCrossHair = _DisplayModule.AddResourceImageSprite( Hero_DisplayBoard.Properties.Resources.ResourceManager, Hero_DisplayBoard.Properties.Resources.BinaryResources.ch2, Bitmap.BitmapImageType.Jpeg, 100, 100); _labelTitle = _DisplayModule.AddLabelSprite(_bigFont, DisplayModule.Color.White, 40, 0, 80, 16); _labelRow1 = _DisplayModule.AddLabelSprite(_smallFont, DisplayModule.Color.White, 30, 46, 100, 15); _labelRow2 = _DisplayModule.AddLabelSprite(_smallFont, DisplayModule.Color.White, 30, 58, 100, 15); _labelRow3 = _DisplayModule.AddLabelSprite(_smallFont, DisplayModule.Color.White, 30, 70, 100, 15); }
public static void Main() { //CSK 10/22/2019 .Follow method tells the follower motor to do whatever the lead motor does //The //Simplifies code a little bit leftdrive2.Follow(leftdrive1, FollowerType.PercentOutput); rightdrive2.Follow(rightdrive1, FollowerType.PercentOutput); //brushlessTest.Follow(rightdrive1, FollowerType.PercentOutput); #if (HASDISPLAY) _AMLogo = _displayModule.AddResourceImageSprite(Properties.Resources.ResourceManager, Properties.Resources.BinaryResources.andymark_logo_160x26, Bitmap.BitmapImageType.Jpeg, 0, 0); _labelTitle = _displayModule.AddLabelSprite(_bigFont, DisplayModule.Color.White, 0, 28, 160, 15); _labelBtn = _displayModule.AddLabelSprite(_smallFont, DisplayModule.Color.Cyan, 30, 60, 100, 10); _leftCrossHair = _displayModule.AddResourceImageSprite(Properties.Resources.ResourceManager, Properties.Resources.BinaryResources.crosshair, Bitmap.BitmapImageType.Jpeg, lftCrossHairOrigin, 100); _rightCrossHair = _displayModule.AddResourceImageSprite(Properties.Resources.ResourceManager, Properties.Resources.BinaryResources.crosshair, Bitmap.BitmapImageType.Jpeg, rtCrossHairOrigin, 100); _labelThrottle = _displayModule.AddLabelSprite(_bigFont, DisplayModule.Color.White, 0, 45, 75, 15); _labelSteering = _displayModule.AddLabelSprite(_bigFont, DisplayModule.Color.White, 80, 45, 75, 15); #endif /* loop forever */ while (true) { if (_gamepad.GetConnectionStatus() == CTRE.Phoenix.UsbDeviceConnection.Connected) { /* feed watchdog to keep Talon's enabled */ CTRE.Phoenix.Watchdog.Feed(); } /* drive robot using gamepad */ Drive(); } }
/* 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 void RunForever() { _main = _displayModule.AddResourceImageSprite( DisplayModule_FuelGauge_Example.Properties.Resources.ResourceManager, DisplayModule_FuelGauge_Example.Properties.Resources.BinaryResources.main, Bitmap.BitmapImageType.Bmp, 0, 0); _cursor = _displayModule.AddResourceImageSprite( DisplayModule_FuelGauge_Example.Properties.Resources.ResourceManager, DisplayModule_FuelGauge_Example.Properties.Resources.BinaryResources.cur, Bitmap.BitmapImageType.Bmp, 45, 40); double cursorPos = 40; double cursorVel = 1; System.Random random = new System.Random(); while (true) { cursorPos += cursorVel; //// Randomize cursor //if (cursorVel > 0) // cursorVel = +1.0 * random.NextDouble() + 0.1; // ensure positive //else if (cursorVel < 0) // cursorVel = -1.0 * random.NextDouble() - 0.1; // ensure negative if (cursorPos > 55) { cursorPos = 55; cursorVel = -1; } if (cursorPos < 5) { cursorPos = 5; cursorVel = +1; } _cursor.SetPosition(45, (int)cursorPos); Thread.Sleep(100); } }
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; } }
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); } }
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); } }
public static void Main() { //vvvCSK 10/28/2019 Copied from CTRE HeroPixyDrive examplevvv /* 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; //^^^CSK 10/28/2019 Copied from CTRE HeroPixyDrive example^^^ /* Configure Talons to operate in percentage VBus mode, and Ramp Up Voltage*/ #if TALONSRX foreach (TalonSRX temp in Talons) #else foreach (VictorSPX temp in Victors) #endif { temp.Set(ControlMode.PercentOutput, 0); temp.ConfigOpenloopRamp(kVoltageRampSec); } //^^^CSK 10/28/2019 Copied from CTRE HeroPixyDrive example^^^ #if (HASDISPLAY) _AMLogo = _displayModule.AddResourceImageSprite(Properties.Resources.ResourceManager, Properties.Resources.BinaryResources.andymark_logo_160x26, Bitmap.BitmapImageType.Jpeg, 0, 0); _labelTitle = _displayModule.AddLabelSprite(_bigFont, DisplayModule.Color.White, 0, 28, 160, 15); _labelBtn = _displayModule.AddLabelSprite(_smallFont, DisplayModule.Color.Cyan, 30, 60, 100, 10); _leftCrossHair = _displayModule.AddResourceImageSprite(Properties.Resources.ResourceManager, Properties.Resources.BinaryResources.crosshair, Bitmap.BitmapImageType.Jpeg, lftCrossHairOrigin, 100); _rightCrossHair = _displayModule.AddResourceImageSprite(Properties.Resources.ResourceManager, Properties.Resources.BinaryResources.crosshair, Bitmap.BitmapImageType.Jpeg, rtCrossHairOrigin, 100); //CSK 10/29/2019 This tells the display where to put the motor "speed" info on the screen _labelFrontMotors = _displayModule.AddLabelSprite(_bigFont, DisplayModule.Color.White, 2, 30, 134, 15); _labelRearMotors = _displayModule.AddLabelSprite(_bigFont, DisplayModule.Color.White, 7, 45, 128, 15); #endif /* loop forever */ while (true) { if (_gamepad.GetConnectionStatus() == CTRE.Phoenix.UsbDeviceConnection.Connected) { /* feed watchdog to keep Talon's enabled */ CTRE.Phoenix.Watchdog.Feed(); } /* Regular mecanum drive that is scaled and Gamepad joysticks have been adjusted */ //CSK 10/30/2019 With "standard" AM FRC wiring (M+ to redline terminal with bump) rotation is counter clockwise //Based on this wiring signs have been applied to make motion match the joystick control expectations float X = -1 * _gamepad.GetAxis(LEFT_JOY_X); float Y = _gamepad.GetAxis(LEFT_JOY_Y); float Twist = -1 * _gamepad.GetAxis(RIGHT_JOY_X); MecanumDrive(Y * kScalarY, X * kScalarX, Twist * kScalarTwist); } }