diff --git a/.gitignore b/.gitignore index 5d853c9..a112d5a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ .Trashes ehthumbs.db Thumbs.db +__MACOSX # NetBeans specific # nbproject/private/ diff --git a/src/com/frc2879/bender/GamepadXbox.java b/src/com/frc2879/bender/GamepadXbox.java new file mode 100644 index 0000000..f2b11c1 --- /dev/null +++ b/src/com/frc2879/bender/GamepadXbox.java @@ -0,0 +1,134 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package com.frc2879.bender; + +/** + * + * @author floogulinc + */ +public class GamepadXbox extends XboxController{ + + public GamepadXbox(int port) { + super(port); + } + + // Defining Joystick Mappings: + public final int Button_X = 3; + public final int Button_Y = 4; + public final int Button_A = 1; + public final int Button_B = 2; + public final int Button_START = 8; + public final int Button_BACK = 7; + public final int Button_RIGHT_BUMPER = 6; + //public final int Button_RIGHT_TRIGGER = 8; + public final int Button_LEFT_BUMPER = 5; + // public final int Button_LEFT_TRIGGER = 7; + public final int Button_LEFT_STICK = 11; + public final int Button_RIGHT_STICK = 12; + + // Joystick axis(s) + public final int Stick_LEFT_Y = 2; + public final int Stick_LEFT_X = 1; + public final int Stick_RIGHT_X = 4; + public final int Stick_RIGHT_Y = 5; + public final int Axis_TRIGGER = 3; + public final int Axis_DPAD = 6; + + + /** + * Returns the X position of the left stick. + */ + public double getLeftX() { + return getRawAxis(Stick_LEFT_X); + } + + /** + * Returns the X position of the right stick. + */ + public double getRightX() { + return getRawAxis(Stick_RIGHT_X); + } + + /** + * Returns the Y position of the left stick. + */ + public double getLeftY() { + return getRawAxis(Stick_LEFT_Y); + } + + /** + * Returns the Y position of the right stick. + */ + public double getRightY() { + return getRawAxis(Stick_RIGHT_Y); + } + + /** + * Checks whether Button A is being pressed and returns true if it is. + */ + public boolean getButtonStateA() { + return getRawButton(Button_A); + } + + /** + * Checks whether Button B is being pressed and returns true if it is. + */ + public boolean getButtonStateB() { + return getRawButton(Button_B); + } + + /** + * Checks whether Button X is being pressed and returns true if it is. + */ + public boolean getButtonStateX() { + return getRawButton(Button_X); + } + + /** + * Checks whether Button Y is being pressed and returns true if it is. + */ + public boolean getButtonStateY() { + return getRawButton(Button_Y); + } + + public boolean getButtonStateLeftBumper() { + return getRawButton(Button_LEFT_BUMPER); + } + + public boolean getButtonStateRightBumper() { + return getRawButton(Button_RIGHT_BUMPER); + } + + + + /** + * Return the DPad axis positions. + */ + public double getDPadX() { + return getRawAxis(Axis_DPAD); + } + + + //Stuff from old logitech class + + + /** + * DPad Left and Right only WPILIB cannot access the vertical axis of the + * Logitech Game Controller Dpad + */ + // public boolean getDPadLeft() { + // double x = getDPadX(); + // return (x < -0.5); + // } + + //public boolean getDPadRight() { + // double x = getDPadX(); + // return (x > 0.5); + // } + + +} diff --git a/src/com/frc2879/bender/Robot.java b/src/com/frc2879/bender/Robot.java index 8162dda..8862b54 100644 --- a/src/com/frc2879/bender/Robot.java +++ b/src/com/frc2879/bender/Robot.java @@ -6,10 +6,11 @@ /*----------------------------------------------------------------------------*/ package com.frc2879.bender; -import edu.wpi.first.wpilibj.Joystick; import edu.wpi.first.wpilibj.RobotDrive; import edu.wpi.first.wpilibj.SimpleRobot; import edu.wpi.first.wpilibj.Timer; +import edu.wpi.first.wpilibj.camera.AxisCamera; +import edu.wpi.first.wpilibj.camera.AxisCameraException; /** * @@ -25,10 +26,11 @@ public class Robot extends SimpleRobot { RobotDrive drivetrain = new RobotDrive(1, 2); - Gamepad gp = new Gamepad(1); + //Gamepad gp = new Gamepad(1); + GamepadXbox gp = new GamepadXbox(1); public final String name = "Bender Bot"; - public final String version = "v1.06"; + public final String version = "v1.08"; public final String fullname = name + " " + version; // CONFIG VALUES @@ -37,11 +39,16 @@ public class Robot extends SimpleRobot { boolean SquaredInputs = true; DSOutput dsout; + + AxisCamera acam; //Called exactly 1 time when the competition starts. protected void robotInit() { dsout = new DSOutput(); System.out.println("Loading " + fullname); + dsout.say(1, "Loading..."); + Timer.delay(0.5); + acam = AxisCamera.getInstance("10.28.79.11"); dsout.say(1, "Welcome to"); dsout.say(2, fullname); @@ -82,7 +89,21 @@ public void saysquaredinputs() { * This function is called once each time the robot enters autonomous mode. */ public void autonomous() { - + if (isAutonomous()) { + dsout.clearOutput(); + dsout.say(1, fullname); + dsout.say(2, "Autonomous Mode"); + Timer time = new Timer(); + time.start(); + while ( time.get() < 1 && isEnabled() && isAutonomous()) { + drivetrain.drive(-0.3, 0); //Negative goes forward for some reason + dsout.say(3, "Time: " + time.get()); + Timer.delay(0.01); + } + time.stop(); + dsout.say(3, "Time: " + time.get() + " DONE"); + time.reset(); + } } /** @@ -147,9 +168,19 @@ public void operatorControl() { // Drive da robot: drivetrain.arcadeDrive(moveL, spinL, SquaredInputs); - Timer.delay(0.01); + Timer.delay(0.005); + } + + } + + protected void disabled(){ + if(isDisabled()){ + dsout.clearOutput(); + dsout.say(1, fullname); + dsout.say(2, "Robot Disabled"); } } + /** * This function is called once each time the robot enters test mode. diff --git a/src/com/frc2879/bender/XboxController.java b/src/com/frc2879/bender/XboxController.java new file mode 100644 index 0000000..e5eeb50 --- /dev/null +++ b/src/com/frc2879/bender/XboxController.java @@ -0,0 +1,368 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.frc2879.bender; + +import edu.wpi.first.wpilibj.DriverStation; +import edu.wpi.first.wpilibj.GenericHID; +import edu.wpi.first.wpilibj.parsing.IInputOutput; + +/** + * A nearly drop in replacement for Joystick using an XBOX USB Controller + * @author Gustave Michel + */ +public class XboxController extends GenericHID implements IInputOutput { + + private DriverStation m_ds; + private final int m_port; + + /** + * Represents an analog axis on a joystick. + */ + public static class AxisType { + + /** + * The integer value representing this enumeration + */ + public final int value; + private static final int kLeftX_val = 1; + private static final int kLeftY_val = 2; + private static final int kTrigger_val = 3; + private static final int kRightX_val = 4; + private static final int kRightY_val = 5; + private static final int kDLeftRight_val = 6; + + private AxisType(int value) { + this.value = value; + } + + /** + * Axis: Left X + */ + public static final AxisType kLeftX = new AxisType(kLeftX_val); + + /** + * Axis: Left Y + */ + public static final AxisType kLeftY = new AxisType(kLeftY_val); + + /** + * Axis: Triggers + */ + public static final AxisType kTrigger = new AxisType(kTrigger_val); + + /** + * Axis: Right X + */ + public static final AxisType kRightX = new AxisType(kRightX_val); + + /** + * Axis: Right Y + */ + public static final AxisType kRightY = new AxisType(kRightY_val); + + /** + * Axis: D-Pad Left-Right + */ + public static final AxisType kDLeftRight = new AxisType(kDLeftRight_val); + } + + /** + * Represents a digital button on a joystick. + */ + public static class ButtonType { + + /** + * The integer value representing this enumeration + */ + public final int value; + private static final int kA_val = 1; + private static final int kB_val = 2; + private static final int kX_val = 3; + private static final int kY_val = 4; + private static final int kL_val = 5; + private static final int kR_val = 6; + private static final int kBack_val = 7; + private static final int kStart_val = 8; + private static final int kLeftStick_val = 9; + private static final int kRightStick_val = 10; + private static final int kRTrigger_val = 11; + private static final int kLTrigger_val = 12; + + private ButtonType(int value) { + this.value = value; + } + + /** + * Button: X-Joystick + */ + public static final ButtonType kLeftStick = new ButtonType(kLeftStick_val); + + /** + * Button: Y-Joystick + */ + public static final ButtonType kRightStick = new ButtonType(kRightStick_val); + + /** + * Button: X + */ + public static final ButtonType kX = new ButtonType(kX_val); + + /** + * Button: Y + */ + public static final ButtonType kY = new ButtonType(kY_val); + + /** + * Button: A + */ + public static final ButtonType kA = new ButtonType(kA_val); + + /** + * Button: B + */ + public static final ButtonType kB = new ButtonType(kB_val); + + /** + * Button: R1 + */ + public static final ButtonType kR = new ButtonType(kR_val); + + /** + * Button: L1 + */ + public static final ButtonType kL = new ButtonType(kL_val); + + /** + * Button: Select + */ + public static final ButtonType kStart = new ButtonType(kStart_val); + + /** + * Button: Right Trigger + */ + public static final ButtonType kRTrigger = new ButtonType(kRTrigger_val); + + /** + * Button: Left Trigger + */ + public static final ButtonType kLTrigger = new ButtonType(kLTrigger_val); + + /** + * Button: Start + */ + public static final ButtonType kBack = new ButtonType(kBack_val); + } + + + /** + * Constructor + * @param port USB Port on DriverStation + */ + public XboxController(int port) { + super(); + m_port = port; + m_ds = DriverStation.getInstance(); + } + + /** + * Get Value from an Axis + * @param axis Axis Number + * @return Value from Axis (-1 to 1) + */ + public double getRawAxis(int axis) { + return m_ds.getStickAxis(m_port, axis); + } + + /** + * Get Value from an Axis + * @param axis AxisType + * @return + */ + public double getAxis(AxisType axis) { + return getRawAxis(axis.value); + } + + /** + * Retrieve value for X axis + * @param hand Hand associated with the Joystick + * @return Value of Axis (-1 to 1) + */ + public double getX(Hand hand) { + if(hand.value == Hand.kRight.value) { + return getAxis(AxisType.kRightX); + } else if(hand.value == Hand.kLeft.value) { + return getAxis(AxisType.kLeftX); + } else { + return 0; + } + } + + /** + * Retrieve value for Y axis + * @param hand Hand associated with the Joystick + * @return Value of Axis (-1 to 1) + */ + public double getY(Hand hand) { + if(hand.value == Hand.kRight.value) { + return getAxis(AxisType.kRightY); + } else if(hand.value == Hand.kLeft.value) { + return getAxis(AxisType.kLeftY); + } else { + return 0; + } + } + + /** + * Unused + * @param hand Unused + * @return 0 + */ + public double getZ(Hand hand) { + return 0; + } + + /** + * Gets Value from D-Pad Left and Right Axis + * @return Axis Value (-1 to 1) + */ + public double getTwist() { + return getAxis(AxisType.kDLeftRight); + } + + /** + * Gets Value from Back Triggers + * @return Axis Value (-1 to 1) + */ + public double getThrottle() { + return getAxis(AxisType.kTrigger); + } + + /** + * Gets value from a button + * @param button number of the button + * @return State of the button + */ + public boolean getRawButton(int button) { + if(button == ButtonType.kRTrigger.value) { //Abstracted Buttons from Analog Axis + if(getThrottle() <= -.6) { + return true; + } + else { + return false; + } + } + if(button == ButtonType.kLTrigger.value) { //Abstracted Buttons from Analog Axis + if(getThrottle() >= .6) { + return true; + } + else { + return false; + } + } + return ((0x1 << (button - 1)) & m_ds.getStickButtons(m_port)) != 0; + } + + /** + * Get Value from a button + * @param button Button Type + * @return + */ + public boolean getButton(ButtonType button) { + return getRawButton(button.value); + } + + /** + * Get Trigger Value as Button + * @param hand Hand associated with button + * @return false + */ + public boolean getTrigger(Hand hand) { + if(hand == Hand.kLeft) { + return getButton(ButtonType.kLTrigger); + } else if(hand == Hand.kRight) { + return getButton(ButtonType.kRTrigger); + } else { + return false; + } + } + + /** + * Get Button from Joystick + * @param hand hand associated with the button + * @return Button Status (true or false) + */ + public boolean getTop(Hand hand) { + if(hand == Hand.kRight) { + return getButton(ButtonType.kRightStick); + } else if(hand == Hand.kLeft) { + return getButton(ButtonType.kLeftStick); + } else { + return false; + } + } + + /** + * Get Value from Back buttons + * @param hand hand associated with the button + * @return state of left or right + */ + public boolean getBumper(Hand hand) { + if(hand == Hand.kRight) { + return getButton(ButtonType.kR); + } else if(hand == Hand.kLeft) { + return getButton(ButtonType.kL); + } else { + return false; + } + } + + /** + * Get State of Select Button + * @return State of button + */ + public boolean getStart() { + return getButton(ButtonType.kStart); + } + + /** + * Get State of Back Button + * @return State of button + */ + public boolean getBack() { + return getButton(ButtonType.kBack); + } + + /** + * Get State of A Button + * @return State of button + */ + public boolean getAButton() { + return getButton(ButtonType.kA); + } + + /** + * Get State of B Button + * @return State of button + */ + public boolean getBButton() { + return getButton(ButtonType.kB); + } + + /** + * Get State of X Button + * @return State of button + */ + public boolean getXButton() { + return getButton(ButtonType.kX); + } + + /** + * Get State of Y Button + * @return State of button + */ + public boolean getYButton() { + return getButton(ButtonType.kY); + } +} \ No newline at end of file