From 6421de4a9f2133f7d9142430e85b6d8ec6d778a3 Mon Sep 17 00:00:00 2001 From: RobotLeopard86 <63123751+RobotLeopard86@users.noreply.github.com> Date: Mon, 24 Feb 2025 17:19:26 -0800 Subject: [PATCH 01/21] Add initial AddressableLED subsystem implementation --- .../commands/SetAddressableLEDPattern.java | 40 ++++++++++++++++ .../AddressableLEDConstants.java | 10 ++++ .../AddressableLEDSubsystem.java | 46 +++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 src/main/java/frc/robot/commands/SetAddressableLEDPattern.java create mode 100644 src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java create mode 100644 src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java diff --git a/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java b/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java new file mode 100644 index 00000000..7aed2755 --- /dev/null +++ b/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java @@ -0,0 +1,40 @@ +package frc.robot.commands; + +import edu.wpi.first.wpilibj.LEDPattern; +import edu.wpi.first.wpilibj2.command.Command; + +public class SetAddressableLEDPattern extends Command { + private final AddressableLEDSubsystem ledSystem; + private final int + section; // If this is -1, that means that this command is targeting the whole strip + private final LEDPattern pattern; + + /** + * @param + */ + public SetAddressableLEDPattern(AddressableLEDSubsystem led, LEDPattern pattern, int section) { + this.section = section; + this.pattern = pattern; + ledSystem = led; + } + + public SetAddressableLEDPattern(AddressableLEDSubsystem led, LEDPattern pattern) { + this(led, pattern, -1); + } + + public void initialize() {} + + public void execute() { + if (section < 0) { + ledSystem.applyPattern(pattern); + } else { + ledSystem.applySectionedPattern(pattern, section); + } + } + + public boolean isFinished() { + return true; + } + + public void end(boolean interrupted) {} +} diff --git a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java new file mode 100644 index 00000000..56fd811c --- /dev/null +++ b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java @@ -0,0 +1,10 @@ +package frc.robot.subsystems.addressableled; + +public class AddressableLEDConstants { + private record Range(int low, int high) {} + + // TODO: Implement real values + public static final int LED_COUNT = 64; + public static final int LED_STRIP_PORT = 0; + public static final Range SECTIONS[] = {new Range(0, LED_COUNT)}; +} diff --git a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java new file mode 100644 index 00000000..fbf04745 --- /dev/null +++ b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java @@ -0,0 +1,46 @@ +package frc.robot.subsystems.addressableled; + +import edu.wpi.first.wpilibj.AddressableLED; +import edu.wpi.first.wpilibj.AddressableLEDBuffer; +import edu.wpi.first.wpilibj.AddressableLEDBufferView; +import edu.wpi.first.wpilibj.LEDPattern; +import edu.wpi.first.wpilibj2.command.SubsystemBase; + +public class AddressableLEDSubsystem extends SubsystemBase { + private final AddressableLED led; + private final AddressableLEDBuffer ledBuffer; + private AddressableLEDBufferView ledViews[]; + + public AddressableLEDSubsystem() { + // Create strip and buffer + led = new AddressableLED(AddressableLEDConstants.LED_STRIP_PORT); + ledBuffer = new AddressableLEDBuffer(AddressableLEDConstants.LED_COUNT); + led.setLength(AddressableLEDConstants.LED_COUNT); + + // Create section views + ledViews = new AddressableLEDBufferView[AddressableLEDConstants.SECTIONS.length]; + for (int i = 0; i < ledViews.length; i++) { + ledViews[i] = + new AddressableLEDBufferView( + ledBuffer, + AddressableLEDConstants.SECTIONS[i].low, + AddressableLEDConstants.SECTIONS[i].high); + } + } + + // Periodically update the LED strip + public void periodic() { + led.setData(ledBuffer); + } + + // Apply a color pattern to a section of the LED strip + public void applySectionedPattern(LEDPattern pattern, int section) { + if (section < 0 || section >= ledViews.length) return; + pattern.applyTo(ledViews[section]); + } + + // Apply a color pattern to a section of the LED strip + public void applyPattern(LEDPattern pattern) { + pattern.applyTo(ledBuffer); + } +} From fa8e40a3c37486d5a99a3549220e2131455b3a80 Mon Sep 17 00:00:00 2001 From: RobotLeopard86 <63123751+RobotLeopard86@users.noreply.github.com> Date: Mon, 24 Feb 2025 17:24:02 -0800 Subject: [PATCH 02/21] Fix missing imports and improper record access --- .../java/frc/robot/commands/SetAddressableLEDPattern.java | 1 + .../subsystems/addressableled/AddressableLEDConstants.java | 2 +- .../subsystems/addressableled/AddressableLEDSubsystem.java | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java b/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java index 7aed2755..cb6bb6c2 100644 --- a/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java +++ b/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java @@ -2,6 +2,7 @@ import edu.wpi.first.wpilibj.LEDPattern; import edu.wpi.first.wpilibj2.command.Command; +import frc.robot.subsystems.addressableled.AddressableLEDSubsystem; public class SetAddressableLEDPattern extends Command { private final AddressableLEDSubsystem ledSystem; diff --git a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java index 56fd811c..40639882 100644 --- a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java +++ b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java @@ -1,7 +1,7 @@ package frc.robot.subsystems.addressableled; public class AddressableLEDConstants { - private record Range(int low, int high) {} + public record Range(int low, int high) {} // TODO: Implement real values public static final int LED_COUNT = 64; diff --git a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java index fbf04745..5ef39728 100644 --- a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java +++ b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java @@ -23,8 +23,8 @@ public AddressableLEDSubsystem() { ledViews[i] = new AddressableLEDBufferView( ledBuffer, - AddressableLEDConstants.SECTIONS[i].low, - AddressableLEDConstants.SECTIONS[i].high); + AddressableLEDConstants.SECTIONS[i].low(), + AddressableLEDConstants.SECTIONS[i].high()); } } From 8b27e762a933baec671570c19d614fc412264805 Mon Sep 17 00:00:00 2001 From: RobotLeopard86 <63123751+RobotLeopard86@users.noreply.github.com> Date: Mon, 24 Feb 2025 17:50:51 -0800 Subject: [PATCH 03/21] Add missing @Override declarations and add Javadoc --- .../commands/SetAddressableLEDPattern.java | 25 +++++++++++++------ .../AddressableLEDSubsystem.java | 1 + 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java b/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java index cb6bb6c2..d8b9265d 100644 --- a/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java +++ b/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java @@ -6,12 +6,17 @@ public class SetAddressableLEDPattern extends Command { private final AddressableLEDSubsystem ledSystem; - private final int - section; // If this is -1, that means that this command is targeting the whole strip + + // If this is -1, that means that this command is targeting the whole strip + private final int section; + private final LEDPattern pattern; /** - * @param + * @param led Addressable LED subsystem to use + * @param pattern Pattern to apply when command run + * @param section Section of LED strip to apply pattern to (index into + * AddressableLEDConstants.SECTIONS) */ public SetAddressableLEDPattern(AddressableLEDSubsystem led, LEDPattern pattern, int section) { this.section = section; @@ -19,12 +24,17 @@ public SetAddressableLEDPattern(AddressableLEDSubsystem led, LEDPattern pattern, ledSystem = led; } + /** + * @param led Addressable LED subsystem to use + * @param pattern Pattern to apply when command run + */ public SetAddressableLEDPattern(AddressableLEDSubsystem led, LEDPattern pattern) { - this(led, pattern, -1); + this.section = -1; + this.pattern = pattern; + ledSystem = led; } - public void initialize() {} - + @Override public void execute() { if (section < 0) { ledSystem.applyPattern(pattern); @@ -33,9 +43,8 @@ public void execute() { } } + @Override public boolean isFinished() { return true; } - - public void end(boolean interrupted) {} } diff --git a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java index 5ef39728..71395b90 100644 --- a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java +++ b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java @@ -29,6 +29,7 @@ public AddressableLEDSubsystem() { } // Periodically update the LED strip + @Override public void periodic() { led.setData(ledBuffer); } From e8279961ef999308c157b6fdf3bb724f5c8a0f82 Mon Sep 17 00:00:00 2001 From: RobotLeopard86 <63123751+RobotLeopard86@users.noreply.github.com> Date: Wed, 26 Feb 2025 17:14:36 -0800 Subject: [PATCH 04/21] Address code review feedback for AddressableLED subsystem and add scaffold for testing command --- .../frc/robot/commands/SetAddressableLEDPattern.java | 12 +++++++----- .../commands/test/AddressableLEDTestCommand.java | 5 +++++ 2 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 src/main/java/frc/robot/commands/test/AddressableLEDTestCommand.java diff --git a/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java b/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java index d8b9265d..ef9067e3 100644 --- a/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java +++ b/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java @@ -18,20 +18,22 @@ public class SetAddressableLEDPattern extends Command { * @param section Section of LED strip to apply pattern to (index into * AddressableLEDConstants.SECTIONS) */ - public SetAddressableLEDPattern(AddressableLEDSubsystem led, LEDPattern pattern, int section) { + public SetAddressableLEDPattern(AddressableLEDSubsystem ledSystem, LEDPattern pattern, int section) { this.section = section; this.pattern = pattern; - ledSystem = led; + this.ledSystem = ledSystem; + addRequirements(ledSystem); } /** * @param led Addressable LED subsystem to use * @param pattern Pattern to apply when command run */ - public SetAddressableLEDPattern(AddressableLEDSubsystem led, LEDPattern pattern) { - this.section = -1; + public SetAddressableLEDPattern(AddressableLEDSubsystem ledSystem, LEDPattern pattern) { + section = -1; this.pattern = pattern; - ledSystem = led; + this.ledSystem = ledSystem; + addRequirements(ledSystem); } @Override diff --git a/src/main/java/frc/robot/commands/test/AddressableLEDTestCommand.java b/src/main/java/frc/robot/commands/test/AddressableLEDTestCommand.java new file mode 100644 index 00000000..558dab29 --- /dev/null +++ b/src/main/java/frc/robot/commands/test/AddressableLEDTestCommand.java @@ -0,0 +1,5 @@ +package frc.robot.commands.test; + +public class AddressableLEDTestCommand extends Command { + +} From fad22dbdd3bda39a6205574bf601f8fe9e89de58 Mon Sep 17 00:00:00 2001 From: RobotLeopard86 <63123751+RobotLeopard86@users.noreply.github.com> Date: Wed, 26 Feb 2025 17:28:31 -0800 Subject: [PATCH 05/21] Add AddressableLED testing command --- .../test/AddressableLEDTestCommand.java | 50 ++++++++++++++++++- .../AddressableLEDConstants.java | 5 ++ .../AddressableLEDSubsystem.java | 11 ++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/main/java/frc/robot/commands/test/AddressableLEDTestCommand.java b/src/main/java/frc/robot/commands/test/AddressableLEDTestCommand.java index 558dab29..2416d51d 100644 --- a/src/main/java/frc/robot/commands/test/AddressableLEDTestCommand.java +++ b/src/main/java/frc/robot/commands/test/AddressableLEDTestCommand.java @@ -1,5 +1,53 @@ package frc.robot.commands.test; +import static edu.wpi.first.units.Units.MetersPerSecond; +import static edu.wpi.first.units.Units.Seconds; + +import edu.wpi.first.wpilibj.LEDPattern; +import edu.wpi.first.wpilibj.util.Color; +import edu.wpi.first.wpilibj2.command.Command; +import frc.robot.subsystems.addressableled.AddressableLEDConstants; +import frc.robot.subsystems.addressableled.AddressableLEDSubsystem; + public class AddressableLEDTestCommand extends Command { - + private final AddressableLEDSubsystem ledSystem; + private LEDPattern currentPattern; + private int ticker = 0; + private int testCount = 0; + + public AddressableLEDTestCommand(AddressableLEDSubsystem ledSystem) { + this.ledSystem = ledSystem; + addRequirements(ledSystem); + } + + @Override + public void initialize() { + ticker = 0; + testCount = 0; + currentPattern = LEDPattern.rainbow(255, 128).scrollAtAbsoluteSpeed(MetersPerSecond.of(1), AddressableLEDConstants.LED_DENSITY); + } + + @Override + public void execute() { + if(ticker < 500) { + ticker++; + } else { + ticker = 0; + testCount++; + if(testCount == AddressableLEDConstants.SECTIONS.length) { + currentPattern = LEDPattern.solid(Color.kLimeGreen).breathe(Seconds.of(2)); + } + } + } + + @Override + public boolean isFinished() { + return testCount < (AddressableLEDConstants.SECTIONS.length + 1); + } + + @Override + public void end(boolean interrupted) { + // TODO Auto-generated method stub + super.end(interrupted); + } } diff --git a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java index 40639882..033065c5 100644 --- a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java +++ b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java @@ -1,10 +1,15 @@ package frc.robot.subsystems.addressableled; +import static edu.wpi.first.units.Units.Meters; + +import edu.wpi.first.units.measure.Distance; + public class AddressableLEDConstants { public record Range(int low, int high) {} // TODO: Implement real values public static final int LED_COUNT = 64; + public static final Distance LED_DENSITY = Meters.of(1.0 / LED_COUNT); public static final int LED_STRIP_PORT = 0; public static final Range SECTIONS[] = {new Range(0, LED_COUNT)}; } diff --git a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java index 71395b90..cde651db 100644 --- a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java +++ b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java @@ -10,6 +10,7 @@ public class AddressableLEDSubsystem extends SubsystemBase { private final AddressableLED led; private final AddressableLEDBuffer ledBuffer; private AddressableLEDBufferView ledViews[]; + private LEDPattern[] currentPatterns; public AddressableLEDSubsystem() { // Create strip and buffer @@ -17,6 +18,9 @@ public AddressableLEDSubsystem() { ledBuffer = new AddressableLEDBuffer(AddressableLEDConstants.LED_COUNT); led.setLength(AddressableLEDConstants.LED_COUNT); + //Create current pattern trackers + currentPatterns = new LEDPattern[AddressableLEDConstants.SECTIONS.length]; + // Create section views ledViews = new AddressableLEDBufferView[AddressableLEDConstants.SECTIONS.length]; for (int i = 0; i < ledViews.length; i++) { @@ -31,6 +35,9 @@ public AddressableLEDSubsystem() { // Periodically update the LED strip @Override public void periodic() { + for(int i = 0; i < ledViews.length; i++) { + currentPatterns[i].applyTo(ledViews[i]); + } led.setData(ledBuffer); } @@ -38,10 +45,14 @@ public void periodic() { public void applySectionedPattern(LEDPattern pattern, int section) { if (section < 0 || section >= ledViews.length) return; pattern.applyTo(ledViews[section]); + currentPatterns[section] = pattern; } // Apply a color pattern to a section of the LED strip public void applyPattern(LEDPattern pattern) { pattern.applyTo(ledBuffer); + for(int i = 0; i < currentPatterns.length; i++) { + currentPatterns[i] = pattern; + } } } From 74fb53fc197f2486fe647eef67ba68f08c8a3b3b Mon Sep 17 00:00:00 2001 From: RobotLeopard86 <63123751+RobotLeopard86@users.noreply.github.com> Date: Wed, 26 Feb 2025 17:44:38 -0800 Subject: [PATCH 06/21] Actually apply the patterns for the AddressableLED test --- .../frc/robot/commands/test/AddressableLEDTestCommand.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/frc/robot/commands/test/AddressableLEDTestCommand.java b/src/main/java/frc/robot/commands/test/AddressableLEDTestCommand.java index 2416d51d..eee33670 100644 --- a/src/main/java/frc/robot/commands/test/AddressableLEDTestCommand.java +++ b/src/main/java/frc/robot/commands/test/AddressableLEDTestCommand.java @@ -33,9 +33,13 @@ public void execute() { ticker++; } else { ticker = 0; + ledSystem.applySectionedPattern(LEDPattern.kOff, testCount); testCount++; if(testCount == AddressableLEDConstants.SECTIONS.length) { currentPattern = LEDPattern.solid(Color.kLimeGreen).breathe(Seconds.of(2)); + ledSystem.applyPattern(currentPattern); + } else { + ledSystem.applySectionedPattern(currentPattern, testCount); } } } @@ -47,7 +51,6 @@ public boolean isFinished() { @Override public void end(boolean interrupted) { - // TODO Auto-generated method stub - super.end(interrupted); + ledSystem.applyPattern(LEDPattern.kOff); } } From 0cc78fe727940912498e102ebd3fd9e230915b2b Mon Sep 17 00:00:00 2001 From: RobotLeopard86 <63123751+RobotLeopard86@users.noreply.github.com> Date: Wed, 26 Feb 2025 17:44:53 -0800 Subject: [PATCH 07/21] Run Spotless! --- .../java/frc/robot/commands/SetAddressableLEDPattern.java | 3 ++- .../robot/commands/test/AddressableLEDTestCommand.java | 8 +++++--- .../addressableled/AddressableLEDSubsystem.java | 6 +++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java b/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java index ef9067e3..f423ba6b 100644 --- a/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java +++ b/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java @@ -18,7 +18,8 @@ public class SetAddressableLEDPattern extends Command { * @param section Section of LED strip to apply pattern to (index into * AddressableLEDConstants.SECTIONS) */ - public SetAddressableLEDPattern(AddressableLEDSubsystem ledSystem, LEDPattern pattern, int section) { + public SetAddressableLEDPattern( + AddressableLEDSubsystem ledSystem, LEDPattern pattern, int section) { this.section = section; this.pattern = pattern; this.ledSystem = ledSystem; diff --git a/src/main/java/frc/robot/commands/test/AddressableLEDTestCommand.java b/src/main/java/frc/robot/commands/test/AddressableLEDTestCommand.java index eee33670..805eb0f1 100644 --- a/src/main/java/frc/robot/commands/test/AddressableLEDTestCommand.java +++ b/src/main/java/frc/robot/commands/test/AddressableLEDTestCommand.java @@ -24,18 +24,20 @@ public AddressableLEDTestCommand(AddressableLEDSubsystem ledSystem) { public void initialize() { ticker = 0; testCount = 0; - currentPattern = LEDPattern.rainbow(255, 128).scrollAtAbsoluteSpeed(MetersPerSecond.of(1), AddressableLEDConstants.LED_DENSITY); + currentPattern = + LEDPattern.rainbow(255, 128) + .scrollAtAbsoluteSpeed(MetersPerSecond.of(1), AddressableLEDConstants.LED_DENSITY); } @Override public void execute() { - if(ticker < 500) { + if (ticker < 500) { ticker++; } else { ticker = 0; ledSystem.applySectionedPattern(LEDPattern.kOff, testCount); testCount++; - if(testCount == AddressableLEDConstants.SECTIONS.length) { + if (testCount == AddressableLEDConstants.SECTIONS.length) { currentPattern = LEDPattern.solid(Color.kLimeGreen).breathe(Seconds.of(2)); ledSystem.applyPattern(currentPattern); } else { diff --git a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java index cde651db..7cbdfa91 100644 --- a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java +++ b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java @@ -18,7 +18,7 @@ public AddressableLEDSubsystem() { ledBuffer = new AddressableLEDBuffer(AddressableLEDConstants.LED_COUNT); led.setLength(AddressableLEDConstants.LED_COUNT); - //Create current pattern trackers + // Create current pattern trackers currentPatterns = new LEDPattern[AddressableLEDConstants.SECTIONS.length]; // Create section views @@ -35,7 +35,7 @@ public AddressableLEDSubsystem() { // Periodically update the LED strip @Override public void periodic() { - for(int i = 0; i < ledViews.length; i++) { + for (int i = 0; i < ledViews.length; i++) { currentPatterns[i].applyTo(ledViews[i]); } led.setData(ledBuffer); @@ -51,7 +51,7 @@ public void applySectionedPattern(LEDPattern pattern, int section) { // Apply a color pattern to a section of the LED strip public void applyPattern(LEDPattern pattern) { pattern.applyTo(ledBuffer); - for(int i = 0; i < currentPatterns.length; i++) { + for (int i = 0; i < currentPatterns.length; i++) { currentPatterns[i] = pattern; } } From 7f0147cbd67dc8e9ff6483f1fbf2857ffd9d7f64 Mon Sep 17 00:00:00 2001 From: RobotLeopard86 <63123751+RobotLeopard86@users.noreply.github.com> Date: Thu, 27 Feb 2025 15:36:43 -0800 Subject: [PATCH 08/21] Add Javadocs for AddressableLED subsystem I didn't forget to run Spotless this time! --- .../frc/robot/commands/SetAddressableLEDPattern.java | 4 +++- .../addressableled/AddressableLEDConstants.java | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java b/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java index f423ba6b..cf3ece76 100644 --- a/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java +++ b/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java @@ -7,7 +7,9 @@ public class SetAddressableLEDPattern extends Command { private final AddressableLEDSubsystem ledSystem; - // If this is -1, that means that this command is targeting the whole strip + /** + * @apiNote If this is -1, that means that this command is targeting the whole strip + */ private final int section; private final LEDPattern pattern; diff --git a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java index 033065c5..3d4f75f4 100644 --- a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java +++ b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java @@ -5,11 +5,20 @@ import edu.wpi.first.units.measure.Distance; public class AddressableLEDConstants { + /** + * @param low The lower bound of the range + * @param high The upper bound of the range + */ public record Range(int low, int high) {} // TODO: Implement real values public static final int LED_COUNT = 64; public static final Distance LED_DENSITY = Meters.of(1.0 / LED_COUNT); public static final int LED_STRIP_PORT = 0; + + /** + * @apiNote The lower bound of the range represents the lowest index LED for this section, and the + * upper bound represents the highest index LED + */ public static final Range SECTIONS[] = {new Range(0, LED_COUNT)}; } From 6cf0918718c808701f750c22c0a955c57bb804e9 Mon Sep 17 00:00:00 2001 From: RobotLeopard86 <63123751+RobotLeopard86@users.noreply.github.com> Date: Sat, 1 Mar 2025 11:28:30 -0800 Subject: [PATCH 09/21] Clarify separation between Blinkin and AddressableLED subsystems --- .../robot/commands/SetBlinkinLEDPattern.java | 43 +++++++++++++++++ .../frc/robot/commands/SetLightPattern.java | 46 ------------------- ...ommand.java => BlinkinLEDTestCommand.java} | 16 +++---- .../BlinkinLEDConstants.java} | 6 +-- .../BlinkinLEDSubsystem.java} | 12 +++-- .../superstructure/wrist/WristConstants.java | 2 +- 6 files changed, 62 insertions(+), 63 deletions(-) create mode 100644 src/main/java/frc/robot/commands/SetBlinkinLEDPattern.java delete mode 100644 src/main/java/frc/robot/commands/SetLightPattern.java rename src/main/java/frc/robot/commands/test/{LEDTestCommand.java => BlinkinLEDTestCommand.java} (63%) rename src/main/java/frc/robot/subsystems/{led/LEDConstants.java => blinkinled/BlinkinLEDConstants.java} (91%) rename src/main/java/frc/robot/subsystems/{led/LEDSubsystem.java => blinkinled/BlinkinLEDSubsystem.java} (81%) diff --git a/src/main/java/frc/robot/commands/SetBlinkinLEDPattern.java b/src/main/java/frc/robot/commands/SetBlinkinLEDPattern.java new file mode 100644 index 00000000..d563411a --- /dev/null +++ b/src/main/java/frc/robot/commands/SetBlinkinLEDPattern.java @@ -0,0 +1,43 @@ +package frc.robot.commands; + +import edu.wpi.first.wpilibj2.command.Command; +import frc.robot.subsystems.blinkinled.BlinkinLEDSubsystem; + +public class SetBlinkinLEDPattern extends Command { + private BlinkinLEDSubsystem ledSystem; + private double pattern; + + /** + * @apiNote If this is -1, that means that this command is targeting the whole strip + */ + private int section; + + private boolean invalid; + + public SetBlinkinLEDPattern(BlinkinLEDSubsystem ledSystem, int section, double pattern) { + invalid = (section < -1 || section >= ledSystem.stripCount); + this.section = section; + this.ledSystem = ledSystem; + this.pattern = pattern; + } + + public SetBlinkinLEDPattern(BlinkinLEDSubsystem led, double pattern) { + this(led, -1, pattern); + } + + @Override + public void initialize() { + if (invalid) return; + if (section == -1) { + ledSystem.applyPatternToAll(pattern); + } else { + ledSystem.applyPatternTo(section, pattern); + } + } + + // Since executing the command is a one-time thing, we always report being done instantly + @Override + public boolean isFinished() { + return true; + } +} diff --git a/src/main/java/frc/robot/commands/SetLightPattern.java b/src/main/java/frc/robot/commands/SetLightPattern.java deleted file mode 100644 index dd713fac..00000000 --- a/src/main/java/frc/robot/commands/SetLightPattern.java +++ /dev/null @@ -1,46 +0,0 @@ -package frc.robot.commands; - -import edu.wpi.first.wpilibj2.command.Command; -import frc.robot.subsystems.led.LEDSubsystem; - -public class SetLightPattern extends Command { - private LEDSubsystem ledSystem; - private double pattern; - - // Set this to -1 to have the command apply to all strips - private int stripID; - - public SetLightPattern(LEDSubsystem led, int strip, double pattern) { - if (strip < -1) - throw new IllegalArgumentException( - "LED configuration commands may ONLY use -1 (all strips) or higher for strip IDs!"); - ledSystem = led; - this.pattern = pattern; - } - - public SetLightPattern(LEDSubsystem led, double pattern) { - this(led, -1, pattern); - } - - @Override - public void initialize() {} - - @Override - public void execute() { - if (stripID == -1) { - ledSystem.applyPatternToAll(pattern); - } else { - ledSystem.applyPatternTo(stripID, pattern); - } - } - - // Since executing the command is a one-time thing, we always report being done instantly - - @Override - public boolean isFinished() { - return true; - } - - @Override - public void end(boolean interrupted) {} -} diff --git a/src/main/java/frc/robot/commands/test/LEDTestCommand.java b/src/main/java/frc/robot/commands/test/BlinkinLEDTestCommand.java similarity index 63% rename from src/main/java/frc/robot/commands/test/LEDTestCommand.java rename to src/main/java/frc/robot/commands/test/BlinkinLEDTestCommand.java index d5840d2e..4108253c 100644 --- a/src/main/java/frc/robot/commands/test/LEDTestCommand.java +++ b/src/main/java/frc/robot/commands/test/BlinkinLEDTestCommand.java @@ -1,11 +1,11 @@ package frc.robot.commands.test; import edu.wpi.first.wpilibj2.command.Command; -import frc.robot.subsystems.led.LEDConstants; -import frc.robot.subsystems.led.LEDSubsystem; +import frc.robot.subsystems.blinkinled.BlinkinLEDConstants; +import frc.robot.subsystems.blinkinled.BlinkinLEDSubsystem; -public class LEDTestCommand extends Command { - private LEDSubsystem ledSystem; +public class BlinkinLEDTestCommand extends Command { + private BlinkinLEDSubsystem ledSystem; private double currentPattern; @@ -17,14 +17,14 @@ public class LEDTestCommand extends Command { * @param time Time in robot updates to wait between changes (each update is 20ms, so 50 updates * is 1 second) */ - public LEDTestCommand(LEDSubsystem led, int time) { + public BlinkinLEDTestCommand(BlinkinLEDSubsystem led, int time) { ledSystem = led; delay = time; } @Override public void initialize() { - currentPattern = LEDConstants.LEDPatterns.BLACK; + currentPattern = BlinkinLEDConstants.Patterns.BLACK; ticker = 0; } @@ -39,11 +39,11 @@ public void execute() { @Override public boolean isFinished() { - return currentPattern <= LEDConstants.LEDPatterns.HOT_PINK; + return currentPattern <= BlinkinLEDConstants.Patterns.HOT_PINK; } @Override public void end(boolean interrupted) { - currentPattern = LEDConstants.LEDPatterns.BLACK; + currentPattern = BlinkinLEDConstants.Patterns.BLACK; } } diff --git a/src/main/java/frc/robot/subsystems/led/LEDConstants.java b/src/main/java/frc/robot/subsystems/blinkinled/BlinkinLEDConstants.java similarity index 91% rename from src/main/java/frc/robot/subsystems/led/LEDConstants.java rename to src/main/java/frc/robot/subsystems/blinkinled/BlinkinLEDConstants.java index 0680007d..18fdd6af 100644 --- a/src/main/java/frc/robot/subsystems/led/LEDConstants.java +++ b/src/main/java/frc/robot/subsystems/blinkinled/BlinkinLEDConstants.java @@ -1,11 +1,11 @@ -package frc.robot.subsystems.led; +package frc.robot.subsystems.blinkinled; -public class LEDConstants { +public class BlinkinLEDConstants { /** * @brief Patterns taken from * @link https://www.revrobotics.com/content/docs/REV-11-1105-UM.pdf */ - public static class LEDPatterns { + public static class Patterns { public static final double HOT_PINK = 0.57; public static final double DARK_RED = 0.59; public static final double RED = 0.61; diff --git a/src/main/java/frc/robot/subsystems/led/LEDSubsystem.java b/src/main/java/frc/robot/subsystems/blinkinled/BlinkinLEDSubsystem.java similarity index 81% rename from src/main/java/frc/robot/subsystems/led/LEDSubsystem.java rename to src/main/java/frc/robot/subsystems/blinkinled/BlinkinLEDSubsystem.java index 30f75b04..94a0db97 100644 --- a/src/main/java/frc/robot/subsystems/led/LEDSubsystem.java +++ b/src/main/java/frc/robot/subsystems/blinkinled/BlinkinLEDSubsystem.java @@ -1,10 +1,10 @@ -package frc.robot.subsystems.led; +package frc.robot.subsystems.blinkinled; import edu.wpi.first.wpilibj.motorcontrol.Spark; import edu.wpi.first.wpilibj2.command.SubsystemBase; -import frc.robot.subsystems.led.LEDConstants.LEDPatterns; +import frc.robot.subsystems.blinkinled.BlinkinLEDConstants.Patterns; -public class LEDSubsystem extends SubsystemBase { +public class BlinkinLEDSubsystem extends SubsystemBase { private class LEDStrip { public Spark pwm; public double pattern; @@ -16,12 +16,14 @@ public LEDStrip(Spark pwmController, double initialPattern) { } private LEDStrip[] strips; + public final int stripCount; - public LEDSubsystem(int... pwmPorts) { + public BlinkinLEDSubsystem(int... pwmPorts) { // Create all the strip objects + stripCount = pwmPorts.length; strips = new LEDStrip[pwmPorts.length]; for (int i = pwmPorts.length; i >= 0; i--) { - strips[i] = new LEDStrip(new Spark(pwmPorts[i]), LEDPatterns.BLACK); + strips[i] = new LEDStrip(new Spark(pwmPorts[i]), Patterns.BLACK); } } diff --git a/src/main/java/frc/robot/subsystems/superstructure/wrist/WristConstants.java b/src/main/java/frc/robot/subsystems/superstructure/wrist/WristConstants.java index df369073..5c9ba589 100644 --- a/src/main/java/frc/robot/subsystems/superstructure/wrist/WristConstants.java +++ b/src/main/java/frc/robot/subsystems/superstructure/wrist/WristConstants.java @@ -11,7 +11,7 @@ public class WristConstants { public static final double CORAL_SCORING_POSITION_L1_L2_L3 = Units.degreesToRotations(35); public static final double CORAL_SCORING_POSITION_L4 = Units.degreesToRotations(0); public static final double CORAL_PICKUP_POSITION = Units.degreesToRotations(55); - + public static final double ABSOLUTE_ENCODER_OFFSET = 0.0; public static final double RELATIVE_CONVERSION_FACTOR = 0.0; From e9c44d43395c795b010a5d656802c4492dad63f0 Mon Sep 17 00:00:00 2001 From: RobotLeopard86 <63123751+RobotLeopard86@users.noreply.github.com> Date: Sat, 1 Mar 2025 11:47:57 -0800 Subject: [PATCH 10/21] Fix Wrist build error resulting from main merge --- .../robot/subsystems/superstructure/wrist/WristConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/frc/robot/subsystems/superstructure/wrist/WristConstants.java b/src/main/java/frc/robot/subsystems/superstructure/wrist/WristConstants.java index ed9ea306..1053773a 100644 --- a/src/main/java/frc/robot/subsystems/superstructure/wrist/WristConstants.java +++ b/src/main/java/frc/robot/subsystems/superstructure/wrist/WristConstants.java @@ -1,5 +1,6 @@ package frc.robot.subsystems.superstructure.wrist; +import edu.wpi.first.math.util.Units; import frc.robot.Constants; import frc.robot.utility.records.PIDConstants; @@ -17,7 +18,6 @@ public class WristConstants { public static final int MOTOR_ID = 0; public static final int CANCODER_ID = 0; - public static final double ABSOLUTE_ENCODER_OFFSET = 0.0; public static final double GEAR_REDUCTION = 1.0; public static final int CURRENT_LIMIT = 30; From d3c6e7b2a1e2c767c2d4a73c31e7a252fe43bf76 Mon Sep 17 00:00:00 2001 From: RobotLeopard86 <63123751+RobotLeopard86@users.noreply.github.com> Date: Sat, 1 Mar 2025 13:33:32 -0800 Subject: [PATCH 11/21] Add superstructure LED patterns --- src/main/java/frc/robot/RobotContainer.java | 28 +++++++++++++++---- .../commands/SetAddressableLEDPattern.java | 16 ++++++----- .../AddressableLEDConstants.java | 26 ++++++++++++++--- 3 files changed, 53 insertions(+), 17 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index f1fbc12d..b6b23f38 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -1,5 +1,7 @@ package frc.robot; +import static edu.wpi.first.units.Units.Percent; +import static edu.wpi.first.units.Units.Second; import static frc.robot.subsystems.drive.DriveConstants.DRIVE_CONFIG; import com.pathplanner.lib.auto.AutoBuilder; @@ -10,13 +12,17 @@ import edu.wpi.first.math.geometry.Transform2d; import edu.wpi.first.math.geometry.Translation2d; import edu.wpi.first.math.util.Units; +import edu.wpi.first.units.measure.Frequency; import edu.wpi.first.wpilibj.Alert; import edu.wpi.first.wpilibj.Alert.AlertType; import edu.wpi.first.wpilibj.DriverStation; +import edu.wpi.first.wpilibj.LEDPattern; import edu.wpi.first.wpilibj.GenericHID.RumbleType; +import edu.wpi.first.wpilibj.LEDPattern.GradientType; import edu.wpi.first.wpilibj.RobotBase; import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; +import edu.wpi.first.wpilibj.util.Color; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.CommandScheduler; import edu.wpi.first.wpilibj2.command.Commands; @@ -26,10 +32,12 @@ import frc.robot.Constants.Mode; import frc.robot.commands.AdaptiveAutoAlignCommands; import frc.robot.commands.DriveCommands; +import frc.robot.commands.SetAddressableLEDPattern; import frc.robot.commands.controllers.JoystickInputController; import frc.robot.commands.controllers.SpeedLevelController; import frc.robot.commands.intake.SetIntakeSpeed; import frc.robot.commands.wrist.SetWrist; +import frc.robot.subsystems.addressableled.AddressableLEDSubsystem; import frc.robot.subsystems.dashboard.DriverDashboard; import frc.robot.subsystems.drive.Drive; import frc.robot.subsystems.drive.DriveConstants; @@ -86,6 +94,7 @@ public class RobotContainer { private final Wrist wrist; private final AlgaeIntake algaeIntake; private final CoralIntake coralIntake; + private final AddressableLEDSubsystem led; private final Hang hang; @@ -145,6 +154,7 @@ public RobotContainer() { elevator = new Elevator(new ElevatorIOHardwareFollow(ElevatorConstants.ELEVATOR_CONFIG)); hang = new Hang(new HangIOHardwareRelative(HangConstants.HANG_CONFIG)); wrist = new Wrist(new WristIO() {}); + led = new AddressableLEDSubsystem(); // algaeIntake = // new AlgaeIntake( @@ -181,6 +191,7 @@ public RobotContainer() { algaeIntake = new AlgaeIntake(new IntakeIO() {}); coralIntake = new CoralIntake(new IntakeIO() {}); + led = new AddressableLEDSubsystem(); break; @@ -504,19 +515,24 @@ private void configureDriverControllerBindings(boolean includeAutoAlign) { private void configureOperatorControllerBindings() { operatorController.back().onTrue(drive.runOnce(drive::stop).withName("CANCEL and stop")); - configureOperatorControllerBindingLevel(operatorController.y(), Superstructure.State.L4); - configureOperatorControllerBindingLevel(operatorController.x(), Superstructure.State.L3); - configureOperatorControllerBindingLevel(operatorController.b(), Superstructure.State.L2); - configureOperatorControllerBindingLevel(operatorController.a(), Superstructure.State.L1); + configureOperatorControllerBindingLevel(operatorController.y(), Superstructure.State.L4, Color.kAqua); + configureOperatorControllerBindingLevel(operatorController.x(), Superstructure.State.L3, Color.kGold); + configureOperatorControllerBindingLevel(operatorController.b(), Superstructure.State.L2, Color.kLime); + configureOperatorControllerBindingLevel(operatorController.a(), Superstructure.State.L1, Color.kPurple); operatorController.leftBumper().whileTrue(hang.set(+0.5).withName("Hang Arm Up")); operatorController.rightBumper().whileTrue(hang.set(-0.5).withName("Hang Arm Down")); } private void configureOperatorControllerBindingLevel( - Trigger trigger, Superstructure.State state) { + Trigger trigger, Superstructure.State state, Color color) { trigger.onTrue(superstructure.setNextPrepare(state)); - trigger.and(operatorController.rightTrigger()).onTrue(superstructure.runPrepare(state)); + if(led != null) { + LEDPattern pattern = LEDPattern.gradient(GradientType.kContinuous, Color.kBlack, color).scrollAtRelativeSpeed(Percent.per(Second).of(35)); + trigger.and(operatorController.rightTrigger()).onTrue(superstructure.runPrepare(state).alongWith(new SetAddressableLEDPattern(led, pattern, 4, 5))); + } else { + trigger.and(operatorController.rightTrigger()).onTrue(superstructure.runPrepare(state)); + } } private Command rumbleController(CommandXboxController controller, double rumbleIntensity) { diff --git a/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java b/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java index cf3ece76..d05ff094 100644 --- a/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java +++ b/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java @@ -8,9 +8,9 @@ public class SetAddressableLEDPattern extends Command { private final AddressableLEDSubsystem ledSystem; /** - * @apiNote If this is -1, that means that this command is targeting the whole strip + * @apiNote If this is empty, that means that this command is targeting the whole strip */ - private final int section; + private final int[] sections; private final LEDPattern pattern; @@ -21,8 +21,8 @@ public class SetAddressableLEDPattern extends Command { * AddressableLEDConstants.SECTIONS) */ public SetAddressableLEDPattern( - AddressableLEDSubsystem ledSystem, LEDPattern pattern, int section) { - this.section = section; + AddressableLEDSubsystem ledSystem, LEDPattern pattern, int... sections) { + this.sections = sections; this.pattern = pattern; this.ledSystem = ledSystem; addRequirements(ledSystem); @@ -33,7 +33,7 @@ public SetAddressableLEDPattern( * @param pattern Pattern to apply when command run */ public SetAddressableLEDPattern(AddressableLEDSubsystem ledSystem, LEDPattern pattern) { - section = -1; + sections = new int[0]; this.pattern = pattern; this.ledSystem = ledSystem; addRequirements(ledSystem); @@ -41,10 +41,12 @@ public SetAddressableLEDPattern(AddressableLEDSubsystem ledSystem, LEDPattern pa @Override public void execute() { - if (section < 0) { + if (sections.length <= 0) { ledSystem.applyPattern(pattern); } else { - ledSystem.applySectionedPattern(pattern, section); + for(int i = 0; i < sections.length; i++) { + ledSystem.applySectionedPattern(pattern, sections[i]); + } } } diff --git a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java index 3d4f75f4..a727114e 100644 --- a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java +++ b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java @@ -11,14 +11,32 @@ public class AddressableLEDConstants { */ public record Range(int low, int high) {} - // TODO: Implement real values - public static final int LED_COUNT = 64; - public static final Distance LED_DENSITY = Meters.of(1.0 / LED_COUNT); + // TODO: Replace these with real values + public static final int LED_COUNT = 60; + public static final Distance LED_DENSITY = Meters.of(1.0 / 60.0); public static final int LED_STRIP_PORT = 0; /** * @apiNote The lower bound of the range represents the lowest index LED for this section, and the * upper bound represents the highest index LED + * + *

Sections

+ * Assume front of robot refers to battery side + *
    + *
  1. Front
  2. + *
  3. Left
  4. + *
  5. Back
  6. + *
  7. Right
  8. + *
  9. Superstructure Left
  10. + *
  11. Superstructure Right
  12. + *
*/ - public static final Range SECTIONS[] = {new Range(0, LED_COUNT)}; + public static final Range SECTIONS[] = { + new Range(0, 9), + new Range(10, 19), + new Range(20, 29), + new Range(30, 39), + new Range(40, 49), + new Range(50, 59) + }; } From 9efff02692a50fb81e019aabe248b051297bfba1 Mon Sep 17 00:00:00 2001 From: RobotLeopard86 <63123751+RobotLeopard86@users.noreply.github.com> Date: Sat, 1 Mar 2025 13:37:47 -0800 Subject: [PATCH 12/21] Fix errors --- src/main/java/frc/robot/RobotContainer.java | 9 ++++++--- .../addressableled/AddressableLEDSubsystem.java | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index b6b23f38..068ec651 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -12,7 +12,6 @@ import edu.wpi.first.math.geometry.Transform2d; import edu.wpi.first.math.geometry.Translation2d; import edu.wpi.first.math.util.Units; -import edu.wpi.first.units.measure.Frequency; import edu.wpi.first.wpilibj.Alert; import edu.wpi.first.wpilibj.Alert.AlertType; import edu.wpi.first.wpilibj.DriverStation; @@ -154,7 +153,7 @@ public RobotContainer() { elevator = new Elevator(new ElevatorIOHardwareFollow(ElevatorConstants.ELEVATOR_CONFIG)); hang = new Hang(new HangIOHardwareRelative(HangConstants.HANG_CONFIG)); wrist = new Wrist(new WristIO() {}); - led = new AddressableLEDSubsystem(); + led = new AddressableLEDSubsystem(false); // algaeIntake = // new AlgaeIntake( @@ -191,7 +190,7 @@ public RobotContainer() { algaeIntake = new AlgaeIntake(new IntakeIO() {}); coralIntake = new CoralIntake(new IntakeIO() {}); - led = new AddressableLEDSubsystem(); + led = new AddressableLEDSubsystem(true); break; @@ -212,6 +211,7 @@ public RobotContainer() { algaeIntake = new AlgaeIntake(new IntakeIO() {}); coralIntake = new CoralIntake(new IntakeIO() {}); + led = new AddressableLEDSubsystem(true); break; @@ -232,6 +232,7 @@ public RobotContainer() { algaeIntake = new AlgaeIntake(new IntakeIO() {}); coralIntake = new CoralIntake(new IntakeIO() {}); + led = new AddressableLEDSubsystem(true); break; @@ -256,6 +257,7 @@ public RobotContainer() { wrist = new Wrist(new WristIOSim()); algaeIntake = new AlgaeIntake(new IntakeIOSim()); coralIntake = new CoralIntake(new IntakeIOSim()); + led = new AddressableLEDSubsystem(true); break; default: @@ -275,6 +277,7 @@ public RobotContainer() { algaeIntake = new AlgaeIntake(new IntakeIO() {}); coralIntake = new CoralIntake(new IntakeIO() {}); + led = new AddressableLEDSubsystem(true); break; } diff --git a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java index 7cbdfa91..81ee32b9 100644 --- a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java +++ b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java @@ -11,8 +11,19 @@ public class AddressableLEDSubsystem extends SubsystemBase { private final AddressableLEDBuffer ledBuffer; private AddressableLEDBufferView ledViews[]; private LEDPattern[] currentPatterns; + private final boolean fake; + + /** + * @param isFake Set this to true to disable useful functions for robots that don't have LEDs attached + */ + public AddressableLEDSubsystem(boolean isFake) { + fake = isFake; + if(fake) { + led = null; + ledBuffer = null; + return; + } - public AddressableLEDSubsystem() { // Create strip and buffer led = new AddressableLED(AddressableLEDConstants.LED_STRIP_PORT); ledBuffer = new AddressableLEDBuffer(AddressableLEDConstants.LED_COUNT); @@ -35,6 +46,7 @@ public AddressableLEDSubsystem() { // Periodically update the LED strip @Override public void periodic() { + if(fake) return; for (int i = 0; i < ledViews.length; i++) { currentPatterns[i].applyTo(ledViews[i]); } @@ -43,6 +55,7 @@ public void periodic() { // Apply a color pattern to a section of the LED strip public void applySectionedPattern(LEDPattern pattern, int section) { + if(fake) return; if (section < 0 || section >= ledViews.length) return; pattern.applyTo(ledViews[section]); currentPatterns[section] = pattern; @@ -50,6 +63,7 @@ public void applySectionedPattern(LEDPattern pattern, int section) { // Apply a color pattern to a section of the LED strip public void applyPattern(LEDPattern pattern) { + if(fake) return; pattern.applyTo(ledBuffer); for (int i = 0; i < currentPatterns.length; i++) { currentPatterns[i] = pattern; From 79bca4618ed43700c994bfdaa850ed75fbcf7f04 Mon Sep 17 00:00:00 2001 From: RobotLeopard86 <63123751+RobotLeopard86@users.noreply.github.com> Date: Sat, 1 Mar 2025 13:40:31 -0800 Subject: [PATCH 13/21] Remove redundant null check --- src/main/java/frc/robot/RobotContainer.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index f2073e46..1ae955a9 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -530,12 +530,8 @@ private void configureOperatorControllerBindings() { private void configureOperatorControllerBindingLevel( Trigger trigger, Superstructure.State state, Color color) { trigger.onTrue(superstructure.setNextPrepare(state)); - if(led != null) { LEDPattern pattern = LEDPattern.gradient(GradientType.kContinuous, Color.kBlack, color).scrollAtRelativeSpeed(Percent.per(Second).of(35)); trigger.and(operatorController.rightTrigger()).onTrue(superstructure.runPrepare(state).alongWith(new SetAddressableLEDPattern(led, pattern, 4, 5))); - } else { - trigger.and(operatorController.rightTrigger()).onTrue(superstructure.runPrepare(state)); - } } private Command rumbleController(CommandXboxController controller, double rumbleIntensity) { From 0b9126f037911390d5761c058fdeb6a38e0743ba Mon Sep 17 00:00:00 2001 From: RobotLeopard86 <63123751+RobotLeopard86@users.noreply.github.com> Date: Sat, 1 Mar 2025 13:50:38 -0800 Subject: [PATCH 14/21] Add appropriate Javadoc for subsystem --- .../addressableled/AddressableLEDSubsystem.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java index 81ee32b9..25bb5bfd 100644 --- a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java +++ b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java @@ -43,7 +43,6 @@ public AddressableLEDSubsystem(boolean isFake) { } } - // Periodically update the LED strip @Override public void periodic() { if(fake) return; @@ -53,7 +52,12 @@ public void periodic() { led.setData(ledBuffer); } - // Apply a color pattern to a section of the LED strip + /** + * Apply a pattern to a section of the LED strip + * + * @param pattern The pattern to apply + * @param section The section of the LED strip to apply. This is an index into AddressableLEDConstants.SECTIONS. + */ public void applySectionedPattern(LEDPattern pattern, int section) { if(fake) return; if (section < 0 || section >= ledViews.length) return; @@ -61,7 +65,12 @@ public void applySectionedPattern(LEDPattern pattern, int section) { currentPatterns[section] = pattern; } - // Apply a color pattern to a section of the LED strip + /** + * Apply a pattern to the entirety of the LED strip + * WARNING: This will overwrite pattern settings for all sections + * + * @param pattern The pattern to apply + */ public void applyPattern(LEDPattern pattern) { if(fake) return; pattern.applyTo(ledBuffer); From ebcae4c9e2a3b55c2a124be54337f7d2aa04119e Mon Sep 17 00:00:00 2001 From: bforcum <113265535+bforcum@users.noreply.github.com> Date: Sat, 1 Mar 2025 14:41:43 -0800 Subject: [PATCH 15/21] Run autoformatting --- src/main/java/frc/robot/RobotContainer.java | 25 +++++++++++++----- .../commands/SetAddressableLEDPattern.java | 2 +- .../AddressableLEDConstants.java | 21 +++++++-------- .../AddressableLEDSubsystem.java | 26 ++++++++++--------- 4 files changed, 43 insertions(+), 31 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 1ae955a9..8f60da92 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -15,8 +15,8 @@ import edu.wpi.first.wpilibj.Alert; import edu.wpi.first.wpilibj.Alert.AlertType; import edu.wpi.first.wpilibj.DriverStation; -import edu.wpi.first.wpilibj.LEDPattern; import edu.wpi.first.wpilibj.GenericHID.RumbleType; +import edu.wpi.first.wpilibj.LEDPattern; import edu.wpi.first.wpilibj.LEDPattern.GradientType; import edu.wpi.first.wpilibj.RobotBase; import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; @@ -518,10 +518,14 @@ private void configureDriverControllerBindings(boolean includeAutoAlign) { private void configureOperatorControllerBindings() { operatorController.back().onTrue(drive.runOnce(drive::stop).withName("CANCEL and stop")); - configureOperatorControllerBindingLevel(operatorController.y(), Superstructure.State.L4, Color.kAqua); - configureOperatorControllerBindingLevel(operatorController.x(), Superstructure.State.L3, Color.kGold); - configureOperatorControllerBindingLevel(operatorController.b(), Superstructure.State.L2, Color.kLime); - configureOperatorControllerBindingLevel(operatorController.a(), Superstructure.State.L1, Color.kPurple); + configureOperatorControllerBindingLevel( + operatorController.y(), Superstructure.State.L4, Color.kAqua); + configureOperatorControllerBindingLevel( + operatorController.x(), Superstructure.State.L3, Color.kGold); + configureOperatorControllerBindingLevel( + operatorController.b(), Superstructure.State.L2, Color.kLime); + configureOperatorControllerBindingLevel( + operatorController.a(), Superstructure.State.L1, Color.kPurple); operatorController.leftBumper().whileTrue(hang.set(+0.5).withName("Hang Arm Up")); operatorController.rightBumper().whileTrue(hang.set(-0.5).withName("Hang Arm Down")); @@ -530,8 +534,15 @@ private void configureOperatorControllerBindings() { private void configureOperatorControllerBindingLevel( Trigger trigger, Superstructure.State state, Color color) { trigger.onTrue(superstructure.setNextPrepare(state)); - LEDPattern pattern = LEDPattern.gradient(GradientType.kContinuous, Color.kBlack, color).scrollAtRelativeSpeed(Percent.per(Second).of(35)); - trigger.and(operatorController.rightTrigger()).onTrue(superstructure.runPrepare(state).alongWith(new SetAddressableLEDPattern(led, pattern, 4, 5))); + LEDPattern pattern = + LEDPattern.gradient(GradientType.kContinuous, Color.kBlack, color) + .scrollAtRelativeSpeed(Percent.per(Second).of(35)); + trigger + .and(operatorController.rightTrigger()) + .onTrue( + superstructure + .runPrepare(state) + .alongWith(new SetAddressableLEDPattern(led, pattern, 4, 5))); } private Command rumbleController(CommandXboxController controller, double rumbleIntensity) { diff --git a/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java b/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java index d05ff094..7a966101 100644 --- a/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java +++ b/src/main/java/frc/robot/commands/SetAddressableLEDPattern.java @@ -44,7 +44,7 @@ public void execute() { if (sections.length <= 0) { ledSystem.applyPattern(pattern); } else { - for(int i = 0; i < sections.length; i++) { + for (int i = 0; i < sections.length; i++) { ledSystem.applySectionedPattern(pattern, sections[i]); } } diff --git a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java index a727114e..63b92c9e 100644 --- a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java +++ b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java @@ -19,17 +19,16 @@ public record Range(int low, int high) {} /** * @apiNote The lower bound of the range represents the lowest index LED for this section, and the * upper bound represents the highest index LED - * - *

Sections

- * Assume front of robot refers to battery side - *
    - *
  1. Front
  2. - *
  3. Left
  4. - *
  5. Back
  6. - *
  7. Right
  8. - *
  9. Superstructure Left
  10. - *
  11. Superstructure Right
  12. - *
+ *

Sections

+ * Assume front of robot refers to battery side + *
    + *
  1. Front + *
  2. Left + *
  3. Back + *
  4. Right + *
  5. Superstructure Left + *
  6. Superstructure Right + *
*/ public static final Range SECTIONS[] = { new Range(0, 9), diff --git a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java index 25bb5bfd..e7478a62 100644 --- a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java +++ b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java @@ -14,11 +14,12 @@ public class AddressableLEDSubsystem extends SubsystemBase { private final boolean fake; /** - * @param isFake Set this to true to disable useful functions for robots that don't have LEDs attached + * @param isFake Set this to true to disable useful functions for robots that don't have LEDs + * attached */ public AddressableLEDSubsystem(boolean isFake) { fake = isFake; - if(fake) { + if (fake) { led = null; ledBuffer = null; return; @@ -45,7 +46,7 @@ public AddressableLEDSubsystem(boolean isFake) { @Override public void periodic() { - if(fake) return; + if (fake) return; for (int i = 0; i < ledViews.length; i++) { currentPatterns[i].applyTo(ledViews[i]); } @@ -54,25 +55,26 @@ public void periodic() { /** * Apply a pattern to a section of the LED strip - * + * * @param pattern The pattern to apply - * @param section The section of the LED strip to apply. This is an index into AddressableLEDConstants.SECTIONS. - */ + * @param section The section of the LED strip to apply. This is an index into + * AddressableLEDConstants.SECTIONS. + */ public void applySectionedPattern(LEDPattern pattern, int section) { - if(fake) return; + if (fake) return; if (section < 0 || section >= ledViews.length) return; pattern.applyTo(ledViews[section]); currentPatterns[section] = pattern; } /** - * Apply a pattern to the entirety of the LED strip - * WARNING: This will overwrite pattern settings for all sections - * + * Apply a pattern to the entirety of the LED strip WARNING: This will overwrite pattern settings + * for all sections + * * @param pattern The pattern to apply - */ + */ public void applyPattern(LEDPattern pattern) { - if(fake) return; + if (fake) return; pattern.applyTo(ledBuffer); for (int i = 0; i < currentPatterns.length; i++) { currentPatterns[i] = pattern; From cead75ccc0ed301220239129d89856bcfc2610cb Mon Sep 17 00:00:00 2001 From: RobotLeopard86 <63123751+RobotLeopard86@users.noreply.github.com> Date: Sat, 1 Mar 2025 15:32:46 -0800 Subject: [PATCH 16/21] Refactor LED pattern manipulation to be within subsystems instead of RobotContainer --- src/main/java/frc/robot/Constants.java | 5 +++ src/main/java/frc/robot/RobotContainer.java | 18 ++------ .../AddressableLEDSubsystem.java | 3 +- .../superstructure/Superstructure.java | 44 ++++++++++++++++++- .../SuperstructureConstants.java | 11 ++++- 5 files changed, 62 insertions(+), 19 deletions(-) diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index 114ab6e1..5ea8400c 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -92,6 +92,11 @@ private static RobotType determineRobotType() { return null; } + /** + * Set this to true to completely disable usage of the AddressableLED subsystem, no matter what + */ + public static boolean MASTER_LED_DISABLE = false; + private static final Alert wrongRobotTypeAlertReal = new Alert( String.format( diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 8f60da92..aee0945b 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -1,7 +1,5 @@ package frc.robot; -import static edu.wpi.first.units.Units.Percent; -import static edu.wpi.first.units.Units.Second; import static frc.robot.subsystems.drive.DriveConstants.DRIVE_CONFIG; import com.pathplanner.lib.auto.AutoBuilder; @@ -16,8 +14,6 @@ import edu.wpi.first.wpilibj.Alert.AlertType; import edu.wpi.first.wpilibj.DriverStation; import edu.wpi.first.wpilibj.GenericHID.RumbleType; -import edu.wpi.first.wpilibj.LEDPattern; -import edu.wpi.first.wpilibj.LEDPattern.GradientType; import edu.wpi.first.wpilibj.RobotBase; import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; @@ -31,7 +27,6 @@ import frc.robot.Constants.Mode; import frc.robot.commands.AdaptiveAutoAlignCommands; import frc.robot.commands.DriveCommands; -import frc.robot.commands.SetAddressableLEDPattern; import frc.robot.commands.controllers.JoystickInputController; import frc.robot.commands.controllers.SpeedLevelController; import frc.robot.commands.intake.SetIntakeSpeed; @@ -283,7 +278,7 @@ public RobotContainer() { } // Superstructure - superstructure = new Superstructure(elevator, wrist); + superstructure = new Superstructure(elevator, wrist, led); // Vision setup // vision.setLastRobotPoseSupplier(drive::getRobotPose); @@ -534,15 +529,8 @@ private void configureOperatorControllerBindings() { private void configureOperatorControllerBindingLevel( Trigger trigger, Superstructure.State state, Color color) { trigger.onTrue(superstructure.setNextPrepare(state)); - LEDPattern pattern = - LEDPattern.gradient(GradientType.kContinuous, Color.kBlack, color) - .scrollAtRelativeSpeed(Percent.per(Second).of(35)); - trigger - .and(operatorController.rightTrigger()) - .onTrue( - superstructure - .runPrepare(state) - .alongWith(new SetAddressableLEDPattern(led, pattern, 4, 5))); + + trigger.and(operatorController.rightTrigger()).onTrue(superstructure.runPrepare(state)); } private Command rumbleController(CommandXboxController controller, double rumbleIntensity) { diff --git a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java index e7478a62..193d088a 100644 --- a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java +++ b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDSubsystem.java @@ -5,6 +5,7 @@ import edu.wpi.first.wpilibj.AddressableLEDBufferView; import edu.wpi.first.wpilibj.LEDPattern; import edu.wpi.first.wpilibj2.command.SubsystemBase; +import frc.robot.Constants; public class AddressableLEDSubsystem extends SubsystemBase { private final AddressableLED led; @@ -18,7 +19,7 @@ public class AddressableLEDSubsystem extends SubsystemBase { * attached */ public AddressableLEDSubsystem(boolean isFake) { - fake = isFake; + fake = isFake || Constants.MASTER_LED_DISABLE; if (fake) { led = null; ledBuffer = null; diff --git a/src/main/java/frc/robot/subsystems/superstructure/Superstructure.java b/src/main/java/frc/robot/subsystems/superstructure/Superstructure.java index 582b924f..f89c4423 100644 --- a/src/main/java/frc/robot/subsystems/superstructure/Superstructure.java +++ b/src/main/java/frc/robot/subsystems/superstructure/Superstructure.java @@ -1,10 +1,17 @@ package frc.robot.subsystems.superstructure; +import static edu.wpi.first.units.Units.Percent; +import static edu.wpi.first.units.Units.Second; + import edu.wpi.first.math.util.Units; +import edu.wpi.first.wpilibj.LEDPattern; +import edu.wpi.first.wpilibj.LEDPattern.GradientType; import edu.wpi.first.wpilibj.util.Color; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.Commands; import edu.wpi.first.wpilibj2.command.SubsystemBase; +import frc.robot.commands.SetAddressableLEDPattern; +import frc.robot.subsystems.addressableled.AddressableLEDSubsystem; import frc.robot.subsystems.superstructure.elevator.Elevator; import frc.robot.subsystems.superstructure.elevator.ElevatorConstants; import frc.robot.subsystems.superstructure.wrist.Wrist; @@ -13,6 +20,7 @@ public class Superstructure extends SubsystemBase { private final Elevator elevator; private final Wrist wrist; + private final AddressableLEDSubsystem led; public static enum State { STOW, @@ -32,9 +40,10 @@ public static enum State { private final SuperstructureVisualizer goalVisualizer = new SuperstructureVisualizer("Goal", Color.kLime); - public Superstructure(Elevator elevator, Wrist wrist) { + public Superstructure(Elevator elevator, Wrist wrist, AddressableLEDSubsystem led) { this.elevator = elevator; this.wrist = wrist; + this.led = led; } public Command prepare() { @@ -63,6 +72,11 @@ public Command run(State goal) { public Command prepareL1() { return Commands.parallel( + new SetAddressableLEDPattern( + led, + LEDPattern.gradient( + GradientType.kContinuous, Color.kBlack, SuperstructureConstants.L1_COLOR) + .scrollAtRelativeSpeed(Percent.per(Second).of(35))), elevator.runOnce( () -> elevator.setGoalHeightMeters(ElevatorConstants.carriageMaxHeight / 4.0)), wrist.runOnce(() -> wrist.setGoal(Units.degreesToRotations(55)))); @@ -70,6 +84,11 @@ public Command prepareL1() { public Command prepareL2() { return Commands.parallel( + new SetAddressableLEDPattern( + led, + LEDPattern.gradient( + GradientType.kContinuous, Color.kBlack, SuperstructureConstants.L2_COLOR) + .scrollAtRelativeSpeed(Percent.per(Second).of(35))), elevator.runOnce( () -> elevator.setGoalHeightMeters(ElevatorConstants.carriageMaxHeight / 2.0)), wrist.runOnce(() -> wrist.setGoal(Units.degreesToRotations(35)))); @@ -77,6 +96,11 @@ public Command prepareL2() { public Command prepareL3() { return Commands.parallel( + new SetAddressableLEDPattern( + led, + LEDPattern.gradient( + GradientType.kContinuous, Color.kBlack, SuperstructureConstants.L3_COLOR) + .scrollAtRelativeSpeed(Percent.per(Second).of(35))), elevator.runOnce( () -> elevator.setGoalHeightMeters(ElevatorConstants.carriageMaxHeight * (3.0 / 4.0))), wrist.runOnce(() -> wrist.setGoal(Units.degreesToRotations(35)))); @@ -84,19 +108,35 @@ public Command prepareL3() { public Command prepareL4() { return Commands.parallel( + new SetAddressableLEDPattern( + led, + LEDPattern.gradient( + GradientType.kContinuous, Color.kBlack, SuperstructureConstants.L4_COLOR) + .scrollAtRelativeSpeed(Percent.per(Second).of(35))), elevator.runOnce(() -> elevator.setGoalHeightMeters(ElevatorConstants.carriageMaxHeight)), wrist.runOnce(() -> wrist.setGoal(Units.degreesToRotations(90)))); } public Command prepareIntake() { return Commands.parallel( + new SetAddressableLEDPattern( + led, + LEDPattern.gradient( + GradientType.kContinuous, Color.kBlack, SuperstructureConstants.INTAKE_COLOR) + .scrollAtRelativeSpeed(Percent.per(Second).of(35))), elevator.runOnce( () -> elevator.setGoalHeightMeters(ElevatorConstants.carriageMaxHeight / 4.0)), wrist.runOnce(() -> wrist.setGoal(Units.degreesToRotations(55)))); } public Command stow() { - return elevator.runOnce(() -> elevator.setGoalHeightMeters(0)); + return Commands.parallel( + new SetAddressableLEDPattern( + led, + LEDPattern.gradient( + GradientType.kContinuous, Color.kBlack, SuperstructureConstants.L1_COLOR) + .scrollAtRelativeSpeed(Percent.per(Second).of(35))), + elevator.runOnce(() -> elevator.setGoalHeightMeters(0))); } @Override diff --git a/src/main/java/frc/robot/subsystems/superstructure/SuperstructureConstants.java b/src/main/java/frc/robot/subsystems/superstructure/SuperstructureConstants.java index 4f94bf20..4f5b70e0 100644 --- a/src/main/java/frc/robot/subsystems/superstructure/SuperstructureConstants.java +++ b/src/main/java/frc/robot/subsystems/superstructure/SuperstructureConstants.java @@ -1,3 +1,12 @@ package frc.robot.subsystems.superstructure; -public class SuperstructureConstants {} +import edu.wpi.first.wpilibj.util.Color; + +public class SuperstructureConstants { + public static final Color STOW_LED_COLOR = Color.kSalmon; + public static final Color L1_COLOR = Color.kPurple; + public static final Color L2_COLOR = Color.kAqua; + public static final Color L3_COLOR = Color.kLime; + public static final Color L4_COLOR = Color.kYellow; + public static final Color INTAKE_COLOR = Color.kOrange; +} From b5dda59d7cd830921be198dbd5c52fc470422cdf Mon Sep 17 00:00:00 2001 From: michael-lesirge <100492377+michael-lesirge@users.noreply.github.com> Date: Mon, 3 Mar 2025 17:34:00 -0800 Subject: [PATCH 17/21] fix build --- src/main/java/frc/robot/RobotContainer.java | 4 -- .../superstructure/Superstructure.java | 40 ------------------- 2 files changed, 44 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 29dd8ee8..c45184b0 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -17,7 +17,6 @@ import edu.wpi.first.wpilibj.RobotBase; import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; -import edu.wpi.first.wpilibj.util.Color; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.CommandScheduler; import edu.wpi.first.wpilibj2.command.Commands; @@ -29,9 +28,6 @@ import frc.robot.commands.DriveCommands; import frc.robot.commands.controllers.JoystickInputController; import frc.robot.commands.controllers.SpeedLevelController; -import frc.robot.commands.intake.SetIntakeSpeed; -import frc.robot.commands.wrist.SetWrist; -import frc.robot.subsystems.addressableled.AddressableLEDSubsystem; import frc.robot.subsystems.dashboard.DriverDashboard; import frc.robot.subsystems.drive.Drive; import frc.robot.subsystems.drive.DriveConstants; diff --git a/src/main/java/frc/robot/subsystems/superstructure/Superstructure.java b/src/main/java/frc/robot/subsystems/superstructure/Superstructure.java index 848c2801..6e8f4252 100644 --- a/src/main/java/frc/robot/subsystems/superstructure/Superstructure.java +++ b/src/main/java/frc/robot/subsystems/superstructure/Superstructure.java @@ -1,17 +1,10 @@ package frc.robot.subsystems.superstructure; -import static edu.wpi.first.units.Units.Percent; -import static edu.wpi.first.units.Units.Second; - import edu.wpi.first.math.util.Units; -import edu.wpi.first.wpilibj.LEDPattern; -import edu.wpi.first.wpilibj.LEDPattern.GradientType; import edu.wpi.first.wpilibj.util.Color; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.Commands; import edu.wpi.first.wpilibj2.command.SubsystemBase; -import frc.robot.commands.SetAddressableLEDPattern; -import frc.robot.subsystems.addressableled.AddressableLEDSubsystem; import frc.robot.subsystems.superstructure.elevator.Elevator; import frc.robot.subsystems.superstructure.elevator.ElevatorConstants; import frc.robot.subsystems.superstructure.intake.Intake; @@ -145,11 +138,6 @@ public Command prepareL3() { public Command prepareL4() { return Commands.parallel( - new SetAddressableLEDPattern( - led, - LEDPattern.gradient( - GradientType.kContinuous, Color.kBlack, SuperstructureConstants.L4_COLOR) - .scrollAtRelativeSpeed(Percent.per(Second).of(35))), elevator.runOnce(() -> elevator.setGoalHeightMeters(ElevatorConstants.carriageMaxHeight)), algaeWrist.runPrepare(algaeHighStow), coralWrist.runPrepare(Units.degreesToRotations(90))); @@ -183,34 +171,6 @@ public Command prepareAlgaeL4() { coralWrist.runPrepare(Units.degreesToRotations(90))); } - public Command prepareAlgaeL1() { - return Commands.parallel( - elevator.runPrepare(ElevatorConstants.carriageMaxHeight / 4.0), - coralWrist.runPrepare(coralHighStow), - algaeWrist.runPrepare(Units.degreesToRotations(90))); - } - - public Command prepareAlgaeL2() { - return Commands.parallel( - elevator.runPrepare(ElevatorConstants.carriageMaxHeight / 2.0), - coralWrist.runPrepare(coralHighStow), - algaeWrist.runPrepare(Units.degreesToRotations(90))); - } - - public Command prepareAlgaeL3() { - return Commands.parallel( - elevator.runPrepare(ElevatorConstants.carriageMaxHeight * (3.0 / 4.0)), - coralWrist.runPrepare(coralHighStow), - algaeWrist.runPrepare(Units.degreesToRotations(90))); - } - - public Command prepareAlgaeL4() { - return Commands.parallel( - elevator.runOnce(() -> elevator.setGoalHeightMeters(ElevatorConstants.carriageMaxHeight)), - coralWrist.runPrepare(coralHighStow), - algaeWrist.runPrepare(Units.degreesToRotations(90))); - } - public Command prepareIntake() { return Commands.parallel( elevator.runPrepare(ElevatorConstants.carriageMaxHeight / 4.0), From 21a0484ac68a3a3c2c6c0811dfd5ecbbb1aee7c1 Mon Sep 17 00:00:00 2001 From: "Aceius E." Date: Wed, 12 Mar 2025 15:35:23 -0700 Subject: [PATCH 18/21] fix --- .../robot/subsystems/superstructure/Superstructure.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/main/java/frc/robot/subsystems/superstructure/Superstructure.java b/src/main/java/frc/robot/subsystems/superstructure/Superstructure.java index d6e9cf45..3741e5c0 100644 --- a/src/main/java/frc/robot/subsystems/superstructure/Superstructure.java +++ b/src/main/java/frc/robot/subsystems/superstructure/Superstructure.java @@ -153,13 +153,6 @@ public Command stowHigh() { elevator.runPositionPrepare(STOW_HEIGHT), coralWrist.runPositionPrepare(STOW_CORAL_ANGLE_HIGH)); } - - public Command prepareAlgaeL4() { - return Commands.parallel( - elevator.runOnce(() -> elevator.setGoalHeightMeters(ElevatorConstants.carriageMaxHeight)), - algaeWrist.runPrepare(algaeHighStow), - coralWrist.runPrepare(Units.degreesToRotations(90))); - } public Command intake() { return coralIntake.runMotors(-0.6); From f2ed68893b6f93cb1b7d5ca5494fe6c9aa050eb8 Mon Sep 17 00:00:00 2001 From: "Aceius E." Date: Wed, 12 Mar 2025 16:00:02 -0700 Subject: [PATCH 19/21] Integrate LEDs into robot container and superstructure --- src/main/java/frc/robot/RobotContainer.java | 20 +++++++++++++++++-- .../frc/robot/commands/DriveCommands.java | 1 - .../superstructure/Superstructure.java | 12 ++++++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index b40d2b2f..e1b0e66b 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -27,6 +27,7 @@ import frc.robot.commands.DriveCommands; import frc.robot.commands.controllers.JoystickInputController; import frc.robot.commands.controllers.SpeedLevelController; +import frc.robot.subsystems.addressableled.AddressableLEDSubsystem; import frc.robot.subsystems.dashboard.DriverDashboard; import frc.robot.subsystems.drive.Drive; import frc.robot.subsystems.drive.DriveConstants; @@ -76,7 +77,6 @@ * subsystems, commands, and button mappings) should be declared here. */ public class RobotContainer { - // Subsystems private final Drive drive; private final AprilTagVision vision; @@ -89,6 +89,8 @@ public class RobotContainer { private final Hang hang; + private final AddressableLEDSubsystem lights; + // Controller private final CommandXboxController driverController = new CommandXboxController(0); private final CommandXboxController operatorController = new CommandXboxController(1); @@ -123,6 +125,8 @@ public class RobotContainer { /** The container for the robot. Contains subsystems, IO devices, and commands. */ public RobotContainer() { + final boolean lightsAreFake; + switch (Constants.getRobot()) { case COMP_BOT_2025: // Real robot (Competition bot with mechanisms), instantiate hardware IO implementations @@ -145,6 +149,8 @@ public RobotContainer() { hang = new Hang(new HangIOHardware(HangConstants.HANG_CONFIG)); coralWrist = new Wrist(new WristIOHardware(WristConstants.WRIST_CONFIG)); coralIntake = new Intake(new IntakeIOHardware(IntakeConstants.CORAL_INTAKE_CONFIG)); + + lightsAreFake = false; break; case WOOD_BOT_TWO_2025: @@ -161,6 +167,8 @@ public RobotContainer() { hang = new Hang(new HangIO() {}); coralWrist = new Wrist(new WristIO() {}); coralIntake = new Intake(new IntakeIO() {}); + + lightsAreFake = false; break; case T_SHIRT_CANNON_CHASSIS: @@ -177,6 +185,8 @@ public RobotContainer() { elevator = new Elevator(new ElevatorIO() {}); coralWrist = new Wrist(new WristIO() {}); coralIntake = new Intake(new IntakeIO() {}); + + lightsAreFake = true; break; case CRESCENDO_CHASSIS_2024: @@ -196,6 +206,7 @@ public RobotContainer() { coralIntake = new Intake(new IntakeIO() {}); + lightsAreFake = true; break; case SIM_BOT: @@ -218,6 +229,8 @@ public RobotContainer() { elevator = new Elevator(new ElevatorIOSim()); coralWrist = new Wrist(new WristIOSim(WristConstants.WRIST_CONFIG)); coralIntake = new Intake(new IntakeIOSim()); + + lightsAreFake = true; break; default: @@ -235,11 +248,14 @@ public RobotContainer() { coralWrist = new Wrist(new WristIO() {}); coralIntake = new Intake(new IntakeIO() {}); + lightsAreFake = true; break; } + lights = new AddressableLEDSubsystem(lightsAreFake); + // Superstructure - superstructure = new Superstructure(elevator, coralWrist, coralIntake); + superstructure = new Superstructure(elevator, coralWrist, coralIntake, lights); // Vision setup // vision.setLastRobotPoseSupplier(drive::getRobotPose); diff --git a/src/main/java/frc/robot/commands/DriveCommands.java b/src/main/java/frc/robot/commands/DriveCommands.java index aba8b36f..1369b94b 100644 --- a/src/main/java/frc/robot/commands/DriveCommands.java +++ b/src/main/java/frc/robot/commands/DriveCommands.java @@ -119,7 +119,6 @@ public static Command joystickDriveWithSlowdown( DoubleSupplier omegaSupplier, DoubleSupplier elevatorHeightSupplier, BooleanSupplier useFieldRelativeSupplier) { - Runnable drive = () -> { Translation2d translation = translationSupplier.get(); diff --git a/src/main/java/frc/robot/subsystems/superstructure/Superstructure.java b/src/main/java/frc/robot/subsystems/superstructure/Superstructure.java index 3741e5c0..70a54538 100644 --- a/src/main/java/frc/robot/subsystems/superstructure/Superstructure.java +++ b/src/main/java/frc/robot/subsystems/superstructure/Superstructure.java @@ -6,6 +6,8 @@ import edu.wpi.first.wpilibj.util.Color; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.Commands; +import frc.robot.commands.SetAddressableLEDPattern; +import frc.robot.subsystems.addressableled.AddressableLEDSubsystem; import frc.robot.subsystems.superstructure.elevator.Elevator; import frc.robot.subsystems.superstructure.intake.Intake; import frc.robot.subsystems.superstructure.wrist.Wrist; @@ -16,6 +18,7 @@ public class Superstructure extends VirtualSubsystem { private final Elevator elevator; private final Wrist coralWrist; private final Intake coralIntake; + private final AddressableLEDSubsystem lights; public static enum State { STOW, @@ -64,10 +67,12 @@ private State(boolean algae) { private final SuperstructureVisualizer goalVisualizer = new SuperstructureVisualizer("Goal", Color.kLime); - public Superstructure(Elevator elevator, Wrist coralWrist, Intake coralIntake) { + public Superstructure( + Elevator elevator, Wrist coralWrist, Intake coralIntake, AddressableLEDSubsystem lights) { this.elevator = elevator; this.coralWrist = coralWrist; this.coralIntake = coralIntake; + this.lights = lights; } public Command run(State goal) { @@ -119,7 +124,8 @@ public Command runPrepare(State goal) { public Command prepareL1() { return Commands.parallel( - elevator.runPositionPrepare(L1_HEIGHT), coralWrist.runPositionPrepare(L1_CORAL_ANGLE)); + elevator.runPositionPrepare(L1_HEIGHT), coralWrist.runPositionPrepare(L1_CORAL_ANGLE)); + // .beforeStarting(new SetAddressableLEDPattern(lights, new Ligh)); } public Command prepareL2() { @@ -153,7 +159,7 @@ public Command stowHigh() { elevator.runPositionPrepare(STOW_HEIGHT), coralWrist.runPositionPrepare(STOW_CORAL_ANGLE_HIGH)); } - + public Command intake() { return coralIntake.runMotors(-0.6); } From ed4e9b5f86d53a94967392d62abd5a5f9c4fb760 Mon Sep 17 00:00:00 2001 From: "Aceius E." Date: Wed, 12 Mar 2025 16:02:40 -0700 Subject: [PATCH 20/21] ok good enough --- .../frc/robot/subsystems/superstructure/Superstructure.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/frc/robot/subsystems/superstructure/Superstructure.java b/src/main/java/frc/robot/subsystems/superstructure/Superstructure.java index 70a54538..069ac61a 100644 --- a/src/main/java/frc/robot/subsystems/superstructure/Superstructure.java +++ b/src/main/java/frc/robot/subsystems/superstructure/Superstructure.java @@ -122,10 +122,10 @@ public Command runPrepare(State goal) { public static final Rotation2d STOW_CORAL_ANGLE = Rotation2d.fromDegrees(-90); public static final Rotation2d STOW_CORAL_ANGLE_HIGH = Rotation2d.fromDegrees(90); + // TODO: Integrate lightstrip commands into this stuff public Command prepareL1() { return Commands.parallel( elevator.runPositionPrepare(L1_HEIGHT), coralWrist.runPositionPrepare(L1_CORAL_ANGLE)); - // .beforeStarting(new SetAddressableLEDPattern(lights, new Ligh)); } public Command prepareL2() { From b545f59e9ea666855023a3f43a6c8930f528c755 Mon Sep 17 00:00:00 2001 From: RobotLeopard86 <63123751+RobotLeopard86@users.noreply.github.com> Date: Wed, 12 Mar 2025 17:55:14 -0700 Subject: [PATCH 21/21] Fix incorrect AddressableLED test end check and clarify Range record purpose --- .../frc/robot/commands/test/AddressableLEDTestCommand.java | 2 +- .../subsystems/addressableled/AddressableLEDConstants.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/frc/robot/commands/test/AddressableLEDTestCommand.java b/src/main/java/frc/robot/commands/test/AddressableLEDTestCommand.java index 805eb0f1..69b049a6 100644 --- a/src/main/java/frc/robot/commands/test/AddressableLEDTestCommand.java +++ b/src/main/java/frc/robot/commands/test/AddressableLEDTestCommand.java @@ -48,7 +48,7 @@ public void execute() { @Override public boolean isFinished() { - return testCount < (AddressableLEDConstants.SECTIONS.length + 1); + return testCount >= (AddressableLEDConstants.SECTIONS.length + 1); } @Override diff --git a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java index 63b92c9e..78fbc8fc 100644 --- a/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java +++ b/src/main/java/frc/robot/subsystems/addressableled/AddressableLEDConstants.java @@ -6,8 +6,9 @@ public class AddressableLEDConstants { /** - * @param low The lower bound of the range - * @param high The upper bound of the range + * This record is used to represent a range of LEDs that are grouped together and exhibit one pattern + * @param low The lowest index LED in the range + * @param high The highest index LED in the range */ public record Range(int low, int high) {}