diff --git a/src/main/java/frc4388/controller/IHandController.java b/src/main/java/frc4388/controller/IHandController.java new file mode 100644 index 0000000..5d5ca19 --- /dev/null +++ b/src/main/java/frc4388/controller/IHandController.java @@ -0,0 +1,18 @@ +package frc4388.controller; + +public interface IHandController { + + public double getLeftXAxis(); + + public double getLeftYAxis(); + + public double getRightXAxis(); + + public double getRightYAxis(); + + public double getLeftTriggerAxis(); + + public double getRightTriggerAxis(); + + public int getDpadAngle(); +} diff --git a/src/main/java/frc4388/controller/XBoxTriggerButton.java b/src/main/java/frc4388/controller/XBoxTriggerButton.java new file mode 100644 index 0000000..ae9217e --- /dev/null +++ b/src/main/java/frc4388/controller/XBoxTriggerButton.java @@ -0,0 +1,61 @@ +package frc4388.controller; + +import frc4388.controller.XboxController; + +import edu.wpi.first.wpilibj.buttons.Button; + +public class XBoxTriggerButton extends Button +{ + public static final int RIGHT_TRIGGER = 0; + public static final int LEFT_TRIGGER = 1; + public static final int RIGHT_AXIS_UP_TRIGGER = 2; + public static final int RIGHT_AXIS_DOWN_TRIGGER = 3; + public static final int RIGHT_AXIS_RIGHT_TRIGGER = 4; + public static final int RIGHT_AXIS_LEFT_TRIGGER = 5; + public static final int LEFT_AXIS_UP_TRIGGER = 6; + public static final int LEFT_AXIS_DOWN_TRIGGER = 7; + public static final int LEFT_AXIS_RIGHT_TRIGGER = 8; + public static final int LEFT_AXIS_LEFT_TRIGGER = 9; + + private XboxController m_controller; + private int m_trigger; + + public XBoxTriggerButton(XboxController controller, int trigger) { + m_controller = controller; + m_trigger = trigger; + } + + public boolean get() { + if (m_trigger == RIGHT_TRIGGER) { + return m_controller.getRightTrigger(); + } + else if (m_trigger == LEFT_TRIGGER) { + return m_controller.getLeftTrigger(); + } + else if (m_trigger == RIGHT_AXIS_UP_TRIGGER) { + return m_controller.getRightAxisUpTrigger(); + } + else if (m_trigger == RIGHT_AXIS_DOWN_TRIGGER) { + return m_controller.getRightAxisDownTrigger(); + } + else if (m_trigger == RIGHT_AXIS_RIGHT_TRIGGER) { + return m_controller.getRightAxisRightTrigger(); + } + else if (m_trigger == RIGHT_AXIS_LEFT_TRIGGER) { + return m_controller.getRightAxisLeftTrigger(); + } + else if (m_trigger == LEFT_AXIS_UP_TRIGGER) { + return m_controller.getLeftAxisUpTrigger(); + } + else if (m_trigger == LEFT_AXIS_DOWN_TRIGGER) { + return m_controller.getLeftAxisDownTrigger(); + } + else if (m_trigger == LEFT_AXIS_RIGHT_TRIGGER) { + return m_controller.getLeftAxisRightTrigger(); + } + else if (m_trigger == LEFT_AXIS_LEFT_TRIGGER) { + return m_controller.getLeftAxisLeftTrigger(); + } + return false; + } +} \ No newline at end of file diff --git a/src/main/java/frc4388/controller/XboxController.java b/src/main/java/frc4388/controller/XboxController.java new file mode 100644 index 0000000..41ac8ca --- /dev/null +++ b/src/main/java/frc4388/controller/XboxController.java @@ -0,0 +1,204 @@ +package frc4388.controller; + +import edu.wpi.first.wpilibj.Joystick; + +/** + * This is a wrapper for the WPILib Joystick class that represents an XBox + * controller. + * @author frc1675 + */ +public class XboxController implements IHandController +{ + public static final int LEFT_X_AXIS = 0; + public static final int LEFT_Y_AXIS = 1; + public static final int LEFT_TRIGGER_AXIS = 2; + public static final int RIGHT_TRIGGER_AXIS = 3; + public static final int RIGHT_X_AXIS = 4; + public static final int RIGHT_Y_AXIS = 5; + public static final int LEFT_RIGHT_DPAD_AXIS = 6; + public static final int TOP_BOTTOM_DPAD_AXIS = 6; + + public static final int A_BUTTON = 1; + public static final int B_BUTTON = 2; + public static final int X_BUTTON = 3; + public static final int Y_BUTTON = 4; + public static final int LEFT_BUMPER_BUTTON = 5; + public static final int RIGHT_BUMPER_BUTTON = 6; + public static final int BACK_BUTTON = 7; + public static final int START_BUTTON = 8; + + public static final int LEFT_JOYSTICK_BUTTON = 9; + public static final int RIGHT_JOYSTICK_BUTTON = 10; + + private static final double LEFT_DPAD_TOLERANCE = -0.9; + private static final double RIGHT_DPAD_TOLERANCE = 0.9; + private static final double BOTTOM_DPAD_TOLERANCE = -0.9; + private static final double TOP_DPAD_TOLERANCE = 0.9; + + private static final double LEFT_TRIGGER_TOLERANCE = 0.5; + private static final double RIGHT_TRIGGER_TOLERANCE = 0.5; + + private static final double RIGHT_AXIS_UP_TOLERANCE = -0.9; + private static final double RIGHT_AXIS_DOWN_TOLERANCE = 0.9; + private static final double RIGHT_AXIS_RIGHT_TOLERANCE = 0.9; + private static final double RIGHT_AXIS_LEFT_TOLERANCE = -0.9; + + private static final double LEFT_AXIS_UP_TOLERANCE = -0.9; + private static final double LEFT_AXIS_DOWN_TOLERANCE = 0.9; + private static final double LEFT_AXIS_RIGHT_TOLERANCE = 0.9; + private static final double LEFT_AXIS_LEFT_TOLERANCE = -0.9; + + private static final double DEADZONE = 0.1; + + private Joystick stick; + + public XboxController(int portNumber){ + stick = new Joystick(portNumber); + } + + public Joystick getJoyStick() { + return stick; + } + + private boolean inDeadZone(double input){ + boolean inDeadZone; + if(Math.abs(input) < DEADZONE){ + inDeadZone = true; + }else{ + inDeadZone = false; + } + return inDeadZone; + } + + private double getAxisWithDeadZoneCheck(double input){ + if(inDeadZone(input)){ + input = 0.0; + } + return input; + } + + public boolean getAButton(){ + return stick.getRawButton(A_BUTTON); + } + + public boolean getXButton(){ + return stick.getRawButton(X_BUTTON); + } + + public boolean getBButton(){ + return stick.getRawButton(B_BUTTON); + } + + public boolean getYButton(){ + return stick.getRawButton(Y_BUTTON); + } + + public boolean getBackButton(){ + return stick.getRawButton(BACK_BUTTON); + } + + public boolean getStartButton(){ + return stick.getRawButton(START_BUTTON); + } + + public boolean getLeftBumperButton(){ + return stick.getRawButton(LEFT_BUMPER_BUTTON); + } + + public boolean getRightBumperButton(){ + return stick.getRawButton(RIGHT_BUMPER_BUTTON); + } + + public boolean getLeftJoystickButton(){ + return stick.getRawButton(LEFT_JOYSTICK_BUTTON); + } + + public boolean getRightJoystickButton(){ + return stick.getRawButton(RIGHT_JOYSTICK_BUTTON); + } + + public double getLeftXAxis(){ + return getAxisWithDeadZoneCheck(stick.getRawAxis(LEFT_X_AXIS)); + } + + public double getLeftYAxis(){ + return getAxisWithDeadZoneCheck(stick.getRawAxis(LEFT_Y_AXIS)); + } + + public double getRightXAxis(){ + return getAxisWithDeadZoneCheck(stick.getRawAxis(RIGHT_X_AXIS)); + } + + public double getRightYAxis(){ + return getAxisWithDeadZoneCheck(stick.getRawAxis(RIGHT_Y_AXIS)); + } + + public double getLeftTriggerAxis(){ + return getAxisWithDeadZoneCheck(stick.getRawAxis(LEFT_TRIGGER_AXIS)); + } + + public double getRightTriggerAxis(){ + return getAxisWithDeadZoneCheck(stick.getRawAxis(RIGHT_TRIGGER_AXIS)); + } + + /**Returns -1 if nothing is pressed, or the angle of the button pressed 0 = up, 90 = right, etc.*/ + public int getDpadAngle() { + return stick.getPOV(); + } + + public boolean getDPadLeft(){ + return (stick.getRawAxis(LEFT_RIGHT_DPAD_AXIS) < LEFT_DPAD_TOLERANCE); + } + + public boolean getDPadRight(){ + return (stick.getRawAxis(LEFT_RIGHT_DPAD_AXIS) > RIGHT_DPAD_TOLERANCE); + } + + public boolean getDPadTop(){ + return (stick.getRawAxis(TOP_BOTTOM_DPAD_AXIS) < TOP_DPAD_TOLERANCE); + } + + public boolean getDPadBottom(){ + return (stick.getRawAxis(TOP_BOTTOM_DPAD_AXIS) > BOTTOM_DPAD_TOLERANCE); + } + + public boolean getLeftTrigger(){ + return (getLeftTriggerAxis() > LEFT_TRIGGER_TOLERANCE); + } + + public boolean getRightTrigger(){ + return (getRightTriggerAxis() > RIGHT_TRIGGER_TOLERANCE); + } + + public boolean getRightAxisUpTrigger(){ + return (getRightYAxis() < RIGHT_AXIS_UP_TOLERANCE); + } + + public boolean getRightAxisDownTrigger(){ + return (getRightYAxis() > RIGHT_AXIS_DOWN_TOLERANCE); + } + + public boolean getRightAxisLeftTrigger(){ + return (getRightXAxis() > RIGHT_AXIS_LEFT_TOLERANCE); + } + + public boolean getRightAxisRightTrigger(){ + return (getRightXAxis() > RIGHT_AXIS_RIGHT_TOLERANCE); + } + + public boolean getLeftAxisUpTrigger(){ + return (getLeftYAxis() < LEFT_AXIS_UP_TOLERANCE); + } + + public boolean getLeftAxisDownTrigger(){ + return (getLeftYAxis() > LEFT_AXIS_DOWN_TOLERANCE); + } + + public boolean getLeftAxisLeftTrigger(){ + return (getLeftXAxis() > LEFT_AXIS_LEFT_TOLERANCE); + } + + public boolean getLeftAxisRightTrigger(){ + return (getLeftXAxis() > LEFT_AXIS_RIGHT_TOLERANCE); + } +} \ No newline at end of file diff --git a/src/main/java/frc/robot/Main.java b/src/main/java/frc4388/robot/Main.java similarity index 97% rename from src/main/java/frc/robot/Main.java rename to src/main/java/frc4388/robot/Main.java index 5b3238a..ad2d494 100644 --- a/src/main/java/frc/robot/Main.java +++ b/src/main/java/frc4388/robot/Main.java @@ -5,7 +5,7 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -package frc.robot; +package frc4388.robot; import edu.wpi.first.wpilibj.RobotBase; diff --git a/src/main/java/frc/robot/OI.java b/src/main/java/frc4388/robot/OI.java similarity index 98% rename from src/main/java/frc/robot/OI.java rename to src/main/java/frc4388/robot/OI.java index 5d57329..9c8ca3e 100644 --- a/src/main/java/frc/robot/OI.java +++ b/src/main/java/frc4388/robot/OI.java @@ -5,7 +5,7 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -package frc.robot; +package frc4388.robot; /** * This class is the glue that binds the controls on the physical operator diff --git a/src/main/java/frc/robot/Robot.java b/src/main/java/frc4388/robot/Robot.java similarity index 97% rename from src/main/java/frc/robot/Robot.java rename to src/main/java/frc4388/robot/Robot.java index 0fc498a..5c4e876 100644 --- a/src/main/java/frc/robot/Robot.java +++ b/src/main/java/frc4388/robot/Robot.java @@ -5,15 +5,15 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -package frc.robot; +package frc4388.robot; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.command.Command; import edu.wpi.first.wpilibj.command.Scheduler; import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; -import frc.robot.commands.ExampleCommand; -import frc.robot.subsystems.ExampleSubsystem; +import frc4388.robot.commands.ExampleCommand; +import frc4388.robot.subsystems.ExampleSubsystem; /** * The VM is configured to automatically run this class, and to call the diff --git a/src/main/java/frc/robot/RobotMap.java b/src/main/java/frc4388/robot/RobotMap.java similarity index 98% rename from src/main/java/frc/robot/RobotMap.java rename to src/main/java/frc4388/robot/RobotMap.java index 45360e4..b6680f9 100644 --- a/src/main/java/frc/robot/RobotMap.java +++ b/src/main/java/frc4388/robot/RobotMap.java @@ -5,7 +5,7 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -package frc.robot; +package frc4388.robot; /** * The RobotMap is a mapping from the ports sensors and actuators are wired into diff --git a/src/main/java/frc/robot/commands/ExampleCommand.java b/src/main/java/frc4388/robot/commands/ExampleCommand.java similarity index 95% rename from src/main/java/frc/robot/commands/ExampleCommand.java rename to src/main/java/frc4388/robot/commands/ExampleCommand.java index 83a3fcc..cb8a9f6 100644 --- a/src/main/java/frc/robot/commands/ExampleCommand.java +++ b/src/main/java/frc4388/robot/commands/ExampleCommand.java @@ -5,10 +5,10 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -package frc.robot.commands; +package frc4388.robot.commands; import edu.wpi.first.wpilibj.command.Command; -import frc.robot.Robot; +import frc4388.robot.Robot; /** * An example command. You can replace me with your own command. diff --git a/src/main/java/frc/robot/subsystems/ExampleSubsystem.java b/src/main/java/frc4388/robot/subsystems/ExampleSubsystem.java similarity index 96% rename from src/main/java/frc/robot/subsystems/ExampleSubsystem.java rename to src/main/java/frc4388/robot/subsystems/ExampleSubsystem.java index 7f5e1a4..50ace89 100644 --- a/src/main/java/frc/robot/subsystems/ExampleSubsystem.java +++ b/src/main/java/frc4388/robot/subsystems/ExampleSubsystem.java @@ -5,7 +5,7 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -package frc.robot.subsystems; +package frc4388.robot.subsystems; import edu.wpi.first.wpilibj.command.Subsystem;