diff --git a/src/org/usfirst/frc/team4737/lib/LogitechController.java b/src/org/usfirst/frc/team4737/lib/LogitechController.java new file mode 100644 index 0000000..bc02705 --- /dev/null +++ b/src/org/usfirst/frc/team4737/lib/LogitechController.java @@ -0,0 +1,82 @@ +package org.usfirst.frc.team4737.lib; + +import edu.wpi.first.wpilibj.Joystick; +import edu.wpi.first.wpilibj.buttons.JoystickButton; + +public class LogitechController { + + public class Axis { + private final Joystick controller; + private final int axis; + + private double deadzone; + + public Axis(Joystick controller, int axis) { + this.controller = controller; + this.axis = axis; + } + + public void setDeadzone(double radius) { + if (radius < 0) throw new IllegalArgumentException("Deadzone cannot be less than 0."); + this.deadzone = radius; + } + + public double getRaw() { + return controller.getRawAxis(axis); + } + + public double get() { + double raw = getRaw(); + if (raw < -deadzone) { + return scale(raw, -1, -deadzone, -1, 0); + } else if (raw > deadzone) { + return scale(raw, deadzone, 1, 0, 1); + } else { + return 0; + } + } + + private double scale(double val, double valLow, double valHigh, double newLow, double newHigh) { + double reduced = (val - valLow) / (valHigh - valLow); + return reduced * (newHigh - newLow) + newLow; + } + } + + public class Thumbstick { + public final Axis X, Y; + + public Thumbstick(Joystick controller, int axisX, int axisY) { + X = new Axis(controller, axisX); + Y = new Axis(controller, axisY); + } + } + + public final Joystick controller; + public final JoystickButton A; + public final JoystickButton B; + public final JoystickButton X; + public final JoystickButton Y; + public final JoystickButton RB; + public final JoystickButton LB; + public final Thumbstick LS; + public final Thumbstick RS; + public final Axis LT; + public final Axis RT; + + public LogitechController(int usbPort) { + controller = new Joystick(usbPort); + A = new JoystickButton(controller, -1); // TODO map the correct button IDs + B = new JoystickButton(controller, -1); + X = new JoystickButton(controller, -1); + Y = new JoystickButton(controller, -1); + RB = new JoystickButton(controller, -1); + LB = new JoystickButton(controller, -1); + LS = new Thumbstick(controller, -1, -1); + RS = new Thumbstick(controller, -1, -1); + LT = new Axis(controller, -1); + RT = new Axis(controller, -1); + } + + // TODO add rumble if possible + +} diff --git a/src/org/usfirst/frc/team4737/robot/OI.java b/src/org/usfirst/frc/team4737/robot/OI.java index fae76d3..52cfda5 100644 --- a/src/org/usfirst/frc/team4737/robot/OI.java +++ b/src/org/usfirst/frc/team4737/robot/OI.java @@ -7,7 +7,10 @@ package org.usfirst.frc.team4737.robot; -import edu.wpi.first.wpilibj.Joystick; +import org.usfirst.frc.team4737.lib.LogitechController; +import org.usfirst.frc.team4737.robot.commands.ReverseIntake; +import org.usfirst.frc.team4737.robot.commands.RunIntake; + /** * This class is the glue that binds the controls on the physical operator @@ -42,12 +45,14 @@ public class OI { // until it is finished as determined by it's isFinished method. // button.whenReleased(new ExampleCommand()); - public Joystick leftJoystick; - public Joystick rightJoystick; + public LogitechController controller; public OI() { - leftJoystick = new Joystick(0); - rightJoystick = new Joystick(1); + controller = new LogitechController(0); + + controller.A.whileHeld(new RunIntake()); + controller.B.whileHeld(new ReverseIntake()); + } } diff --git a/src/org/usfirst/frc/team4737/robot/commands/TeleopTankDrive.java b/src/org/usfirst/frc/team4737/robot/commands/TeleopTankDrive.java index 1c31da5..81be37e 100644 --- a/src/org/usfirst/frc/team4737/robot/commands/TeleopTankDrive.java +++ b/src/org/usfirst/frc/team4737/robot/commands/TeleopTankDrive.java @@ -21,8 +21,8 @@ protected void initialize() { // Called repeatedly when this Command is scheduled to run protected void execute() { Robot.DRIVETRAIN.tankDrive( - Robot.OI.leftJoystick.getRawAxis(1), - Robot.OI.rightJoystick.getRawAxis(1)); + Robot.OI.controller.LS.Y.get(), + Robot.OI.controller.RS.Y.get()); } // Make this return true when this Command no longer needs to run execute()