-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathController.java
147 lines (128 loc) · 3.76 KB
/
Controller.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package frc.robot.utils;
import java.util.Map;
import edu.wpi.first.wpilibj.XboxController;
import frc.robot.Constants;
public class Controller extends XboxController {
public final double kGHOST = .05; // Threshold for blocking ghost signals
/**
* Initializes an Xbox controller.
*
* @param port Controller port (default should be 0)
*/
public Controller(int port) {
super(port);
}
/**
* Get the current joystick values in a Hashmap
*
* @return Returns stick values - Used in DriveTrain when driving
*/
public Map<String, Double> getSticks() {
// Returns a map of the sticks accessible by their keys ie - get("LSX")
return Map.of("LSX", this.getLeftX(), "LSY", this.getLeftY(), "RSX", this.getRightX(), "RSY", this.getRightY());
}
/**
* Get the joystick's right-x stick values
*
* @return Returns stick value as long as it exceeds the kGhost value -
* otherwise we return 0
*/
public double getRightX() {
return (super.getRawAxis(Constants.ControllerConstants.S_RIGHT_X_PORT) > kGHOST
|| super.getRawAxis(Constants.ControllerConstants.S_RIGHT_X_PORT) < -kGHOST)
? super.getRawAxis(Constants.ControllerConstants.S_RIGHT_X_PORT)
: 0;
}
/**
* Get the joystick's right-y stick values
*
* @return Returns stick value as long as it exceeds the kGhost value -
* otherwise we return 0
*/
public double getRightY() {
return (-super.getRawAxis(Constants.ControllerConstants.S_RIGHT_Y_PORT) > kGHOST
|| -super.getRawAxis(Constants.ControllerConstants.S_RIGHT_Y_PORT) < -kGHOST)
? -super.getRawAxis(Constants.ControllerConstants.S_RIGHT_Y_PORT)
: 0;
}
/**
* Get the joystick's left-x stick values
*
* @return Returns stick value as long as it exceeds the kGhost value -
* otherwise we return 0
*/
public double getLeftX() {
return (super.getRawAxis(Constants.ControllerConstants.S_LEFT_X_PORT) > kGHOST
|| super.getRawAxis(Constants.ControllerConstants.S_LEFT_X_PORT) < -kGHOST)
? super.getRawAxis(Constants.ControllerConstants.S_LEFT_X_PORT)
: 0;
}
/**
* Get the joystick's left-y stick values
*
* @return Returns stick value as long as it exceeds the kGhost value -
* otherwise we return 0
*/
public double getLeftY() {
return (-super.getRawAxis(Constants.ControllerConstants.S_LEFT_Y_PORT) > kGHOST
|| -super.getRawAxis(Constants.ControllerConstants.S_LEFT_Y_PORT) < -kGHOST)
? -super.getRawAxis(Constants.ControllerConstants.S_LEFT_Y_PORT)
: 0;
}
/**
* Get the controller's dpad value
*
* @return Returns the Joysticks DPad values
*/
public int getDPad() {
return super.getPOV();
}
/**
* Get the Xbox Controller's Right trigger
*
* @return The controller's right trigger value
*/
public double getRightTrigger() {
return super.getTriggerAxis(Hand.kRight);
}
/**
* Get the Xbox Controller's Left trigger
*
* @return The controller's left trigger value
*/
public double getLeftTrigger() {
return super.getTriggerAxis(Hand.kLeft);
}
/**
* Get the Xbox Controller right hand (right side)
*
* @return The Right side of the controller
*/
public Hand getRightHand() {
return Hand.kRight;
}
/**
* Get the Xbox Controller left hand (left side)
*
* @return The left side of the controller
*/
public Hand getLeftHand() {
return Hand.kLeft;
}
/**
* Whether the bumper was pressed since the last check.
*
* @return Boolean (true) pressed / (false) not pressed
*/
public boolean getRightBumperPressed() {
return super.getBumperPressed(getRightHand());
}
/**
* Whether the bumper was pressed since the last check.
*
* @return Boolean (true) pressed / (false) not pressed
*/
public boolean getLeftBumperPressed() {
return super.getBumperPressed(getLeftHand());
}
}