-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemoman.java
More file actions
380 lines (341 loc) · 11.1 KB
/
Copy pathDemoman.java
File metadata and controls
380 lines (341 loc) · 11.1 KB
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
package demoman;
import edu.wpi.first.wpilibj.*;
import edu.wpi.first.wpilibj.DriverStationEnhancedIO.EnhancedIOException;
import edu.wpi.first.wpilibj.camera.AxisCamera;
import edu.wpi.first.wpilibj.camera.AxisCameraException;
import edu.wpi.first.wpilibj.image.NIVisionException;
/*
* Team 3181 Robotics
* Project: Breakaway
* Codename: Demoman
* (The Chargin Scottsman)
* Filename: Demoman.java
*/
/**
* This class represents the robot, nicknamed Demoman by a very TF2 obsessed
* programmer. Most methods are simple enough; just remeber that "teleop"
* means "operator controlled".
*
* @author eric
* @author ben
*
*/
public class Demoman extends IterativeRobot {
/*--- Instance Variables ---*/
// Maintain autonomous state
int autonomousMode = 0;
// Autonomous timer
static Timer autonomousTimer = new Timer();
// Camera
AxisCamera camera;
// There was a problem with the wiring of DS DI 5, it's
// normally closed. Reversing logic causes problems
// if the DS isn't hooked up... so run checks to make
// sure it is, and if not, we take appropriate action
boolean fiveHookedUp = false;
/*--- Initialization Routines ---*/
/**
* Procedures for when the robot has just been booted, but has NOT been put into any mode.
* <i>Does nothing.</i>
*
*/
public void robotInit() {
System.out.println("Robot has been initialized!");
// Check for the presence of DSDI five
if (Hardware.DS.getDigitalInput(5))
{
fiveHookedUp = true;
}
/*camera = AxisCamera.getInstance();
camera.writeCompression(0);
camera.writeBrightness(10);
camera.writeResolution(AxisCamera.ResolutionT.k160x120) ;*/
}
/**
* Procedures for when the robot has just been put into disabled mode.
* <i>Does nothing.</i>
*
*/
public void disabledInit() {
// Failsafe for DSDI5 check. In case somebody was pushing
// the button during the other checks.
if (Hardware.DS.getDigitalInput(5))
{
fiveHookedUp = true;
}
System.out.println("Robot has been disabled id-feb17");
}
/**
* Procedures for when the robot has just been put into autonomous mode.
* The robot is stopped and the drive system is reset.
* Switches are read to determine which autonomous program to run.
* A timer is started to help autonomous programs use dead-reckoning.
*
*/
public void autonomousInit() {
System.out.println("Robot has been put into autonomous mode");
// Failsafe for DSDI5 check. In case somebody was pushing
// the button during the other checks.
if (Hardware.DS.getDigitalInput(5))
{
fiveHookedUp = true;
}
// Stop everything.
Hardware.robotDrive.stop();
// Find out which autnomous mode we want
autonomousMode = 0;
// Leftmost worth 4
autonomousMode += Hardware.autonomousSwitches[0].get() ? 4 : 0;
// Middle worth 2
autonomousMode += Hardware.autonomousSwitches[1].get() ? 2 : 0;
// Rightmost worth 1
autonomousMode += Hardware.autonomousSwitches[2].get() ? 1 : 0;
// Make sure the compressor is on
Hardware.compressor.start();
// Start the autonomous timer, referenced by all autonomous modes
autonomousTimer.start();
}
/**
* Procedures for when the robot has just been put into teleoperator mode.
* The robot is stopped and the drive system reset. Just in case you know.
*
*/
public void teleopInit() {
System.out.println("Robot has been put into teleoperator mode");
Kicking.pressureInit();
// Failsafe for DSDI5 check. In case somebody was pushing
// the button during the other checks.
if (Hardware.DS.getDigitalInput(5))
{
fiveHookedUp = true;
}
Hardware.robotDrive.stop();
// Make sure the compressor is on
Hardware.compressor.start();
}
/*--- Periodic Routines ---*/
// Where stuff happens
/**
* What the robot should do while disabled, over and over again.
* <i>Does nothing.</i>
*
*/
public void disabledPeriodic() {
Watchdog.getInstance().feed();
}
/**
* What the robot should do while in autonomous mode, over and over again.
* It will call the static run() method of the corrent autonomous class.
* Authors of autonomous run() methods should take care that their functions
* terminate in a timely fashion, and use the timer for timed functions.
*
*/
public void autonomousPeriodic() {
Watchdog.getInstance().feed();
updateDashboard();
System.out.println("Autonomous mode: " + autonomousMode);
switch (autonomousMode) {
case 0:
// AutonomousDoNothing.run();
break;
case 1:
AutonomousZone1.run();
break;
case 2:
AutonomousZone2.run();
break;
case 3:
AutonomousZone3.run();
break;
}
Kicking.pressureMaintenance();
}
/**
* What the robot should do while in teleoperated mode, over and over again.
* Currently, this function sets the motors, using ramping, to the joysticks values.
* It also checks the trigger state, and attempts to kick the ball if the trigger is pressed.
*
* @see DriveSystem#driveAtSpeed
* @see Kicking#kickBall
*
*/
public void teleopPeriodic() {
Watchdog.getInstance().feed();
// Are we in "stopped" mode? This is a mode where we disabled ourselves WITHOUT the use
// of the e-stop button. Useful for demonstrations.
// commented out until i can get a verification on the hardware
/*if(Hardware.stoppedModeSwitch.get())
{
Hardware.robotDrive.stop();
return;
}*/
// Respond to drivers
updateDashboard();
double goLeft;
double goRight;
if (Hardware.rightJoystick.getRawButton(2) || Hardware.leftJoystick.getRawButton(2)){
goLeft = Hardware.leftJoystick.getY() * .7;
goRight = Hardware.rightJoystick.getY() * .7;
} else {
goLeft = Hardware.leftJoystick.getY();
goRight = Hardware.rightJoystick.getY();
}
Hardware.robotDrive.driveAtSpeed(goLeft, goRight);
// See if we're supposed to be kicking the ball.
if (Hardware.rightJoystick.getTrigger() || Hardware.leftJoystick.getTrigger() || Hardware.DS.getDigitalInput(6)) {
Kicking.kickBall();
}
Kicking.pressureMaintenance();
//set enhanced I/O digital outputs for kicker retracted
if (!Hardware.kickerLatchSwitch.get()) {
try {
DriverStationEnhancedIO dseio = DriverStation.getInstance().getEnhancedIO();
dseio.setDigitalOutput(1, true);
dseio.setDigitalOutput(2, true);
dseio.setDigitalOutput(3, true);
dseio.setDigitalOutput(4, true);
} catch (EnhancedIOException ex) {
System.out.println("Error in Enhanced IO.");
}
} else {
try {
DriverStationEnhancedIO dseio = DriverStation.getInstance().getEnhancedIO();
dseio.setDigitalOutput(1, false);
dseio.setDigitalOutput(2, false);
dseio.setDigitalOutput(3, false);
dseio.setDigitalOutput(4, false);
} catch (EnhancedIOException ex) {
System.out.println("Error in Enhanced IO.");
}
}
// (UN)Locking the winch?
// Since DSDI5 is normally closed, we reverse its logic--
// but make sure that it's present before we reverse its logic.
/* if (!Hardware.DS.getDigitalInput(5) && fiveHookedUp) {
Winch.changeLockState();
}
Winch.actOnLockState();
// Lifting us up?
if (Hardware.DS.getDigitalInput(7)) {
Winch.lift(Hardware.DS.getAnalogInput("y"));
} else if (Hardware.rightJoystick.getRawButton(4)) {
Winch.lift(Hardware.rightJoystick.getX());
} else if (Hardware.leftJoystick.getRawButton(4)) {
Winch.lift(Hardware.leftJoystick.getX());
} else {
Winch.stop();
}*/
// new winch code, built at the rally
if (Hardware.rightJoystick.getRawButton(4))
{
/* ---------------------------------- */
/* joystick input */
/* ---------------------------------- */
Winch.overrideUnlock();
Winch.lift(Hardware.rightJoystick.getX());
} else {
if (Hardware.DS.getDigitalInput(7))
{
/* --------------------------------- */
/* Reese's board Input */
/* --------------------------------- */
Winch.overrideUnlock();
Winch.lift(Hardware.DS.getAnalogInput("y"));
}
else
{
Winch.lift(0.0);
Winch.overrideLock();
}
}
// Control the ball roller
if (Hardware.DS.getDigitalInput(3)) {
Hardware.ballRoller.set(1);
} else if (Hardware.DS.getDigitalInput(2)) {
// Remember, if 3 is true there is no possible way 4 is also true, so an else if works
Hardware.ballRoller.set(-1);
} else {
// Neither are true, so let's turn it off (Flipper is in the middle)
Hardware.ballRoller.set(0);
}
// Give output to the driver
//Hardware.DS.giveOutput();
}
/**
* Update the dashboard with cool information. Talk to Reese if you want to know specifics
* about this function, he got it from teh internetz and put it in here, but didn't bother
* to write documentation for it.
*
*/
void updateDashboard() {
Dashboard lowDashData = DriverStation.getInstance().getDashboardPackerLow();
lowDashData.addCluster();
{
lowDashData.addCluster();
{ //analog modules
lowDashData.addCluster();
{
for (int i = 1; i <= 8; i++) {
lowDashData.addFloat((float) AnalogModule.getInstance(1).getAverageVoltage(i));
}
}
lowDashData.finalizeCluster();
lowDashData.addCluster();
{
for (int i = 1; i <= 8; i++) {
lowDashData.addFloat((float) AnalogModule.getInstance(2).getAverageVoltage(i));
}
}
lowDashData.finalizeCluster();
}
lowDashData.finalizeCluster();
lowDashData.addCluster();
{ //digital modules
lowDashData.addCluster();
{
lowDashData.addCluster();
{
int module = 4;
lowDashData.addByte(DigitalModule.getInstance(module).getRelayForward());
lowDashData.addByte(DigitalModule.getInstance(module).getRelayForward());
lowDashData.addShort(DigitalModule.getInstance(module).getAllDIO());
lowDashData.addShort(DigitalModule.getInstance(module).getDIODirection());
lowDashData.addCluster();
{
for (int i = 1; i <= 10; i++) {
lowDashData.addByte((byte) DigitalModule.getInstance(module).getPWM(i));
}
}
lowDashData.finalizeCluster();
}
lowDashData.finalizeCluster();
}
lowDashData.finalizeCluster();
lowDashData.addCluster();
{
lowDashData.addCluster();
{
int module = 6;
lowDashData.addByte(DigitalModule.getInstance(module).getRelayForward());
lowDashData.addByte(DigitalModule.getInstance(module).getRelayReverse());
lowDashData.addShort(DigitalModule.getInstance(module).getAllDIO());
lowDashData.addShort(DigitalModule.getInstance(module).getDIODirection());
lowDashData.addCluster();
{
for (int i = 1; i <= 10; i++) {
lowDashData.addByte((byte) DigitalModule.getInstance(module).getPWM(i));
}
}
lowDashData.finalizeCluster();
}
lowDashData.finalizeCluster();
}
lowDashData.finalizeCluster();
}
lowDashData.finalizeCluster();
lowDashData.addByte(Solenoid.getAll());
}
lowDashData.finalizeCluster();
lowDashData.commit();
}
}