From 1657b6fb8d233a127b9d2890efceefc98dfaa872 Mon Sep 17 00:00:00 2001 From: semblanceofsense Date: Mon, 24 Feb 2025 20:57:59 -0700 Subject: [PATCH 01/11] LED subsystem and command --- src/main/deploy/tuning.json | 1 + .../java/frc/robot/commands/LEDCommand.java | 21 +++++ .../frc/robot/constants/LEDConstants.java | 8 ++ .../frc/robot/subsystems/LEDSubsystem.java | 77 +++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 src/main/deploy/tuning.json create mode 100644 src/main/java/frc/robot/commands/LEDCommand.java create mode 100644 src/main/java/frc/robot/constants/LEDConstants.java create mode 100644 src/main/java/frc/robot/subsystems/LEDSubsystem.java diff --git a/src/main/deploy/tuning.json b/src/main/deploy/tuning.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/src/main/deploy/tuning.json @@ -0,0 +1 @@ +{} diff --git a/src/main/java/frc/robot/commands/LEDCommand.java b/src/main/java/frc/robot/commands/LEDCommand.java new file mode 100644 index 0000000..eab7ecb --- /dev/null +++ b/src/main/java/frc/robot/commands/LEDCommand.java @@ -0,0 +1,21 @@ +/* Black Knights Robotics (C) 2025 */ +package frc.robot.commands; + +import edu.wpi.first.wpilibj2.command.Command; +import frc.robot.subsystems.LEDSubsystem; +import frc.robot.subsystems.LEDSubsystem.AnimationTypes; + +public class LEDCommand extends Command { + private final LEDSubsystem ledSubsystem; + private final AnimationTypes animationType; + + public LEDCommand(LEDSubsystem ledSubsystem, AnimationTypes animationType) { + this.ledSubsystem = ledSubsystem; + this.animationType = animationType; + } + + @Override + public void execute() { + ledSubsystem.setAnimation(animationType); + } +} diff --git a/src/main/java/frc/robot/constants/LEDConstants.java b/src/main/java/frc/robot/constants/LEDConstants.java new file mode 100644 index 0000000..dd79438 --- /dev/null +++ b/src/main/java/frc/robot/constants/LEDConstants.java @@ -0,0 +1,8 @@ +/* Black Knights Robotics (C) 2025 */ +package frc.robot.constants; + +/** Constants for the LEDs */ +public class LEDConstants { + public static final int DEVICE_ID = 0; + public static final int LED_COUNT = 0; +} diff --git a/src/main/java/frc/robot/subsystems/LEDSubsystem.java b/src/main/java/frc/robot/subsystems/LEDSubsystem.java new file mode 100644 index 0000000..1373dba --- /dev/null +++ b/src/main/java/frc/robot/subsystems/LEDSubsystem.java @@ -0,0 +1,77 @@ +/* Black Knights Robotics (C) 2025 */ +package frc.robot.subsystems; + +import com.ctre.phoenix.led.*; +import edu.wpi.first.wpilibj2.command.SubsystemBase; +import frc.robot.constants.LEDConstants; +import frc.robot.utils.ConfigManager; +import org.apache.logging.log4j.core.pattern.AbstractStyleNameConverter.Green; +import org.apache.logging.log4j.core.pattern.AbstractStyleNameConverter.Yellow; + +// Thx Matero for half the code +public class LEDSubsystem extends SubsystemBase { + private final CANdle candle = + new CANdle( + (int) ConfigManager.getInstance().get("led_device_id", LEDConstants.DEVICE_ID), + "rio"); + + private final int ledCount = + (int) ConfigManager.getInstance().get("led_count", LEDConstants.LED_COUNT); + + private int r = 0; + private int g = 0; + private int b = 0; + + public enum AnimationTypes { + Red, + Green, + Yellow, + Blue, + Off + } + + private AnimationTypes currentAnimation = null; + private Animation animation = null; + + private boolean pureRGB = false; + + public LEDSubsystem() { + CANdleConfiguration config = new CANdleConfiguration(); + config.statusLedOffWhenActive = true; + config.disableWhenLOS = false; + config.stripType = CANdle.LEDStripType.RGB; + config.brightnessScalar = 0.1; + } + + private void setRGB(int r, int g, int b) { + this.pureRGB = true; + this.r = r; + this.g = g; + this.b = b; + // this.candle.setLEDs(r, g, b); + } + + public void setAnimation(AnimationTypes toChange) { + currentAnimation = toChange; + this.pureRGB = false; + + switch (toChange) { + case Red: + setRGB(255, 0, 0); + case Yellow: + setRGB(255, 255, 0); + case Blue: + setRGB(0, 0, 255); + case Green: + setRGB(0, 255, 0); + case Off: + setRGB(0, 0, 0); + } + } + + @Override + public void periodic() { + candle.animate(animation); + if (this.pureRGB) candle.setLEDs(this.r, this.g, this.b); + } +} From 841bc8b1a87846e3466cfc00833eb41b7069e25d Mon Sep 17 00:00:00 2001 From: semblanceofsense Date: Wed, 26 Feb 2025 12:48:49 -0700 Subject: [PATCH 02/11] remove tuning.json --- src/main/deploy/tuning.json | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/main/deploy/tuning.json diff --git a/src/main/deploy/tuning.json b/src/main/deploy/tuning.json deleted file mode 100644 index 0967ef4..0000000 --- a/src/main/deploy/tuning.json +++ /dev/null @@ -1 +0,0 @@ -{} From 978a1f9a8fbad5c045d0f73f90a824bc6ec4cdbe Mon Sep 17 00:00:00 2001 From: semblanceofsense Date: Wed, 26 Feb 2025 13:43:55 -0700 Subject: [PATCH 03/11] Remove command edit out periodic --- .../java/frc/robot/commands/LEDCommand.java | 21 ------------------- .../frc/robot/subsystems/LEDSubsystem.java | 10 ++------- 2 files changed, 2 insertions(+), 29 deletions(-) delete mode 100644 src/main/java/frc/robot/commands/LEDCommand.java diff --git a/src/main/java/frc/robot/commands/LEDCommand.java b/src/main/java/frc/robot/commands/LEDCommand.java deleted file mode 100644 index eab7ecb..0000000 --- a/src/main/java/frc/robot/commands/LEDCommand.java +++ /dev/null @@ -1,21 +0,0 @@ -/* Black Knights Robotics (C) 2025 */ -package frc.robot.commands; - -import edu.wpi.first.wpilibj2.command.Command; -import frc.robot.subsystems.LEDSubsystem; -import frc.robot.subsystems.LEDSubsystem.AnimationTypes; - -public class LEDCommand extends Command { - private final LEDSubsystem ledSubsystem; - private final AnimationTypes animationType; - - public LEDCommand(LEDSubsystem ledSubsystem, AnimationTypes animationType) { - this.ledSubsystem = ledSubsystem; - this.animationType = animationType; - } - - @Override - public void execute() { - ledSubsystem.setAnimation(animationType); - } -} diff --git a/src/main/java/frc/robot/subsystems/LEDSubsystem.java b/src/main/java/frc/robot/subsystems/LEDSubsystem.java index 1373dba..95f72bf 100644 --- a/src/main/java/frc/robot/subsystems/LEDSubsystem.java +++ b/src/main/java/frc/robot/subsystems/LEDSubsystem.java @@ -48,11 +48,11 @@ private void setRGB(int r, int g, int b) { this.r = r; this.g = g; this.b = b; - // this.candle.setLEDs(r, g, b); + this.candle.setLEDs(r, g, b); } public void setAnimation(AnimationTypes toChange) { - currentAnimation = toChange; + this.currentAnimation = toChange; this.pureRGB = false; switch (toChange) { @@ -68,10 +68,4 @@ public void setAnimation(AnimationTypes toChange) { setRGB(0, 0, 0); } } - - @Override - public void periodic() { - candle.animate(animation); - if (this.pureRGB) candle.setLEDs(this.r, this.g, this.b); - } } From b9fce006c31a6563dd52e7c8cc5edac767ae2c2e Mon Sep 17 00:00:00 2001 From: semblanceofsense Date: Wed, 26 Feb 2025 13:49:31 -0700 Subject: [PATCH 04/11] Delete unnecessary imports --- src/main/java/frc/robot/subsystems/LEDSubsystem.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/frc/robot/subsystems/LEDSubsystem.java b/src/main/java/frc/robot/subsystems/LEDSubsystem.java index 95f72bf..320d091 100644 --- a/src/main/java/frc/robot/subsystems/LEDSubsystem.java +++ b/src/main/java/frc/robot/subsystems/LEDSubsystem.java @@ -4,19 +4,16 @@ import com.ctre.phoenix.led.*; import edu.wpi.first.wpilibj2.command.SubsystemBase; import frc.robot.constants.LEDConstants; -import frc.robot.utils.ConfigManager; -import org.apache.logging.log4j.core.pattern.AbstractStyleNameConverter.Green; -import org.apache.logging.log4j.core.pattern.AbstractStyleNameConverter.Yellow; // Thx Matero for half the code public class LEDSubsystem extends SubsystemBase { private final CANdle candle = new CANdle( - (int) ConfigManager.getInstance().get("led_device_id", LEDConstants.DEVICE_ID), + LEDConstants.DEVICE_ID, "rio"); private final int ledCount = - (int) ConfigManager.getInstance().get("led_count", LEDConstants.LED_COUNT); + LEDConstants.LED_COUNT; private int r = 0; private int g = 0; From 003c8291747989e60eebee2173544bd2392f0573 Mon Sep 17 00:00:00 2001 From: semblanceofsense Date: Wed, 26 Feb 2025 13:56:06 -0700 Subject: [PATCH 05/11] javadoc --- src/main/java/frc/robot/subsystems/LEDSubsystem.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/frc/robot/subsystems/LEDSubsystem.java b/src/main/java/frc/robot/subsystems/LEDSubsystem.java index 320d091..1bbc42a 100644 --- a/src/main/java/frc/robot/subsystems/LEDSubsystem.java +++ b/src/main/java/frc/robot/subsystems/LEDSubsystem.java @@ -5,7 +5,10 @@ import edu.wpi.first.wpilibj2.command.SubsystemBase; import frc.robot.constants.LEDConstants; -// Thx Matero for half the code +/** + * Subsystem for LED colors and animations + * Thx Matero for half the code +*/ public class LEDSubsystem extends SubsystemBase { private final CANdle candle = new CANdle( @@ -19,6 +22,7 @@ public class LEDSubsystem extends SubsystemBase { private int g = 0; private int b = 0; + /** Possible animation/colors */ public enum AnimationTypes { Red, Green, @@ -32,6 +36,7 @@ public enum AnimationTypes { private boolean pureRGB = false; + /** Create new LED subsystem */ public LEDSubsystem() { CANdleConfiguration config = new CANdleConfiguration(); config.statusLedOffWhenActive = true; @@ -40,6 +45,7 @@ public LEDSubsystem() { config.brightnessScalar = 0.1; } + /** Set LEDs to static color */ private void setRGB(int r, int g, int b) { this.pureRGB = true; this.r = r; @@ -48,6 +54,7 @@ private void setRGB(int r, int g, int b) { this.candle.setLEDs(r, g, b); } + /** Set animation/color of LEDs */ public void setAnimation(AnimationTypes toChange) { this.currentAnimation = toChange; this.pureRGB = false; From bcc0c7510367c982696bb549853a09fa486f792d Mon Sep 17 00:00:00 2001 From: semblanceofsense Date: Wed, 26 Feb 2025 13:56:47 -0700 Subject: [PATCH 06/11] spotless --- .../java/frc/robot/subsystems/LEDSubsystem.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/main/java/frc/robot/subsystems/LEDSubsystem.java b/src/main/java/frc/robot/subsystems/LEDSubsystem.java index 1bbc42a..96e916b 100644 --- a/src/main/java/frc/robot/subsystems/LEDSubsystem.java +++ b/src/main/java/frc/robot/subsystems/LEDSubsystem.java @@ -5,18 +5,11 @@ import edu.wpi.first.wpilibj2.command.SubsystemBase; import frc.robot.constants.LEDConstants; -/** - * Subsystem for LED colors and animations - * Thx Matero for half the code -*/ +/** Subsystem for LED colors and animations Thx Matero for half the code */ public class LEDSubsystem extends SubsystemBase { - private final CANdle candle = - new CANdle( - LEDConstants.DEVICE_ID, - "rio"); + private final CANdle candle = new CANdle(LEDConstants.DEVICE_ID, "rio"); - private final int ledCount = - LEDConstants.LED_COUNT; + private final int ledCount = LEDConstants.LED_COUNT; private int r = 0; private int g = 0; From f0768000824298077bd7bb2c2856bb99912d4b8e Mon Sep 17 00:00:00 2001 From: semblanceofsense Date: Wed, 26 Feb 2025 14:16:44 -0700 Subject: [PATCH 07/11] Add params to javadoc --- .../java/frc/robot/subsystems/LEDSubsystem.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/frc/robot/subsystems/LEDSubsystem.java b/src/main/java/frc/robot/subsystems/LEDSubsystem.java index 96e916b..cedf8a0 100644 --- a/src/main/java/frc/robot/subsystems/LEDSubsystem.java +++ b/src/main/java/frc/robot/subsystems/LEDSubsystem.java @@ -38,7 +38,13 @@ public LEDSubsystem() { config.brightnessScalar = 0.1; } - /** Set LEDs to static color */ + /** + * Set LEDs to static color + * + * @param r LED red value 0-255 + * @param b LED blue value 0-255 + * @param g LED green value 0-255 + */ private void setRGB(int r, int g, int b) { this.pureRGB = true; this.r = r; @@ -47,7 +53,11 @@ private void setRGB(int r, int g, int b) { this.candle.setLEDs(r, g, b); } - /** Set animation/color of LEDs */ + /** + * Set animation/color of LEDs + * + * @param toChange Animation to change the animation to + */ public void setAnimation(AnimationTypes toChange) { this.currentAnimation = toChange; this.pureRGB = false; From 6c64cf25d62262088895b2e56011fd88379478cf Mon Sep 17 00:00:00 2001 From: semblanceofsense Date: Wed, 26 Feb 2025 14:17:50 -0700 Subject: [PATCH 08/11] Remove code artifacts --- src/main/java/frc/robot/subsystems/LEDSubsystem.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/main/java/frc/robot/subsystems/LEDSubsystem.java b/src/main/java/frc/robot/subsystems/LEDSubsystem.java index cedf8a0..5e6e86f 100644 --- a/src/main/java/frc/robot/subsystems/LEDSubsystem.java +++ b/src/main/java/frc/robot/subsystems/LEDSubsystem.java @@ -24,11 +24,6 @@ public enum AnimationTypes { Off } - private AnimationTypes currentAnimation = null; - private Animation animation = null; - - private boolean pureRGB = false; - /** Create new LED subsystem */ public LEDSubsystem() { CANdleConfiguration config = new CANdleConfiguration(); @@ -46,7 +41,6 @@ public LEDSubsystem() { * @param g LED green value 0-255 */ private void setRGB(int r, int g, int b) { - this.pureRGB = true; this.r = r; this.g = g; this.b = b; @@ -59,9 +53,6 @@ private void setRGB(int r, int g, int b) { * @param toChange Animation to change the animation to */ public void setAnimation(AnimationTypes toChange) { - this.currentAnimation = toChange; - this.pureRGB = false; - switch (toChange) { case Red: setRGB(255, 0, 0); From ed552157f4a301b4d5fe5dc97387486bc3c388ae Mon Sep 17 00:00:00 2001 From: semblanceofsense Date: Wed, 26 Feb 2025 15:44:29 -0700 Subject: [PATCH 09/11] remove unread variables --- src/main/java/frc/robot/constants/LEDConstants.java | 1 - src/main/java/frc/robot/subsystems/LEDSubsystem.java | 11 +---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/main/java/frc/robot/constants/LEDConstants.java b/src/main/java/frc/robot/constants/LEDConstants.java index dd79438..d284729 100644 --- a/src/main/java/frc/robot/constants/LEDConstants.java +++ b/src/main/java/frc/robot/constants/LEDConstants.java @@ -4,5 +4,4 @@ /** Constants for the LEDs */ public class LEDConstants { public static final int DEVICE_ID = 0; - public static final int LED_COUNT = 0; } diff --git a/src/main/java/frc/robot/subsystems/LEDSubsystem.java b/src/main/java/frc/robot/subsystems/LEDSubsystem.java index 5e6e86f..94b705e 100644 --- a/src/main/java/frc/robot/subsystems/LEDSubsystem.java +++ b/src/main/java/frc/robot/subsystems/LEDSubsystem.java @@ -9,12 +9,6 @@ public class LEDSubsystem extends SubsystemBase { private final CANdle candle = new CANdle(LEDConstants.DEVICE_ID, "rio"); - private final int ledCount = LEDConstants.LED_COUNT; - - private int r = 0; - private int g = 0; - private int b = 0; - /** Possible animation/colors */ public enum AnimationTypes { Red, @@ -41,10 +35,7 @@ public LEDSubsystem() { * @param g LED green value 0-255 */ private void setRGB(int r, int g, int b) { - this.r = r; - this.g = g; - this.b = b; - this.candle.setLEDs(r, g, b); + candle.setLEDs(r, g, b); } /** From 9bbd55c3bfc0604334e1222103896903930fdc6a Mon Sep 17 00:00:00 2001 From: semblanceofsense Date: Thu, 27 Feb 2025 18:25:47 -0700 Subject: [PATCH 10/11] Don't update if colors arent changed --- src/main/deploy/tuning.json | 1 + src/main/java/frc/robot/subsystems/LEDSubsystem.java | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/main/deploy/tuning.json diff --git a/src/main/deploy/tuning.json b/src/main/deploy/tuning.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/src/main/deploy/tuning.json @@ -0,0 +1 @@ +{} diff --git a/src/main/java/frc/robot/subsystems/LEDSubsystem.java b/src/main/java/frc/robot/subsystems/LEDSubsystem.java index 94b705e..7d321cc 100644 --- a/src/main/java/frc/robot/subsystems/LEDSubsystem.java +++ b/src/main/java/frc/robot/subsystems/LEDSubsystem.java @@ -8,6 +8,9 @@ /** Subsystem for LED colors and animations Thx Matero for half the code */ public class LEDSubsystem extends SubsystemBase { private final CANdle candle = new CANdle(LEDConstants.DEVICE_ID, "rio"); + private int r = 0; + private int g = 0; + private int b = 0; /** Possible animation/colors */ public enum AnimationTypes { @@ -35,7 +38,12 @@ public LEDSubsystem() { * @param g LED green value 0-255 */ private void setRGB(int r, int g, int b) { - candle.setLEDs(r, g, b); + if (this.r != r || this.b != b || this.g != g) { + candle.setLEDs(r, g, b); + this.r = r; + this.g = g; + this.b = b; + } } /** From f520b6bb95c8ed4363181d8aaf7abca08052cf4c Mon Sep 17 00:00:00 2001 From: semblanceofsense Date: Thu, 27 Feb 2025 18:43:41 -0700 Subject: [PATCH 11/11] REMOVE TUNING.JSON --- src/main/deploy/tuning.json | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/main/deploy/tuning.json diff --git a/src/main/deploy/tuning.json b/src/main/deploy/tuning.json deleted file mode 100644 index 0967ef4..0000000 --- a/src/main/deploy/tuning.json +++ /dev/null @@ -1 +0,0 @@ -{}