2
2
3
3
import static edu .wpi .first .units .Units .Seconds ;
4
4
5
+ import edu .wpi .first .math .geometry .Pose2d ;
5
6
import edu .wpi .first .units .measure .Time ;
6
7
import edu .wpi .first .wpilibj .AddressableLED ;
7
8
import edu .wpi .first .wpilibj .AddressableLEDBuffer ;
9
+ import edu .wpi .first .wpilibj .AddressableLEDBufferView ;
8
10
import edu .wpi .first .wpilibj .DriverStation .Alliance ;
9
11
import edu .wpi .first .wpilibj .LEDPattern ;
10
12
import edu .wpi .first .wpilibj .util .Color ;
17
19
18
20
public class LEDs extends SubsystemBase {
19
21
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 =
22
24
new AddressableLEDBuffer (LedConstants .kLedBufferLength );
25
+ private final AddressableLEDBufferView leftStrip = ledBuffer .createView (20 , 39 ).reversed ();
26
+ private final AddressableLEDBufferView rightStrip = ledBuffer .createView (0 , 19 );
23
27
24
28
public LEDs () {
25
- m_led .setLength (m_ledData .getLength ());
26
- m_led .start ();
29
+ led .setLength (ledBuffer .getLength ());
30
+ led .start ();
27
31
}
28
32
29
33
@ Override
30
34
public void periodic () {
31
- m_led .setData (m_ledData );
35
+ led .setData (ledBuffer );
32
36
}
33
37
34
38
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 );
37
41
}
38
42
}
39
43
44
+ private void setBoth (int index , Color color ) {
45
+ leftStrip .setLED (index , color );
46
+ rightStrip .setLED (index , color );
47
+ }
48
+
40
49
private void autoColor (Alliance alliance , int autoMode ) {
41
50
clearBuffer ();
42
51
int block = LedConstants .kLEDsPerBlock + LedConstants .kLEDsBetweenBlocks ;
43
52
if (1 > autoMode ) { // 0 indicates no auto selected.
44
53
for (var led = 0 ; led < LedConstants .kLEDsPerBlock ; led ++) {
45
- m_ledData . setLED (led , Color .kYellow );
54
+ setBoth (led , Color .kYellow );
46
55
}
47
56
} else {
48
57
for (var mode = 0 ; mode < autoMode ; mode ++) {
49
58
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 );
55
60
}
56
61
}
57
62
}
58
- m_led .setData (m_ledData );
63
+ led .setData (ledBuffer );
59
64
}
60
65
61
66
public Command createEnabledCommand () {
@@ -65,6 +70,35 @@ public Command createEnabledCommand() {
65
70
});
66
71
}
67
72
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
+
68
102
public Command createDisabledCommand (
69
103
IntSupplier autoSwitchPositionSupplier ,
70
104
Supplier <Alliance > allianceColorSupplier ,
@@ -84,7 +118,8 @@ public Command createChangeAutoAnimationCommand() {
84
118
LEDPattern scrollingRainbow = rainbow .scrollAtRelativeSpeed (duration .asFrequency ());
85
119
return this .run (
86
120
() -> {
87
- scrollingRainbow .applyTo (m_ledData );
121
+ scrollingRainbow .applyTo (leftStrip );
122
+ scrollingRainbow .applyTo (rightStrip );
88
123
})
89
124
.withTimeout (duration )
90
125
.ignoringDisable (true );
0 commit comments