mirror of
https://github.com/Team4388/Robot-Essentials.git
synced 2026-06-09 00:38:01 -06:00
Update documentation for Xbox Controllers
This commit is contained in:
@@ -4,8 +4,12 @@ import frc4388.controller.XboxController;
|
|||||||
|
|
||||||
import edu.wpi.first.wpilibj.buttons.Button;
|
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 RIGHT_TRIGGER = 0;
|
||||||
public static final int LEFT_TRIGGER = 1;
|
public static final int LEFT_TRIGGER = 1;
|
||||||
public static final int RIGHT_AXIS_UP_TRIGGER = 2;
|
public static final int RIGHT_AXIS_UP_TRIGGER = 2;
|
||||||
@@ -20,11 +24,16 @@ public class XBoxTriggerButton extends Button
|
|||||||
private XboxController m_controller;
|
private XboxController m_controller;
|
||||||
private int m_trigger;
|
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_controller = controller;
|
||||||
m_trigger = trigger;
|
m_trigger = trigger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
@Override
|
||||||
public boolean get() {
|
public boolean get() {
|
||||||
if (m_trigger == RIGHT_TRIGGER) {
|
if (m_trigger == RIGHT_TRIGGER) {
|
||||||
return m_controller.getRightTrigger();
|
return m_controller.getRightTrigger();
|
||||||
|
|||||||
@@ -60,21 +60,26 @@ public class XboxController implements IHandController
|
|||||||
return stick;
|
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){
|
private boolean inDeadZone(double input){
|
||||||
boolean inDeadZone;
|
return (Math.abs(input) < DEADZONE);
|
||||||
if(Math.abs(input) < DEADZONE){
|
|
||||||
inDeadZone = true;
|
|
||||||
}else{
|
|
||||||
inDeadZone = false;
|
|
||||||
}
|
|
||||||
return inDeadZone;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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){
|
private double getAxisWithDeadZoneCheck(double input){
|
||||||
if(inDeadZone(input)){
|
if(inDeadZone(input)){
|
||||||
input = 0.0;
|
return 0.0;
|
||||||
|
} else {
|
||||||
|
return input;
|
||||||
}
|
}
|
||||||
return input;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getAButton(){
|
public boolean getAButton(){
|
||||||
@@ -141,9 +146,12 @@ public class XboxController implements IHandController
|
|||||||
return getAxisWithDeadZoneCheck(stick.getRawAxis(RIGHT_TRIGGER_AXIS));
|
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() {
|
public int getDpadAngle() {
|
||||||
return stick.getPOV();
|
return stick.getPOV(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getDPadLeft(){
|
public boolean getDPadLeft(){
|
||||||
|
|||||||
@@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user