public static void Main() { //Gamepad for input CTRE.Controller.GameController _gamepad = new CTRE.Controller.GameController(CTRE.UsbHostDevice.GetInstance(0), 0); //Create the DriverModule object by giving it the port you plugged it in to. CTRE.HERO.Module.DriverModule driver = new CTRE.HERO.Module.DriverModule(CTRE.HERO.IO.Port5); //these just act as shorter names for the driveLow and pullUp states bool driveLow = CTRE.HERO.Module.DriverModule.OutputState.driveLow; bool pullUp = CTRE.HERO.Module.DriverModule.OutputState.pullUp; while (true) { //When the 'X' button is pressed, enable outputs if (_gamepad.GetButton(1) == true) { driver.Set(1, driveLow); driver.Set(2, driveLow); } else { driver.Set(1, pullUp); driver.Set(2, pullUp); } System.Threading.Thread.Sleep(10); } }
public void SetRef(CTRE.Controller.GameController reference, uint idx) { if (idx >= 0 && idx <= 5) { _controllers[idx] = reference; } }
public int GetFirstButton(CTRE.Controller.GameController gamepad) { for (uint i = 0; i < 16; ++i) { if (gamepad.GetButton(i)) { return((int)i); } } return(-1); }
//Password to module wifi is "password1" /** entry point of the application */ public static void Main() { ds = new CTRE.FRC.DriverStation(wifiport); //Create new Driver station object at port 4 _gamepad = new CTRE.Controller.GameController(ds, 0); //Set controller to look at DS with ID 0 //Create two TalonSrx objects and set their control mode left1 = new CTRE.TalonSrx(1); right1 = new CTRE.TalonSrx(2); left1.SetControlMode(CTRE.TalonSrx.ControlMode.kPercentVbus); right1.SetControlMode(CTRE.TalonSrx.ControlMode.kPercentVbus); //Set IP module looks for and is configured with, Computer must set to Static IP ds.SendIP(new byte[] { 10, 0, 33, 2 }, new byte[] { 10, 0, 33, 5 }); while (true) { //Must be called for DS to function ds.update(); //Send Battery Voltage information to Driver Station ds.SendBattery(left1.GetBusVoltage()); if (ds.IsAuton() && ds.IsEnabled()) { //Auton Code while enabled } else if (ds.IsAuton() && !ds.IsEnabled()) { //Auton Code while disabled } else if (!ds.IsAuton() && ds.IsEnabled()) { //Teleop Code while enabled Drive(); Debug.Print(stringBuilder.ToString()); ds.SendUDP(2550, Encoding.UTF8.GetBytes(stringBuilder.ToString())); stringBuilder.Clear(); } else if (!ds.IsAuton() && !ds.IsEnabled()) { //Teleop Code while disabled } } }
static void Drive() { if (null == _gamepad) { _gamepad = new CTRE.Controller.GameController(CTRE.UsbHostDevice.GetInstance(0), 0); } float x = _gamepad.GetAxis(0); // Positive is strafe-right, negative is strafe-left float y = -1 * _gamepad.GetAxis(1); // Positive is forward, negative is reverse float turn = _gamepad.GetAxis(2); // Positive is turn-right, negative is turn-left Deadband(ref x); Deadband(ref y); Deadband(ref turn); drive.Set(CTRE.Drive.Styles.Basic.PercentOutput, y, x, turn); }
static void Drive() { if (null == _gamepad) { _gamepad = new CTRE.Controller.GameController(CTRE.UsbHostDevice.GetInstance(0), 0); } float x = _gamepad.GetAxis(0); float y = -1 * _gamepad.GetAxis(1); float twist = _gamepad.GetAxis(2); Deadband(ref x); Deadband(ref y); Deadband(ref twist); drive.Set(CTRE.Drive.Styles.Basic.PercentOutput, y, twist); }
public static void Main() { //Gamepad for input CTRE.Controller.GameController _gamepad = new CTRE.Controller.GameController(CTRE.UsbHostDevice.GetInstance(0), 0); //simple PWM for fine control of pulse width, period, timing... uint period = 50000; //period between pulses uint duration = 1500; //duration of pulse PWM pwm_9 = new PWM(CTRE.HERO.IO.Port3.PWM_Pin9, period, duration, PWM.ScaleFactor.Microseconds, false); pwm_9.Start(); //starts the signal // ...and just a PWM SpeedController for motor controller (Victor SP, Talon SR, Victor 888, etc.)... PWMSpeedController pwmSpeedController = new PWMSpeedController(CTRE.HERO.IO.Port3.PWM_Pin4); while (true) { /* only enable motor control (PWM/CAN) if gamepad is connected. Logitech gamepads may be disabled using the X/D switch */ if (_gamepad.GetConnectionStatus() == CTRE.UsbDeviceConnection.Connected) { CTRE.Watchdog.Feed(); } /* let axis control the pwm speed controller */ pwmSpeedController.Set(0.10f); /* 10% */ /* let button1 control the explicit PWM pin duration*/ if (_gamepad.GetButton(1) == true) { pwm_9.Duration = 2000; /* 2.0ms */ } else { pwm_9.Duration = 1000; /* 1.0ms */ } /* yield for a bit, this controls this task's frequency */ System.Threading.Thread.Sleep(10); } }