-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlasmaTrigger.java
100 lines (88 loc) · 1.96 KB
/
PlasmaTrigger.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
package frc.robot.controllers;
import edu.wpi.first.wpilibj.DriverStation;
public class PlasmaTrigger {
private final int joystickPort;
private final byte triggerNumByte;
boolean isHeld = false;
/**
* Constructor for plasma trigger
*
* @param triggerNum - ID number of trigger
* @param joystickPort - Port of joystick trigger is on
*
* @author Nic A
*/
public PlasmaTrigger(int triggerNum, int joystickPort) {
this.joystickPort = joystickPort;
this.triggerNumByte = (byte)triggerNum;
}
/**
* Checks if trigger has been pressed past threshold
*
* @return true if trigger value > threshold
*
* @author Nic A
*/
public boolean isPressed(){
return DriverStation.getStickAxis(joystickPort, triggerNumByte) > JoystickConstants.triggerThreshold;
}
/**
* Checks if trigger has been toggled from off to on
*
* @return True once when trigger goes from being off to being pressed
*
* @author Nic A
*/
public boolean isOffToOn(){
if(!isHeld && isPressed()){
isHeld = true;
return true;
}
else{
isHeld = isPressed();
return false;
}
}
/**
* Checks if trigger has been toggled from on to off
*
* @return True once when trigger goes from being pressed to off
*
* @author Nic A
*/
public boolean isOnToOff(){
if(isHeld && !isPressed()){
isHeld = false;
return true;
}
else{
isHeld = isPressed();
return false;
}
}
/**
* Returns the raw value from trigger after reversal
*
* @return Joystick value
*
* @author Nic
*/
public double getTrueAxis(){
return DriverStation.getStickAxis(joystickPort, triggerNumByte);
}
/**
* Returns the value of the trigger after reversal and deadband calculations
*
* @return Value of trigger axis if greater than threshold, 0 otherwise
*
* @Author Nic A
*/
public double getFilteredAxis(){
if(Math.abs(getTrueAxis()) > JoystickConstants.triggerThreshold){
return getTrueAxis();
}
else{
return 0;
}
}
}