Skip to content

Commit df80317

Browse files
Leds (#99)
* Updates for new robot * Merge and fix * Remove unused imports * ran spotless --------- Co-authored-by: DylanTaylor29 <[email protected]>
1 parent 1e844fa commit df80317

File tree

2 files changed

+51
-16
lines changed

2 files changed

+51
-16
lines changed

src/main/java/frc/robot/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public static final class ClimberConstants {
292292
}
293293

294294
public static final class LedConstants {
295-
public static final int kLedPort = 0;
295+
public static final int kLedPort = 9;
296296
public static final int kLedBufferLength = 40;
297297

298298
public static final int kLEDsPerBlock = 2;

src/main/java/frc/robot/LEDs/LEDs.java

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import static edu.wpi.first.units.Units.Seconds;
44

5+
import edu.wpi.first.math.geometry.Pose2d;
56
import edu.wpi.first.units.measure.Time;
67
import edu.wpi.first.wpilibj.AddressableLED;
78
import edu.wpi.first.wpilibj.AddressableLEDBuffer;
9+
import edu.wpi.first.wpilibj.AddressableLEDBufferView;
810
import edu.wpi.first.wpilibj.DriverStation.Alliance;
911
import edu.wpi.first.wpilibj.LEDPattern;
1012
import edu.wpi.first.wpilibj.util.Color;
@@ -17,45 +19,48 @@
1719

1820
public class LEDs extends SubsystemBase {
1921

20-
private final AddressableLED m_led = new AddressableLED(LedConstants.kLedPort);
21-
private final AddressableLEDBuffer m_ledData =
22+
private final AddressableLED led = new AddressableLED(LedConstants.kLedPort);
23+
private final AddressableLEDBuffer ledBuffer =
2224
new AddressableLEDBuffer(LedConstants.kLedBufferLength);
25+
private final AddressableLEDBufferView leftStrip = ledBuffer.createView(20, 39).reversed();
26+
private final AddressableLEDBufferView rightStrip = ledBuffer.createView(0, 19);
2327

2428
public LEDs() {
25-
m_led.setLength(m_ledData.getLength());
26-
m_led.start();
29+
led.setLength(ledBuffer.getLength());
30+
led.start();
2731
}
2832

2933
@Override
3034
public void periodic() {
31-
m_led.setData(m_ledData);
35+
led.setData(ledBuffer);
3236
}
3337

3438
private void clearBuffer() {
35-
for (var i = 0; i < m_ledData.getLength(); i++) {
36-
m_ledData.setRGB(i, 0, 0, 0);
39+
for (var i = 0; i < ledBuffer.getLength(); i++) {
40+
ledBuffer.setRGB(i, 0, 0, 0);
3741
}
3842
}
3943

44+
private void setBoth(int index, Color color) {
45+
leftStrip.setLED(index, color);
46+
rightStrip.setLED(index, color);
47+
}
48+
4049
private void autoColor(Alliance alliance, int autoMode) {
4150
clearBuffer();
4251
int block = LedConstants.kLEDsPerBlock + LedConstants.kLEDsBetweenBlocks;
4352
if (1 > autoMode) { // 0 indicates no auto selected.
4453
for (var led = 0; led < LedConstants.kLEDsPerBlock; led++) {
45-
m_ledData.setLED(led, Color.kYellow);
54+
setBoth(led, Color.kYellow);
4655
}
4756
} else {
4857
for (var mode = 0; mode < autoMode; mode++) {
4958
for (var i = 0; i < LedConstants.kLEDsPerBlock; i++) {
50-
if (alliance.equals(Alliance.Red)) {
51-
m_ledData.setLED(i + (mode * block), Color.kRed);
52-
} else {
53-
m_ledData.setLED(i + (mode * block), Color.kBlue);
54-
}
59+
setBoth(i + (mode * block), alliance == Alliance.Red ? Color.kRed : Color.kBlue);
5560
}
5661
}
5762
}
58-
m_led.setData(m_ledData);
63+
led.setData(ledBuffer);
5964
}
6065

6166
public Command createEnabledCommand() {
@@ -65,6 +70,35 @@ public Command createEnabledCommand() {
6570
});
6671
}
6772

73+
/*
74+
* Use LEDs to indicate how to move the robot from the current pose
75+
* to the target pose. The directions must indicate:
76+
*
77+
* (1) Heading - how to face the robot in the correct direction
78+
* - Use outer pixels to indicate heading: Both green indicates
79+
* proper heading. Red on one side means rotate away from that
80+
* side.
81+
*
82+
* (2) Distance - how far from target
83+
* - Some portion of interior pixels light up. More pixels
84+
* means more distance. Red means backwards, relative to
85+
* the robot; green means forward, yellow means sideways.
86+
*
87+
* (3) Direction - which angle to move the robot
88+
* - Offset of pixel block indicates which angle: close to center
89+
* means pretty much straight, close to edge means diagonal.
90+
*
91+
*/
92+
public void indicatePoseSeek(Pose2d currentPose, Pose2d targetPose) {
93+
var delta = targetPose.minus(currentPose);
94+
}
95+
96+
public Command createPoseSeekingCommand(
97+
Supplier<Pose2d> targetPoseSupplier, Supplier<Pose2d> currentPoseSupplier) {
98+
return this.run(() -> indicatePoseSeek(currentPoseSupplier.get(), targetPoseSupplier.get()))
99+
.ignoringDisable(true);
100+
}
101+
68102
public Command createDisabledCommand(
69103
IntSupplier autoSwitchPositionSupplier,
70104
Supplier<Alliance> allianceColorSupplier,
@@ -84,7 +118,8 @@ public Command createChangeAutoAnimationCommand() {
84118
LEDPattern scrollingRainbow = rainbow.scrollAtRelativeSpeed(duration.asFrequency());
85119
return this.run(
86120
() -> {
87-
scrollingRainbow.applyTo(m_ledData);
121+
scrollingRainbow.applyTo(leftStrip);
122+
scrollingRainbow.applyTo(rightStrip);
88123
})
89124
.withTimeout(duration)
90125
.ignoringDisable(true);

0 commit comments

Comments
 (0)