Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ public final class Constants {
public static class OperatorConstants {
public static final int kDriverControllerPort = 0;
}

//placeholder constants
public static class LEDConstants {
public static final int KPORT = 0;
public static final int KLENGTH = 60;

public static final double BLINK_TIME = 1; // in seconds for after intake/outtake
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable seems to be unused.

}
}
119 changes: 119 additions & 0 deletions src/main/java/frc/robot/subsystems/LedSubsystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package frc.robot.subsystems;

import edu.wpi.first.units.Units;

import static edu.wpi.first.units.Units.Centimeters;
import static edu.wpi.first.units.Units.Meters;
import static edu.wpi.first.units.Units.Percent;
import static edu.wpi.first.units.Units.Second;

import edu.wpi.first.units.measure.Distance;
import edu.wpi.first.units.measure.Time;
import edu.wpi.first.wpilibj.AddressableLED;
import edu.wpi.first.wpilibj.AddressableLEDBuffer;
import edu.wpi.first.wpilibj.LEDPattern;
import edu.wpi.first.wpilibj.util.Color;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.Constants.LEDConstants;

public class LedSubsystem extends SubsystemBase {
private final AddressableLED m_led;
private final AddressableLEDBuffer m_ledBuffer;

/** Called once at the beginning of the robot program. */
public LedSubsystem() {
// PWM port 9
// Must be a PWM header, not MXP or DIO
m_led = new AddressableLED(LEDConstants.KPORT);

// Reuse buffer
// Default to a length of 60, start empty output
// Length is expensive to set, so only set it once, then just update data
m_ledBuffer = new AddressableLEDBuffer(LEDConstants.KLENGTH);
m_led.setLength(m_ledBuffer.getLength());

// Set the data
m_led.setData(m_ledBuffer);

m_led.start();

// Set the default command to turn the strip off, otherwise the last colors written by
// the last command to run will continue to be displayed.
// Note: Other default patterns could be used instead!
setDefaultCommand((runScrollingRedBlueCommand()).withName("Off"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the name of this command to something like "Default colors" or something?

}


@Override
public void periodic() {
// Periodically send the latest LED color data to the LED strip for it to display


m_led.setData(m_ledBuffer);
}

/**
* Creates a command that runs a pattern on the entire LED strip.
*
* @param pattern the LED pattern to run
*/
public Command runPattern(LEDPattern pattern) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add names to all of these commands with .withName("[color/pattern]")? This way, when we log the subsystem, we'll be able to see what command is running on it (in case we need to debug, this will make our lives much easier).

return run(() -> pattern.applyTo(m_ledBuffer)).ignoringDisable(true);
}

public Command runBlinkGreen() {
return runPattern(LEDPattern.solid(Color.kGreen).blink(Time.ofBaseUnits(0.25, Units.Seconds)));
}

public Command runSolidYellow() {
return runPattern(LEDPattern.solid(Color.kYellow));
}

public Command runSolidBlue() {
return runPattern(LEDPattern.solid(Color.kDarkBlue));
}

public Command runSolidOrange() {
return runPattern(LEDPattern.solid(Color.kOrange));
}

public Command runSolidGreen() {
return runPattern(LEDPattern.solid(Color.kGreen));
}

public Command runSolidRed() {
return runPattern(LEDPattern.solid(Color.kRed));
}

public Command runSolidWhite() {
return runPattern(LEDPattern.solid(Color.kWhite));
}

public Command runSolidPink() {
return runPattern(LEDPattern.solid(Color.kPink));
}

public Command runSolidPurple() {
return runPattern(LEDPattern.solid(Color.kPurple));
}

public Command runGradientBlueYellow(){
LEDPattern gradient = LEDPattern.gradient(LEDPattern.GradientType.kDiscontinuous, Color.kYellow, Color.kBlue);
return runPattern(gradient);
}

public Command runGradientGreenYellow(){
LEDPattern gradient = LEDPattern.gradient(LEDPattern.GradientType.kDiscontinuous, Color.kYellow, Color.kGreen).scrollAtRelativeSpeed(Percent.per(Second).of(100));
return runPattern(gradient);
}

public Command runScrollingRedBlueCommand(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it red and blue? :( I liked blue + yellow better--they're our team colors! /hj

Distance ledSpacing = Meters.of(1 / 60.0);
LEDPattern base = LEDPattern.gradient(LEDPattern.GradientType.kDiscontinuous, Color.kRed, Color.kBlue);
LEDPattern pattern = base.scrollAtRelativeSpeed(Percent.per(Second).of(100));
LEDPattern absolute = base.scrollAtAbsoluteSpeed(Centimeters.per(Second).of(6.25), ledSpacing);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be unused code. Not sure if we want to keep it.

return runPattern(pattern);
}

}