|
7 | 7 |
|
8 | 8 | package frc.robot.subsystems; |
9 | 9 |
|
10 | | -import edu.wpi.first.wpilibj.VictorSP; |
| 10 | +import edu.wpi.first.wpilibj.Relay; |
| 11 | +import edu.wpi.first.wpilibj.Relay.Value; |
11 | 12 | import edu.wpi.first.wpilibj.command.Subsystem; |
12 | 13 | import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; |
13 | 14 | import frc.robot.commands.SetLight; |
|
16 | 17 | * Add your docs here. |
17 | 18 | */ |
18 | 19 | public class Lights extends Subsystem { |
| 20 | + |
| 21 | + public enum LightState { |
| 22 | + OFF, |
| 23 | + CARGO, |
| 24 | + HATCH, |
| 25 | + CLIMBER |
| 26 | + } |
19 | 27 | // Put methods for controlling this subsystem |
20 | 28 | // here. Call these from Commands. |
21 | | - private VictorSP lights; |
22 | | - private double lightsValue = 0; |
| 29 | + private Relay lights; |
| 30 | + private LightState lightsState; |
23 | 31 |
|
24 | 32 | /** |
25 | 33 | * 0 is off 0.5 is orange 1 is yellow |
26 | 34 | */ |
27 | 35 |
|
28 | | - public Lights(VictorSP lights) { |
| 36 | + public Lights(Relay lights) { |
29 | 37 | this.lights = lights; |
| 38 | + lightsState = LightState.HATCH; |
30 | 39 | } |
31 | 40 |
|
32 | | - public void setLights() { |
33 | | - lights.set(lightsValue); |
34 | | - String color; |
35 | | - if (lightsValue == 0) { |
| 41 | + public void setLights(LightState newState) { |
| 42 | + String color = ""; |
| 43 | + switch (newState) { |
| 44 | + case OFF: |
| 45 | + lights.set(Relay.Value.kOff); |
36 | 46 | color = "None"; |
37 | | - } else if (lightsValue == 0.5) { |
38 | | - color = "Yellow"; |
39 | | - } else { |
| 47 | + break; |
| 48 | + case CARGO: |
| 49 | + lights.set(Relay.Value.kForward); |
40 | 50 | color = "Orange"; |
| 51 | + break; |
| 52 | + case HATCH: |
| 53 | + lights.set(Relay.Value.kReverse); |
| 54 | + color = "Blue"; |
| 55 | + break; |
| 56 | + case CLIMBER: |
| 57 | + lights.set(Relay.Value.kOn); |
| 58 | + color = "Rainbow"; |
| 59 | + break; |
41 | 60 | } |
| 61 | + lightsState = newState; |
42 | 62 | SmartDashboard.putString("Lights Current Color", color); |
43 | 63 | } |
44 | 64 |
|
45 | 65 | public void toggleLights() { |
46 | | - if (lightsValue == 0) { |
47 | | - lightsValue = 0.5; |
48 | | - } else if (lightsValue == 0.5) { |
49 | | - lightsValue = 1; |
50 | | - } else { |
51 | | - lightsValue = 0; |
| 66 | + if (lightsState == LightState.OFF) { |
| 67 | + lightsState = LightState.CARGO; |
| 68 | + } else if (lightsState == LightState.CARGO) { |
| 69 | + lightsState = LightState.HATCH; |
| 70 | + } else if (lightsState == LightState.HATCH) { |
| 71 | + lightsState = LightState.CLIMBER; |
| 72 | + } |
| 73 | + else { |
| 74 | + lightsState = LightState.OFF; |
52 | 75 | } |
53 | 76 | } |
54 | 77 |
|
55 | 78 | @Override |
56 | 79 | public void initDefaultCommand() { |
57 | | - setDefaultCommand(new SetLight(this)); |
| 80 | + setDefaultCommand(new SetLight(this, LightState.HATCH)); |
58 | 81 | } |
59 | 82 | } |
0 commit comments