Skip to content
3 changes: 3 additions & 0 deletions src/main/java/org/team2342/frc/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
import org.littletonrobotics.junction.networktables.NT4Publisher;
import org.littletonrobotics.junction.wpilog.WPILOGReader;
import org.littletonrobotics.junction.wpilog.WPILOGWriter;
// import org.team2342.frc.subsystems.CANdleSystem.CANdleSystem;
import org.team2342.frc.util.PhoenixUtils;
import org.team2342.lib.logging.ExecutionLogger;

public class Robot extends LoggedRobot {
private Command autonomousCommand;
private static final double loopOverrunWarningTimeout = 0.2;
// private final CANdleSystem candle = new CANdleSystem(null);

private final RobotContainer robotContainer;

Expand Down Expand Up @@ -160,6 +162,7 @@ public void robotPeriodic() {
robotContainer.updateAlerts();

ExecutionLogger.log("RobotPeriodic");
// candle.periodic();
}

@Override
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/team2342/frc/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import edu.wpi.first.wpilibj.Alert.AlertType;
import edu.wpi.first.wpilibj.PowerDistribution.ModuleType;
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.Commands;
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine;
Expand All @@ -37,13 +38,18 @@
import org.team2342.frc.subsystems.vision.Vision;
import org.team2342.frc.subsystems.vision.VisionIO;
import org.team2342.frc.subsystems.vision.VisionIOSim;
import org.team2342.lib.leds.*;
import org.team2342.lib.leds.LedIO.LedEffect;
import org.team2342.lib.util.AllianceUtils;
import org.team2342.lib.util.EnhancedXboxController;

public class RobotContainer {
@Getter private final Drive drive;
@Getter private final Vision vision;

public final LedIOCANdle candle = new LedIOCANdle(22, 37);
public final LedStrip leds = new LedStrip(candle, "leds");

private final LoggedDashboardChooser<Command> autoChooser;

@Getter
Expand Down Expand Up @@ -107,7 +113,6 @@ public RobotContainer() {

autoChooser = new LoggedDashboardChooser<>("Auto Choices", AutoBuilder.buildAutoChooser());
autoChooser.get();

if (Constants.TUNING) setupDevelopmentRoutines();

configureBindings();
Expand Down Expand Up @@ -150,6 +155,10 @@ private void configureBindings() {
drive::getPose,
() -> -driverController.getLeftY(),
() -> -driverController.getLeftX()));

leds.setFirst(Color.kRed, LedEffect.FLASHING);
leds.setSecond(Color.kBlue, LedEffect.RAINBOW);
// leds.setAll(Color.kGreen, LedEffect.RAINBOW);
}

public Command getAutonomousCommand() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
// Copyright (c) 2026 Team 2342
// https://github.com/FRCTeamPhoenix
//
// This source code is licensed under the MIT License.
// See the LICENSE file in the root directory of this project.

package org.team2342.frc.subsystems.CANdleSystem;

import com.ctre.phoenix6.CANBus;
import com.ctre.phoenix6.configs.CANdleConfiguration;
import com.ctre.phoenix6.controls.SolidColor;
import com.ctre.phoenix6.hardware.CANdle;
import com.ctre.phoenix6.signals.RGBWColor;
import com.ctre.phoenix6.signals.StatusLedWhenActiveValue;
import com.ctre.phoenix6.signals.StripTypeValue;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

public class CANdleSystem extends SubsystemBase {
private final CANdle m_candle = new CANdle(22, new CANBus("rio"));
private final int LedCount = 300;
private XboxController joystick;

public enum AnimationTypes {
ColorFlow,
Fire,
Larson,
Rainbow,
RgbFade,
SingleFade,
Strobe,
Twinkle,
TwinkleOff,
SetAll
}

private AnimationTypes m_currentAnimation;

public CANdleSystem(XboxController joy) {
this.joystick = joy;
changeAnimation(AnimationTypes.SetAll);
CANdleConfiguration configAll = new CANdleConfiguration();
configAll.CANdleFeatures.StatusLedWhenActive = StatusLedWhenActiveValue.Disabled;
configAll.LED.StripType = StripTypeValue.GRB;
m_candle.getConfigurator().apply(configAll);
}

public void incrementAnimation() {
switch (m_currentAnimation) {
case ColorFlow:
changeAnimation(AnimationTypes.Fire);
break;
case Fire:
changeAnimation(AnimationTypes.Larson);
break;
case Larson:
changeAnimation(AnimationTypes.Rainbow);
break;
case Rainbow:
changeAnimation(AnimationTypes.RgbFade);
break;
case RgbFade:
changeAnimation(AnimationTypes.SingleFade);
break;
case SingleFade:
changeAnimation(AnimationTypes.Strobe);
break;
case Strobe:
changeAnimation(AnimationTypes.Twinkle);
break;
case Twinkle:
changeAnimation(AnimationTypes.TwinkleOff);
break;
case TwinkleOff:
changeAnimation(AnimationTypes.ColorFlow);
break;
case SetAll:
changeAnimation(AnimationTypes.ColorFlow);
break;
}
}

public void decrementAnimation() {
switch (m_currentAnimation) {
case ColorFlow:
changeAnimation(AnimationTypes.TwinkleOff);
break;
case Fire:
changeAnimation(AnimationTypes.ColorFlow);
break;
case Larson:
changeAnimation(AnimationTypes.Fire);
break;
case Rainbow:
changeAnimation(AnimationTypes.Larson);
break;
case RgbFade:
changeAnimation(AnimationTypes.Rainbow);
break;
case SingleFade:
changeAnimation(AnimationTypes.RgbFade);
break;
case Strobe:
changeAnimation(AnimationTypes.SingleFade);
break;
case Twinkle:
changeAnimation(AnimationTypes.Strobe);
break;
case TwinkleOff:
changeAnimation(AnimationTypes.Twinkle);
break;
case SetAll:
changeAnimation(AnimationTypes.ColorFlow);
break;
}
}

public void setColors() {
changeAnimation(AnimationTypes.SetAll);
}

public void changeAnimation(AnimationTypes toChange) {
m_currentAnimation = toChange;

// switch(toChange)
// {
// case ColorFlow:
// m_toAnimate = new ColorFlowAnimation(128, 20, 70, 0, 0.7, LedCount,
// Direction.Forward);
// break;
// case Fire:
// m_toAnimate = new FireAnimation(0.5, 0.7, LedCount, 0.7, 0.5);
// break;
// case Larson:
// m_toAnimate = new LarsonAnimation(0, 255, 46, 0, 1, LedCount, BounceMode.Front, 3);
// break;
// case Rainbow:
// m_toAnimate = new RainbowAnimation(1, 0.1, LedCount);
// break;
// case RgbFade:
// m_toAnimate = new RgbFadeAnimation(0.7, 0.4, LedCount);
// break;
// case SingleFade:
// m_toAnimate = new SingleFadeAnimation(50, 2, 200, 0, 0.5, LedCount);
// break;
// case Strobe:
// m_toAnimate = new StrobeAnimation(240, 10, 180, 0, 98.0 / 256.0, LedCount);
// break;
// case Twinkle:
// m_toAnimate = new TwinkleAnimation(30, 70, 60, 0, 0.4, LedCount,
// TwinklePercent.Percent6);
// break;
// case TwinkleOff:
// m_toAnimate = new TwinkleOffAnimation(70, 90, 175, 0, 0.8, LedCount,
// TwinkleOffPercent.Percent100);
// break;
// case SetAll:
// m_toAnimate = null;
// break;
// }
// System.out.println("Changed to " + m_currentAnimation.toString());
}

@Override
public void periodic() {
// This method will be called once per scheduler run
// SolidColor request = new SolidColor(0, 67);
// request.withColor(new RGBWColor(0, 255, 0,0));

m_candle.setControl(new SolidColor(0, 67).withColor(new RGBWColor(0, 217, 0, 0)));

// if(m_toAnimate == null) {
// m_candle.setLEDs((int)(joystick.getLeftTriggerAxis() * 255),
// (int)(joystick.getRightTriggerAxis() * 255),
// (int)(joystick.getLeftX() * 255));
// } else {
// m_candle.animate(m_toAnimate);
// }
// m_candle.modulateVBatOutput(joystick.getRightY());
}

@Override
public void simulationPeriodic() {
// This method will be called once per scheduler run during simulation
}
}
15 changes: 15 additions & 0 deletions src/main/java/org/team2342/frc/util/PhoenixUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import com.ctre.phoenix6.BaseStatusSignal;
import com.ctre.phoenix6.StatusCode;
import com.ctre.phoenix6.signals.RGBWColor;
import edu.wpi.first.wpilibj.util.Color;
import java.util.function.Supplier;

public class PhoenixUtils {
Expand Down Expand Up @@ -47,4 +49,17 @@ public static void refreshSignals() {
// Check to make sure there are signals to refresh
if (registeredSignals.length > 0) BaseStatusSignal.refreshAll(registeredSignals);
}

/**
* Used to convert {@link edu.wpi.first.wpilibj.util.Color} to {@link
* com.ctre.phoenix6.signals.RGBWColor}
*
* @param c WPILib Color to be converted
*/
public static RGBWColor toCTREColor(Color c) {
if (c == null) {
return new RGBWColor(0, 0, 0, 0);
}
return new RGBWColor((int) (c.red * 255), (int) (c.green * 255), (int) (c.blue * 255), 0);
}
}
40 changes: 39 additions & 1 deletion src/main/java/org/team2342/lib/leds/LedIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,42 @@

package org.team2342.lib.leds;

public interface LedIO {}
import edu.wpi.first.wpilibj.util.Color;
// import org.littletonrobotics.junction.AutoLog;

public interface LedIO {
// @AutoLog
public static class LedIOInputs {
public Color firstHalfColor = Color.kBlack;
public Color secondHalfColor = Color.kBlack;
public LedEffect firstHalfEffect = LedEffect.OFF;
public LedEffect secondHalfEffect = LedEffect.OFF;
}

public default void updateInputs(LedIOInputs inputs) {}

public default void setColor(Half half, Color color) {}

public default void setEffect(Half half, LedEffect effect, Color color) {}

public default void setColor(Color color) {
setColor(Half.ALL, color);
}

public default void setEffect(LedEffect effect, Color color) {
setEffect(Half.ALL, effect, color);
}

public enum Half {
FIRST,
SECOND,
ALL
}

public enum LedEffect {
SOLID,
FLASHING,
RAINBOW,
OFF
}
}
Loading