1
1
package frc .robot .subsystems .lift ;
2
2
3
+ import static edu .wpi .first .units .Units .Centimeters ;
3
4
import static edu .wpi .first .units .Units .Degrees ;
4
5
import static edu .wpi .first .units .Units .Inches ;
5
6
import static edu .wpi .first .units .Units .Meters ;
@@ -43,6 +44,12 @@ public static enum USER_INPUT {
43
44
static final DutyCycleOut HOMING_SPEED = new DutyCycleOut (-0.05 );
44
45
static final Distance HOMING_EPSILON = Millimeters .of (5 );
45
46
47
+ // Tolerance in cm of top and bottom minimum clearance
48
+ static final Distance ELEVATOR_TOLERANCE = Centimeters .of (0.5 );
49
+
50
+ // Tolerance in degrees of arm
51
+ static final Angle ARM_TOLERANCE = Degrees .of (0.5 );
52
+
46
53
static final Angle SCORING_L1_ANGLE = Degrees .of (0 );
47
54
static final Angle SCORING_L2_ANGLE = Degrees .of (0 );
48
55
static final Angle SCORING_L3_ANGLE = Degrees .of (0 );
@@ -61,6 +68,7 @@ public static enum USER_INPUT {
61
68
static final Distance L3_HEIGHT = Inches .of (0 );
62
69
static final Distance L4_HEIGHT = Inches .of (0 );
63
70
71
+
64
72
/* TODO: Actually get user input */
65
73
private static USER_INPUT getUserInput () { return USER_INPUT .STOW ; }
66
74
@@ -96,6 +104,7 @@ public LiftStates nextState() {
96
104
@ Override
97
105
public void initialize () {
98
106
s_liftinstance .setElevatorHeight (STOW_HEIGHT );
107
+ s_liftinstance .setArmAngle (STOW_ANGLE );
99
108
}
100
109
101
110
@ Override
@@ -165,7 +174,7 @@ public void initialize() {
165
174
166
175
@ Override
167
176
public SystemState nextState () {
168
- if (s_liftinstance .getArmAngle ().gte (SAFE_INTAKE_ANGLE )) {
177
+ if (s_liftinstance .getArmAngle ().lte (SAFE_INTAKE_ANGLE )) {
169
178
return STOW_L4_S1 ;
170
179
}
171
180
return this ;
@@ -302,22 +311,21 @@ public void initialize() {
302
311
s_liftinstance .setElevatorHeight (L4_HEIGHT );
303
312
}
304
313
305
- @ Override
306
- public void execute () {
307
- if (s_liftinstance .getElevatorHeight () == CLEAR_HEIGHT && s_liftinstance .getArmAngle () == STOW_ANGLE ) {
308
- s_liftinstance .setArmAngle (SCORING_L4_ANGLE );
309
- }
310
- }
311
-
312
314
@ Override
313
315
public SystemState nextState () {
314
- if (s_liftinstance .getElevatorHeight () == L4_HEIGHT && s_liftinstance . getArmAngle () == SCORING_L4_ANGLE ) {
316
+ if (s_liftinstance .getElevatorHeight (). gte ( CLEAR_HEIGHT ) ) {
315
317
return L4 ;
316
318
}
317
319
return this ;
318
320
}
319
321
},
320
322
L4 {
323
+ @ Override
324
+ public void initialize () {
325
+ s_liftinstance .setElevatorHeight (L4_HEIGHT );
326
+ s_liftinstance .setArmAngle (SCORING_L4_ANGLE );
327
+ }
328
+
321
329
@ Override
322
330
public SystemState nextState () {
323
331
if (getUserInput () == USER_INPUT .STOW ) {
@@ -343,7 +351,7 @@ public void initialize() {
343
351
344
352
@ Override
345
353
public SystemState nextState () {
346
- if (s_liftinstance .getArmAngle () == STOW_ANGLE ) {
354
+ if (s_liftinstance .getArmAngle (). gte ( STOW_ANGLE ) ) {
347
355
return STOW ;
348
356
}
349
357
return this ;
@@ -357,7 +365,7 @@ public void initialize() {
357
365
358
366
@ Override
359
367
public SystemState nextState () {
360
- if (s_liftinstance .getArmAngle () == STOW_ANGLE ) {
368
+ if (s_liftinstance .getArmAngle (). gte ( STOW_ANGLE ) ) {
361
369
return STOW ;
362
370
}
363
371
return this ;
@@ -371,7 +379,7 @@ public void initialize() {
371
379
372
380
@ Override
373
381
public SystemState nextState () {
374
- if (s_liftinstance .getElevatorHeight () == CLEAR_HEIGHT ) {
382
+ if (s_liftinstance .getElevatorHeight (). gte ( CLEAR_HEIGHT ) ) {
375
383
return L3_STOW_S2 ;
376
384
}
377
385
return this ;
@@ -385,7 +393,7 @@ public void initialize() {
385
393
386
394
@ Override
387
395
public SystemState nextState () {
388
- if (s_liftinstance .getArmAngle () == STOW_ANGLE ) {
396
+ if (s_liftinstance .getArmAngle (). gte ( STOW_ANGLE ) ) {
389
397
return STOW ;
390
398
}
391
399
return this ;
@@ -399,7 +407,7 @@ public void initialize() {
399
407
400
408
@ Override
401
409
public SystemState nextState () {
402
- if (s_liftinstance .getArmAngle () == STOW_ANGLE ) {
410
+ if (s_liftinstance .getArmAngle (). gte ( STOW_ANGLE ) ) {
403
411
return STOW ;
404
412
}
405
413
return this ;
@@ -413,7 +421,7 @@ public void initialize() {
413
421
414
422
@ Override
415
423
public SystemState nextState () {
416
- if (s_liftinstance .getArmAngle () == SAFE_REEF_ANGLE_BOTTOM ) {
424
+ if (s_liftinstance .getArmAngle (). gte ( SAFE_REEF_ANGLE_BOTTOM ) ) {
417
425
return STOW_L3_S1 ;
418
426
}
419
427
return this ;
@@ -427,7 +435,7 @@ public void initialize() {
427
435
428
436
@ Override
429
437
public SystemState nextState () {
430
- if (s_liftinstance .getArmAngle () == SAFE_REEF_ANGLE_BOTTOM ) {
438
+ if (s_liftinstance .getArmAngle (). gte ( SAFE_REEF_ANGLE_BOTTOM ) ) {
431
439
return STOW_L4_S1 ;
432
440
}
433
441
return this ;
@@ -441,7 +449,7 @@ public void initialize() {
441
449
442
450
@ Override
443
451
public SystemState nextState () {
444
- if (s_liftinstance .getArmAngle () == SAFE_REEF_ANGLE_BOTTOM ) {
452
+ if (s_liftinstance .getArmAngle (). gte ( SAFE_REEF_ANGLE_BOTTOM ) ) {
445
453
return STOW_L1_S1 ;
446
454
}
447
455
return this ;
@@ -455,7 +463,7 @@ public void initialize() {
455
463
456
464
@ Override
457
465
public SystemState nextState () {
458
- if (s_liftinstance .getArmAngle () == SAFE_REEF_ANGLE_BOTTOM ) {
466
+ if (s_liftinstance .getArmAngle (). gte ( SAFE_REEF_ANGLE_BOTTOM ) ) {
459
467
return STOW_L3_S1 ;
460
468
}
461
469
return this ;
@@ -469,7 +477,7 @@ public void initialize() {
469
477
470
478
@ Override
471
479
public SystemState nextState () {
472
- if (s_liftinstance .getArmAngle () == SAFE_REEF_ANGLE_BOTTOM ) {
480
+ if (s_liftinstance .getArmAngle (). gte ( SAFE_REEF_ANGLE_BOTTOM ) ) {
473
481
return STOW_L4_S1 ;
474
482
}
475
483
return this ;
@@ -483,7 +491,7 @@ public void initialize() {
483
491
484
492
@ Override
485
493
public SystemState nextState () {
486
- if (s_liftinstance .getArmAngle () == SAFE_REEF_ANGLE_TOP ) {
494
+ if (s_liftinstance .getArmAngle (). gte ( SAFE_REEF_ANGLE_TOP ) ) {
487
495
return L3_L1_S2 ;
488
496
}
489
497
return this ;
@@ -497,7 +505,7 @@ public void initialize() {
497
505
498
506
@ Override
499
507
public SystemState nextState () {
500
- if (s_liftinstance .getElevatorHeight () == CLEAR_HEIGHT ) {
508
+ if (s_liftinstance .getElevatorHeight (). gte ( CLEAR_HEIGHT ) ) {
501
509
return L3_L1_S3 ;
502
510
}
503
511
return this ;
@@ -506,17 +514,31 @@ public SystemState nextState() {
506
514
L3_L1_S3 {
507
515
@ Override
508
516
public void initialize () {
509
- s_liftinstance .setElevatorHeight ( CLEAR_HEIGHT );
517
+ s_liftinstance .setArmAngle ( SAFE_REEF_ANGLE_BOTTOM );
510
518
}
511
519
512
520
@ Override
513
521
public SystemState nextState () {
514
- if (s_liftinstance .getElevatorHeight () == CLEAR_HEIGHT ) {
515
- return L3_L1_S3 ;
522
+ if (s_liftinstance .getArmAngle ().gte (SAFE_REEF_ANGLE_BOTTOM )) {
523
+ return L3_L1_S4 ;
524
+ }
525
+ return this ;
526
+ }
527
+ },
528
+ L3_L1_S4 {
529
+ @ Override
530
+ public void initialize () {
531
+ s_liftinstance .setElevatorHeight (L1_HEIGHT );
532
+ }
533
+
534
+ @ Override
535
+ public SystemState nextState () {
536
+ if (s_liftinstance .getElevatorHeight ().lte (L1_HEIGHT )) {
537
+ return L1 ;
516
538
}
517
539
return this ;
518
540
}
519
- };
541
+ },
520
542
}
521
543
522
544
private static LiftSubsystem s_liftinstance ;
@@ -705,4 +727,24 @@ public void close() {
705
727
m_pivotMotor .close ();
706
728
s_liftinstance = null ;
707
729
}
730
+
731
+ /**
732
+ * Return whether the elevator is at a target height or not
733
+ * @return Boolean of if elevator is at target height
734
+ */
735
+ public boolean elevatorAt (Distance target_height ) {
736
+
737
+ Distance cur_height = getElevatorHeight ();
738
+ return (cur_height .gte (target_height .minus (ELEVATOR_TOLERANCE )) && cur_height .lte (target_height .plus (ELEVATOR_TOLERANCE )));
739
+ }
740
+
741
+ /**
742
+ * Return whether the arm is at a target angle or not
743
+ * @return Boolean of if arm is at target angle
744
+ */
745
+ public boolean armAt (Angle target_angle ) {
746
+
747
+ Angle cur_angle = getArmAngle ();
748
+ return (cur_angle .gte (target_angle .minus (ARM_TOLERANCE )) && cur_angle .lte (target_angle .plus (ARM_TOLERANCE )));
749
+ }
708
750
}
0 commit comments