Skip to content

Commit c6192e1

Browse files
committed
made all the nessecary changes
1 parent daec791 commit c6192e1

File tree

3 files changed

+53
-42
lines changed

3 files changed

+53
-42
lines changed

src/main/java/frc/robot/constants/LEDConstants.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
public class LEDConstants {
66
// Auto/Operator = 27
77
// other = 21.5
8-
public static final int kStripLength = 70;
8+
public static final int kTotalStripLength = 70;
9+
public static final int kBottomStripLength = 43;
10+
public static final int kTopStripLength = 27;
11+
public static final int kTopFirstIndex = kBottomStripLength + 1;
912

10-
public static final int kAlgeaEnd = kStripLength / 3;
11-
public static final int kLevelStart = kStripLength / 3;
12-
public static final int kPlaceStart = kStripLength / 9 * 7;
13-
public static final int kGetAlgeaStart = kStripLength / 9 * 8;
13+
public static final int kAlgeaEnd = kBottomStripLength / 3 + 1;
14+
public static final int kLevelStart = kTopFirstIndex;
15+
public static final int kPlaceStart = kTopFirstIndex + kTopStripLength / 3;
16+
public static final int kGetAlgeaStart = kTopFirstIndex + kTopStripLength / 3 * 2;
17+
public static final int kAutoPlacingStart = kTopFirstIndex;
1418

1519
public static final Color kAlmostBlack = new Color(0, 0, 1);
1620

@@ -41,6 +45,7 @@ public class LEDConstants {
4145
// Climb LED Colors
4246
public static final Color kWaitingForCage = Color.kRed;
4347
public static final Color kHasCage = Color.kGreen;
48+
public static final Color kClimbed = Color.kGoldenrod;
4449
public static final Color[] kGameColors = {
4550
Color.kBlack, // a dummy color
4651
Color.kDarkRed,

src/main/java/frc/robot/subsystems/led/LEDIO.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@
22

33
import edu.wpi.first.wpilibj.AddressableLED;
44
import edu.wpi.first.wpilibj.AddressableLEDBuffer;
5+
import edu.wpi.first.wpilibj.AddressableLEDBufferView;
56
import edu.wpi.first.wpilibj.LEDPattern;
67
import edu.wpi.first.wpilibj.util.Color;
8+
import frc.robot.constants.LEDConstants;
79

810
public class LEDIO {
911
private AddressableLED ledBase;
1012
private AddressableLEDBuffer led;
13+
private AddressableLEDBufferView ledTop;
1114

1215
public LEDIO(int port, int length) {
1316
ledBase = new AddressableLED(port);
1417
ledBase.setLength(length);
1518
ledBase.start();
1619
led = new AddressableLEDBuffer(length);
20+
ledTop = led.createView(LEDConstants.kTopFirstIndex, LEDConstants.kTotalStripLength + 1);
1721
ledBase.setData(led);
1822
}
1923

@@ -28,6 +32,7 @@ public void setPort(int port) {
2832
public void setLength(int length) {
2933
ledBase.setLength(length);
3034
led = new AddressableLEDBuffer(length);
35+
ledTop = led.createView(LEDConstants.kTopFirstIndex, LEDConstants.kTotalStripLength + 1);
3136
ledBase.setData(led);
3237
}
3338

@@ -47,6 +52,18 @@ public Color getLED(int index) {
4752
return led.getLED(index);
4853
}
4954

55+
public void setLEDTop(int index, Color color) {
56+
ledTop.setLED(index, color);
57+
}
58+
59+
public void setLEDTop(int index, int r, int g, int b) {
60+
ledTop.setRGB(index, r, g, b);
61+
}
62+
63+
public Color getLEDTop(int index) {
64+
return ledTop.getLED(index);
65+
}
66+
5067
public void setOff() {
5168
for (int i = 0; i < led.getLength(); i++) {
5269
setLED(i, Color.kBlack);

src/main/java/frc/robot/subsystems/led/LEDSubsystem.java

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import edu.wpi.first.wpilibj.LEDPattern.GradientType;
88
import edu.wpi.first.wpilibj.util.Color;
99
import frc.robot.constants.LEDConstants;
10+
import frc.robot.subsystems.robotState.RobotStateSubsystem.CoralLoc;
11+
import frc.robot.subsystems.robotState.RobotStateSubsystem.ScoringLevel;
12+
1013
import java.util.Map;
1114
import java.util.Set;
1215
import org.strykeforce.telemetry.measurable.MeasurableSubsystem;
@@ -20,31 +23,31 @@ public class LEDSubsystem extends MeasurableSubsystem {
2023
// section patterns
2124
private LEDPattern algea =
2225
LEDPattern.steps(
23-
Map.of(0, LEDConstants.kHasAlgea, LEDConstants.kStripLength / 3, Color.kBlack));
26+
Map.of(0, LEDConstants.kHasAlgea, LEDConstants.kAlgeaEnd, Color.kBlack));
2427
private LEDPattern coral = LEDPattern.solid(LEDConstants.kCoralInRobot);
2528
private LEDPattern level = LEDPattern.steps(Map.of(LEDConstants.kLevelStart, LEDConstants.kL1));
2629
private LEDPattern place =
2730
LEDPattern.steps(Map.of(LEDConstants.kPlaceStart, LEDConstants.kManual));
2831
private LEDPattern getAlgea =
2932
LEDPattern.steps(Map.of(LEDConstants.kGetAlgeaStart, LEDConstants.kNotGetAlgea));
3033
private LEDPattern autoplace =
31-
LEDPattern.steps(Map.of(LEDConstants.kStripLength / 3 * 2, LEDConstants.kAutoPlacing))
34+
LEDPattern.steps(Map.of(LEDConstants.kAutoPlacingStart, LEDConstants.kAutoPlacing))
3235
.blink(Seconds.of(0.25));
3336
private LEDPattern currentLimiting =
3437
LEDPattern.solid(LEDConstants.kCurrentLimiting).blink(Seconds.of(1), Seconds.of(2));
3538

3639
// section booleans and states
3740
private boolean hasAlgae = false;
38-
private CoralStates coralState = CoralStates.NO_PIECE;
39-
private LevelStates levelState = LevelStates.L1;
41+
private CoralLoc coralState = CoralLoc.NONE;
42+
private ScoringLevel levelState = ScoringLevel.L1;
4043
private PlaceStates placeState = PlaceStates.MANUAL;
4144
private boolean shouldGetAlgea = false;
4245
private boolean autoPlacing = false;
4346
private boolean isLimiting = false;
4447

4548
// game stuff
46-
private int[] BottomUnits = new int[LEDConstants.kStripLength];
47-
private int[] TopUnits = new int[LEDConstants.kStripLength];
49+
private int[] BottomUnits = new int[LEDConstants.kTopStripLength];
50+
private int[] TopUnits = new int[LEDConstants.kTopStripLength];
4851

4952
public LEDSubsystem(LEDIO io) {
5053
this.io = io;
@@ -66,10 +69,7 @@ public void setState(LEDStates state) {
6669
io.setStrip(LEDConstants.kHasCage);
6770
break;
6871
case CLIMB_UP:
69-
// base =
70-
// LEDPattern.gradient(GradientType.kContinuous, Color.kLightGoldenrodYellow, Color.kBlack)
71-
// .scrollAtRelativeSpeed(Percent.per(Seconds).of(1));
72-
io.setOff();
72+
io.setStrip(LEDConstants.kClimbed);
7373
break;
7474
default:
7575
break;
@@ -86,12 +86,12 @@ public void setAlgeaLights(boolean on) {
8686
buildBase();
8787
}
8888

89-
public void setCoralLights(CoralStates state) {
89+
public void setCoralLights(CoralLoc state) {
9090
coralState = state;
9191
buildBase();
9292
}
9393

94-
public void setLevelLights(LevelStates state) {
94+
public void setLevelLights(ScoringLevel state) {
9595
levelState = state;
9696
buildBase();
9797
}
@@ -121,11 +121,11 @@ public boolean getAlgeaLights() {
121121
return hasAlgae;
122122
}
123123

124-
public CoralStates getCoralLights() {
124+
public CoralLoc getCoralLights() {
125125
return coralState;
126126
}
127127

128-
public LevelStates getLevelLights() {
128+
public ScoringLevel getLevelLights() {
129129
return levelState;
130130
}
131131

@@ -151,16 +151,18 @@ private void buildBase() {
151151
Map.of(
152152
0,
153153
hasAlgae ? LEDConstants.kHasAlgea : LEDConstants.kNotHasAlgea,
154-
LEDConstants.kStripLength / 3,
154+
LEDConstants.kAlgeaEnd,
155155
Color.kBlack));
156156
switch (coralState) {
157-
case IN_FUNNEL:
157+
case FUNNEL:
158+
case TRANSFER:
158159
coral = LEDPattern.solid(LEDConstants.kCoralInFunnel);
159160
break;
160-
case IN_ROBOT:
161+
case CORAL:
162+
case SCORING:
161163
coral = LEDPattern.solid(LEDConstants.kCoralInRobot);
162164
break;
163-
case NO_PIECE:
165+
case NONE:
164166
coral = LEDPattern.solid(LEDConstants.kCoralNotInRobot);
165167
break;
166168
}
@@ -196,12 +198,12 @@ private void buildBase() {
196198

197199
//game stuff
198200
private void advanceUnits() {
199-
for (int i = 0; i <= LEDConstants.kStripLength-1; i++) {
201+
for (int i = 0; i <= LEDConstants.kTopStripLength+1; i++) {
200202
BottomUnits[i + 1] = BottomUnits[i];
201203
TopUnits[i] = TopUnits[i + 1];
202204
if (i == 0)
203205
BottomUnits[i] = 0;
204-
if (i == LEDConstants.kStripLength)
206+
if (i == LEDConstants.kTopStripLength)
205207
TopUnits[i] = 0;
206208
if (TopUnits[i] != 0 && BottomUnits[i] != 0) {
207209
if (BottomUnits[i] == TopUnits[i]) {
@@ -227,10 +229,10 @@ private void advanceUnits() {
227229
}
228230

229231
private void displayUnits() {
230-
for (int i = 0; i <= LEDConstants.kStripLength-1; i++) {
231-
io.setLED(i, LEDConstants.kGameColors[BottomUnits[i]]);
232+
for (int i = 0; i <= LEDConstants.kTopStripLength+1; i++) {
233+
io.setLEDTop(i, LEDConstants.kGameColors[BottomUnits[i]]);
232234
if (TopUnits[i] != 0){
233-
io.setLED(i, LEDConstants.kGameColors[TopUnits[i] + 3]);
235+
io.setLEDTop(i, LEDConstants.kGameColors[TopUnits[i] + 3]);
234236
}
235237
}
236238
}
@@ -241,7 +243,7 @@ public void addGameUnit(boolean isBottom, int unitNum) {
241243
if (isBottom){
242244
BottomUnits[0] = unitNum;
243245
} else {
244-
TopUnits[LEDConstants.kStripLength - 1] = unitNum;
246+
TopUnits[LEDConstants.kTopStripLength - 1] = unitNum;
245247
}
246248
}
247249
}
@@ -312,19 +314,6 @@ public enum LEDStates {
312314
CLIMB_UP
313315
}
314316

315-
public enum CoralStates {
316-
IN_FUNNEL,
317-
IN_ROBOT,
318-
NO_PIECE
319-
}
320-
321-
public enum LevelStates {
322-
L1,
323-
L2,
324-
L3,
325-
L4
326-
}
327-
328317
public enum PlaceStates {
329318
MANUAL,
330319
LEFT,

0 commit comments

Comments
 (0)