From 2b0cad989c1b1dc00311b79397a56d7e654a0ec5 Mon Sep 17 00:00:00 2001 From: HFocus Date: Sun, 4 Aug 2019 15:58:48 -0600 Subject: [PATCH] Update documentation for Xbox Controllers --- .../frc4388/controller/XBoxTriggerButton.java | 15 ++++++++-- .../frc4388/controller/XboxController.java | 30 ++++++++++++------- .../java/frc4388/robot/subsystems/Drive.java | 25 ++++++++++++++++ 3 files changed, 56 insertions(+), 14 deletions(-) create mode 100644 src/main/java/frc4388/robot/subsystems/Drive.java diff --git a/src/main/java/frc4388/controller/XBoxTriggerButton.java b/src/main/java/frc4388/controller/XBoxTriggerButton.java index ae9217e..a922fec 100644 --- a/src/main/java/frc4388/controller/XBoxTriggerButton.java +++ b/src/main/java/frc4388/controller/XBoxTriggerButton.java @@ -4,8 +4,12 @@ import frc4388.controller.XboxController; import edu.wpi.first.wpilibj.buttons.Button; -public class XBoxTriggerButton extends Button -{ +/** + * Mapping for the Xbox controller triggers to allow triggers to be defined as + * buttons in {@link frc4388.robot.OI}. Checks to see if the given trigger + * exceeds a tolerance defined in {@link XboxController}. + */ +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; @@ -20,11 +24,16 @@ public class XBoxTriggerButton extends Button private XboxController m_controller; private int m_trigger; - public XBoxTriggerButton(XboxController controller, int trigger) { + /** + * Creates a Trigger-Button mapped to a specific Xbox controller and trigger + */ + public XboxTriggerButton(XboxController controller, int trigger) { m_controller = controller; m_trigger = trigger; } + /** {@inheritDoc} */ + @Override public boolean get() { if (m_trigger == RIGHT_TRIGGER) { return m_controller.getRightTrigger(); diff --git a/src/main/java/frc4388/controller/XboxController.java b/src/main/java/frc4388/controller/XboxController.java index 41ac8ca..bd0582c 100644 --- a/src/main/java/frc4388/controller/XboxController.java +++ b/src/main/java/frc4388/controller/XboxController.java @@ -60,21 +60,26 @@ public class XboxController implements IHandController return stick; } + /** + * Checks if the input falls within the deadzone. + * @param input from an axis on the controller + * @return true if input falls in deadzone, false if input falls outside deadzone + */ private boolean inDeadZone(double input){ - boolean inDeadZone; - if(Math.abs(input) < DEADZONE){ - inDeadZone = true; - }else{ - inDeadZone = false; - } - return inDeadZone; + return (Math.abs(input) < DEADZONE); } + /** + * Updates an input to have a deadzone around the 0 position + * @param input from an axis on the controller + * @return updated input + */ private double getAxisWithDeadZoneCheck(double input){ if(inDeadZone(input)){ - input = 0.0; + return 0.0; + } else { + return input; } - return input; } public boolean getAButton(){ @@ -141,9 +146,12 @@ public class XboxController implements IHandController 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.*/ + /** + * Get the angle input from the dpad. + * @return -1 if nothing is pressed, or the angle of the button pressed. 0 = up, 90 = right, etc. + */ public int getDpadAngle() { - return stick.getPOV(); + return stick.getPOV(0); } public boolean getDPadLeft(){ diff --git a/src/main/java/frc4388/robot/subsystems/Drive.java b/src/main/java/frc4388/robot/subsystems/Drive.java new file mode 100644 index 0000000..81da6b7 --- /dev/null +++ b/src/main/java/frc4388/robot/subsystems/Drive.java @@ -0,0 +1,25 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package frc4388.robot.subsystems; + +import edu.wpi.first.wpilibj.command.Subsystem; +import frc4388.controller.XboxTriggerButton; + +/** + * Add your docs here. + */ +public class Drive extends Subsystem { + // Put methods for controlling this subsystem + // here. Call these from Commands. + + @Override + public void initDefaultCommand() { + // Set the default command for a subsystem here. + // setDefaultCommand(new MySpecialCommand()); + } +}