-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCatzGrabber.java
218 lines (184 loc) · 6.56 KB
/
CatzGrabber.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/************************************************
* Timothy Vu
*
* Last Revised: 2/20/18 AL
* 11/7/18 EL
* 11/17/2018 ZT,CL,SA
*
* added printout debug data code
* flipped polarity of forearm and bicep solenoids
*
* Methods: openFlapToggle(), intakeCube(), launchCube(),
* deployIntake(), retractIntake()
*
* Functionality:
***********************************************/
package mechanisms;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.Timer;
import robot.Robot;
public class CatzGrabber {
public static WPI_TalonSRX intakeRT;
public static WPI_TalonSRX intakeLT;
public static Solenoid intakeForearm;
public static Solenoid intakeBicep;
public static boolean bicepDeployed = false;
public static boolean forearmOpen = false;
public static SolenoidState bicepState = SolenoidState.Closed;
public static SolenoidState forearmState = SolenoidState.Closed;
final static public int RT_INTAKE_PWM_PORT_NUMBER = 4;
final static public int LT_INTAKE_PWM_PORT_NUMBER = 1;
final static public int INTAKE_FOREARM_PCM_PORT_NUMBER = 1;
final static public int INTAKE_BICEP_PCM_PORT_NUMBER = 0;
final static public double FUNCTION_EXECUTION_DELAY = 0.1; //Time in between the execution of functions
final static public double INTAKE_SPEED = 1.0;
final static public double CUBE_OUTTAKE_WAIT_TIME = 0.5;
public enum SolenoidState {
Open(true), Closed(false);
private boolean state;
SolenoidState(boolean state){
this.state = state;
}
public boolean getState() {
return state;
}
}
/***************************
* Constructor
***************************/
public CatzGrabber() {
intakeRT = new WPI_TalonSRX(RT_INTAKE_PWM_PORT_NUMBER);
intakeLT = new WPI_TalonSRX(LT_INTAKE_PWM_PORT_NUMBER);
intakeForearm = new Solenoid(INTAKE_FOREARM_PCM_PORT_NUMBER);
intakeBicep = new Solenoid(INTAKE_BICEP_PCM_PORT_NUMBER);
printOutDebugData("Successfully initialized CatzGrabber");
}
/****************************************
* Method to set intake speed of grabber
****************************************/
public void setIntakeSpeed(double speed) {
intakeLT.set(speed);
intakeRT.set(-speed);
}
/*****************************************
*Method to close forearm on custom delay
*****************************************/
public void closeForearm(double delay) {
forearmState = SolenoidState.Closed;
intakeForearm.set(forearmState.getState());
printOutDebugData("Grabber forearm set to Closed");
Timer.delay(delay);
}
/*******************************************
*Method to close forearm on default delay
*******************************************/
public void closeForearm() {
closeForearm(FUNCTION_EXECUTION_DELAY);
}
/*****************************************
*Method to open forearm on custom delay
*****************************************/
public void openForearm(double delaySec) {
forearmState = SolenoidState.Open;
intakeForearm.set(forearmState.getState());
printOutDebugData("Grabber forearm set to Open");
Timer.delay(delaySec);
}
/*******************************************
*Method to close forearm on default delay
*******************************************/
public void openForearm() {
openForearm(FUNCTION_EXECUTION_DELAY);
}
/************************************************
*Method to toggle forearm opening and closing
************************************************/
public void toggleForearm() {
if (forearmState == SolenoidState.Open) {
this.closeForearm(FUNCTION_EXECUTION_DELAY);
} else {
this.openForearm(FUNCTION_EXECUTION_DELAY);
}
}
/*****************************************
*Method to lower grabber on custom delay
*****************************************/
public void deployBicep(double delay) {
bicepState = SolenoidState.Open;
intakeBicep.set(true);
printOutDebugData("Grabber Bicep set to Deploy");
Timer.delay(delay);
}
/*****************************************
*Method to lower grabber on default delay
*****************************************/
public void deployBicep() {
deployBicep(FUNCTION_EXECUTION_DELAY);
}
/*****************************************
*Method to raise grabber on custom delay
*****************************************/
public void retractBicep(double delay) {
bicepState = SolenoidState.Closed;
intakeBicep.set(false);
printOutDebugData("Grabber forearm set to Retract");
Timer.delay(delay);
}
/*****************************************
*Method to raise grabber on default delay
*****************************************/
public void retractBicep() {
retractBicep(FUNCTION_EXECUTION_DELAY);
}
/*************************************************************
*Method to close forearm and raise grabber simultaneously
*************************************************************/
public void retractGrabber() {
this.closeForearm(FUNCTION_EXECUTION_DELAY);
this.retractBicep(FUNCTION_EXECUTION_DELAY);
}
/*************************************************************
*Method to open forearm and lower grabber simultaneously
*************************************************************/
public void deployGrabber() {
this.deployBicep(FUNCTION_EXECUTION_DELAY);
this.openForearm(FUNCTION_EXECUTION_DELAY);
}
/****************************************
*Method to launch cube out of forearm
****************************************/
public void shootCube() {
this.setIntakeSpeed(-INTAKE_SPEED);
Timer.delay(CUBE_OUTTAKE_WAIT_TIME);
this.setIntakeSpeed(0.0);
}
/**********************************************
*Method to place cube down with custom speed
**********************************************/
public void placeCube(double speed) {
this.deployBicep(FUNCTION_EXECUTION_DELAY);
this.setIntakeSpeed(speed);
Timer.delay(CUBE_OUTTAKE_WAIT_TIME);
this.retractBicep(FUNCTION_EXECUTION_DELAY);
this.setIntakeSpeed(0.0);
}
/*****************************************************************
*Method to intake cube by lowering grabber and activating intake
*****************************************************************/
public void intakeCube() {
this.deployBicep(FUNCTION_EXECUTION_DELAY);
this.setIntakeSpeed(INTAKE_SPEED);
Timer.delay(CUBE_OUTTAKE_WAIT_TIME);
this.setIntakeSpeed(0.0);
}
/********************************
*Method printing out debug data
********************************/
private static void printOutDebugData(String info) {
if (Robot.debugMode == true) {
double currentTime = Robot.globalTimer.get();
System.out.println(currentTime + " -" + info);
}
}
}