diff --git a/src/main/java/frc/team3128/Constants.java b/src/main/java/frc/team3128/Constants.java index 35605ee..5156769 100644 --- a/src/main/java/frc/team3128/Constants.java +++ b/src/main/java/frc/team3128/Constants.java @@ -552,44 +552,45 @@ public static class BalanceConstants{ } public static class LedConstants{ - public static class Green{ - public static final int HUE = 60; - public static final int SATURATION = 255; - public static final int VALUE = 255; - } - - public static class Blue{ - public static final int HUE = 120; - public static final int SATURATION = 255; - public static final int VALUE = 255; - } + public static final int CANDLE_ID = 37; + + public static final int WHITE_VALUE = 0; //leds used don't have a white value + + public static final int STARTING_ID = 8; + public static final int PIVOT_COUNT = 100; + public static final int PIVOT_COUNT_FRONT = 50; //change + public static final int PIVOT_COUNT_BACK = 50; //change - public static class Red{ - public static final int HUE = 0; - public static final int SATURATION = 255; - public static final int VALUE = 255; - } + public static final double HOLDING_SPEED = 2; - public static class Yellow{ - public static final int HUE = 30; - public static final int SATURATION = 255; - public static final int VALUE = 255; - } + public static class RainbowAnimation { + public static final double BRIGHTNESS = 1; + public static final double SPEED = 1; - public static class Purple{ - public static final int HUE = 130; - public static final int SATURATION = 255; - public static final int VALUE = 50; } - public static class Off{ - public static final int HUE = 0; - public static final int SATURATION = 0; - public static final int VALUE = 0; + public enum Colors { + OFF(0,0,0,false), + CONE(255,255,0,false), + CUBE(255,0,255,false), + HOLDING(255,0,0,false), + + AUTO(0,0,0,true), + DEFAULT(0,0,225,false); + + public final int r; + public final int b; + public final int g; + public final boolean animation; + + Colors(int r, int g, int b,boolean animation) { + this.r = r; + this.g = g; + this.b = b; + this.animation = animation; + } + } - - public static final int PORT = 0; - public static final int LENGTH = 288; } diff --git a/src/main/java/frc/team3128/RobotContainer.java b/src/main/java/frc/team3128/RobotContainer.java index ab30cd9..7852094 100644 --- a/src/main/java/frc/team3128/RobotContainer.java +++ b/src/main/java/frc/team3128/RobotContainer.java @@ -12,7 +12,7 @@ import edu.wpi.first.wpilibj2.command.RunCommand; import edu.wpi.first.wpilibj2.command.button.Trigger; import frc.team3128.commands.CmdSwerveDrive; - +import frc.team3128.Constants.LedConstants.Colors; import frc.team3128.PositionConstants.Position; import static frc.team3128.commands.CmdManager.*; import frc.team3128.common.hardware.input.NAR_ButtonBoard; @@ -21,7 +21,7 @@ import frc.team3128.common.narwhaldashboard.NarwhalDashboard; import frc.team3128.common.utility.Log; import frc.team3128.subsystems.Elevator; -import frc.team3128.subsystems.Led; +import frc.team3128.subsystems.Leds; import frc.team3128.common.utility.NAR_Shuffleboard; import frc.team3128.subsystems.Swerve; import frc.team3128.subsystems.Vision; @@ -38,7 +38,7 @@ public class RobotContainer { private Swerve swerve; private Vision vision; - private Led led; + private Leds leds; private Elevator elevator; private NAR_Joystick leftStick; @@ -61,7 +61,7 @@ public RobotContainer() { swerve = Swerve.getInstance(); vision = Vision.getInstance(); - led = Led.getInstance(); + leds = Leds.getInstance(); elevator = Elevator.getInstance(); //TODO: Enable all PIDSubsystems so that useOutput runs here @@ -168,6 +168,7 @@ private void configureButtonBindings() { } public void init() { + leds.setElevatorLeds(Colors.DEFAULT); Vision.AUTO_ENABLED = false; if (DriverStation.getAlliance() == Alliance.Red) { buttonPad.getButton(4).onTrue( diff --git a/src/main/java/frc/team3128/commands/CmdManager.java b/src/main/java/frc/team3128/commands/CmdManager.java index 9764ce4..c2a919a 100644 --- a/src/main/java/frc/team3128/commands/CmdManager.java +++ b/src/main/java/frc/team3128/commands/CmdManager.java @@ -9,7 +9,7 @@ import frc.team3128.PositionConstants.Position; import frc.team3128.common.hardware.input.NAR_XboxController; -import frc.team3128.subsystems.Led; +import frc.team3128.subsystems.Leds; import frc.team3128.subsystems.Wrist; import frc.team3128.subsystems.Manipulator; import frc.team3128.subsystems.Swerve; @@ -17,7 +17,7 @@ import frc.team3128.subsystems.Elevator; public class CmdManager { - private static Led led = Led.getInstance(); + private static Leds leds = Leds.getInstance(); private static Wrist wrist = Wrist.getInstance(); private static Manipulator manipulator = Manipulator.getInstance(); private static Swerve swerve = Swerve.getInstance(); diff --git a/src/main/java/frc/team3128/subsystems/Led.java b/src/main/java/frc/team3128/subsystems/Led.java deleted file mode 100644 index b05e65c..0000000 --- a/src/main/java/frc/team3128/subsystems/Led.java +++ /dev/null @@ -1,88 +0,0 @@ -package frc.team3128.subsystems; - -import edu.wpi.first.wpilibj.AddressableLED; -import edu.wpi.first.wpilibj.AddressableLEDBuffer; -import edu.wpi.first.wpilibj.DriverStation; -import edu.wpi.first.wpilibj2.command.SubsystemBase; -import frc.team3128.Constants.LedConstants; -import frc.team3128.Constants.LedConstants.*; - -public class Led extends SubsystemBase{ - - private static Led instance; - private AddressableLED led; - private AddressableLEDBuffer ledBuffer; - - public Led(){ - initLEDs(); - } - - public static synchronized Led getInstance() { - if (instance == null) { - instance = new Led(); - } - return instance; - } - - public void initLEDs() { - led = new AddressableLED(LedConstants.PORT); - - ledBuffer = new AddressableLEDBuffer(LedConstants.LENGTH); - led.setLength(ledBuffer.getLength()); - - led.setData(ledBuffer); - led.start(); - - } - - //general color methods : use variables - public void setRGB(int r, int g, int b) { - for (var i = 0; i < ledBuffer.getLength(); i++) { - // Sets the specified LED to the RGB values - ledBuffer.setRGB(i, r, g, b); - } - - led.setData(ledBuffer); - } - - public void setHSV(int h, int s, int v) { - for (var i = 0; i < ledBuffer.getLength(); i++) { - // Sets the specified LED to the HSV values - ledBuffer.setHSV(i, h, s, v); - } - - led.setData(ledBuffer); - } - - //custom color methods : use constants - public void setAllianceColor() { - if (DriverStation.getAlliance() == DriverStation.Alliance.Blue) { - setHSV(Blue.HUE, Blue.SATURATION, Blue.VALUE); - } - else if (DriverStation.getAlliance() == DriverStation.Alliance.Red) { - setHSV(Red.HUE, Red.SATURATION, Red.VALUE); - } - } - - public void setColorYellow() { - setHSV(Yellow.HUE, Yellow.SATURATION, Yellow.VALUE); - } - - public void setColorPurple() { - setHSV(Purple.HUE, Purple.SATURATION, Purple.VALUE); - } - - public void setAutoColor() { - setHSV(Green.HUE, Green.SATURATION, Green.VALUE); - } - - public void setPickupColor(boolean cone) { - if (cone) { - setColorYellow(); - } else { - setColorPurple(); - } - } - - -} diff --git a/src/main/java/frc/team3128/subsystems/Leds.java b/src/main/java/frc/team3128/subsystems/Leds.java new file mode 100644 index 0000000..f30d2e3 --- /dev/null +++ b/src/main/java/frc/team3128/subsystems/Leds.java @@ -0,0 +1,82 @@ +package frc.team3128.subsystems; + +import com.ctre.phoenix.led.CANdle; +import com.ctre.phoenix.led.CANdle.LEDStripType; +import com.ctre.phoenix.led.CANdle.VBatOutputMode; +import com.ctre.phoenix.CANifier.LEDChannel; +import com.ctre.phoenix.led.Animation; +import com.ctre.phoenix.led.CANdleConfiguration; +import com.ctre.phoenix.led.CANdleControlFrame; +import com.ctre.phoenix.led.CANdleStatusFrame; +import com.ctre.phoenix.led.RainbowAnimation; +import com.ctre.phoenix.led.RgbFadeAnimation; +import com.ctre.phoenix.led.SingleFadeAnimation; +import com.ctre.phoenix.led.ColorFlowAnimation.Direction; +import com.ctre.phoenix.led.LarsonAnimation.BounceMode; +import com.ctre.phoenix.led.TwinkleAnimation.TwinklePercent; +import com.ctre.phoenix.led.TwinkleOffAnimation.TwinkleOffPercent; + + +import edu.wpi.first.wpilibj2.command.SubsystemBase; +import frc.team3128.Constants.LedConstants; +import frc.team3128.Constants.LedConstants.Colors;; + + +public class Leds extends SubsystemBase { + private final CANdle m_candle = new CANdle(LedConstants.CANDLE_ID); + + private static Leds instance; + + public static Leds getInstance() { + if (instance == null) { + instance = new Leds(); + } + return instance; + } + + public Leds() { + configCandle(); + } + + private void configCandle() { + CANdleConfiguration config = new CANdleConfiguration(); + config.stripType = LEDStripType.RGB; + config.brightnessScalar = 1; + m_candle.configAllSettings(config); + } + + //Set Elevator Leds + public void setElevatorLeds(Colors color) { + + switch (color) { + case AUTO : + m_candle.animate(new RainbowAnimation(LedConstants.RainbowAnimation.BRIGHTNESS,LedConstants.RainbowAnimation.SPEED,LedConstants.PIVOT_COUNT_FRONT,false,LedConstants.STARTING_ID),0); + m_candle.animate(new RainbowAnimation(LedConstants.RainbowAnimation.BRIGHTNESS,LedConstants.RainbowAnimation.SPEED,LedConstants.PIVOT_COUNT_BACK,true,LedConstants.STARTING_ID+LedConstants.PIVOT_COUNT_FRONT),1); + break; + case HOLDING: + resetAnimationSlot(1,1); + m_candle.animate(new SingleFadeAnimation(color.r, color.g, color.b,LedConstants.WHITE_VALUE,LedConstants.HOLDING_SPEED,LedConstants.PIVOT_COUNT),0); + break; + default : + resetAnimationSlot(2); + m_candle.setLEDs(color.r,color.g,color.b,LedConstants.WHITE_VALUE,LedConstants.STARTING_ID,LedConstants.PIVOT_COUNT); + break; + } + } + + public void resetAnimationSlot(int slots) { + for (int i = 0; i < slots; i++) { + m_candle.animate(null,i); + } + } + + public void resetAnimationSlot(int slots, int offset) { + for (int i = 0; i < slots; i++) { + m_candle.animate(null,i+offset); + } + } + + + + +} \ No newline at end of file