Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelLesirge committed Mar 1, 2024
2 parents 8be1aa7 + 7af525b commit 9b77e94
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 34 deletions.
11 changes: 10 additions & 1 deletion src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,16 @@ public static class VisionConstants {
}

public static class LightConstants {
public static final int LED_CONTROLLER_PWM_SLOT = 0;
public static final int LED_CONTROLLER_PWM_SLOT = 1;
public static final int LED_QUANTITY = 60;

public static final double LED_COLOR_RED = 0.61;
public static final double LED_COLOR_ORANGE = 0.65;
public static final double LED_COLOR_YELLOW = 0.69;
public static final double LED_COLOR_GREEN = 0.77;
public static final double LED_COLOR_BLUE = 0.87;
public static final double LED_COLOR_PURPLE = 0.91;
public static final double LED_COLOR_WHITE = 0.93;
public static final double LED_COLOR_RAINBOW = -0.99;
}
}
11 changes: 8 additions & 3 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import com.kauailabs.navx.frc.AHRS;

import edu.wpi.first.wpilibj.AddressableLED;
import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.GenericHID.HIDType;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
Expand Down Expand Up @@ -94,7 +93,11 @@ public class RobotContainer {

private final Vision vision = new Vision(VisionConstants.CAMERA_NAME, VisionConstants.CAMERA_POSE);

private final LightStrip lightStrip = new LightStrip(new AddressableLED(LightConstants.LED_CONTROLLER_PWM_SLOT));
private final ArmRotateTo armToIntake = new ArmRotateTo(arm, ArmConstants.ARM_INTAKE_DEGREES);
private final ArmRotateTo armToAmp = new ArmRotateTo(arm, ArmConstants.ARM_AMP_SHOOTING_DEGREES);
private final ArmRotateTo armToSpeaker = new ArmRotateTo(arm, ArmConstants.ARM_SPEAKER_SHOOTING_DEGREES);

private final LightStrip lightStrip = new LightStrip(LightConstants.LED_CONTROLLER_PWM_SLOT);

/**
* The container for the robot. Contains subsystems, OI devices, and commands.
Expand All @@ -103,7 +106,6 @@ public RobotContainer() {
autoChooser.addOption("Rotate by 90", Autos.rotateTestAuto(drivetrain, 90, false));
autoChooser.addOption("Forward", Autos.driveAuto(drivetrain, +1));
autoChooser.addOption("Backward", Autos.driveAuto(drivetrain, -1));
autoChooser.addOption("Make LEDs blue", new SetLightstripColor(lightStrip, 0, 0, 200));
SmartDashboard.putData("Auto Chooser", autoChooser);

SmartDashboard.putString("Bot Name", Constants.currentBot.toString() + " - " + Constants.serialNumber);
Expand Down Expand Up @@ -193,6 +195,9 @@ public void setUpOperatorController() {
joystick.button(4).onTrue(armToIntake);
joystick.button(5).onTrue(armToAmp);
joystick.button(6).onTrue(armToSpeaker);

joystick.button(7).onTrue(new SetLightstripColor(lightStrip, LightConstants.LED_COLOR_BLUE));
joystick.button(8).onTrue(new SetLightstripColor(lightStrip, LightConstants.LED_COLOR_RED));
} else {
SmartDashboard.putString("Operator Ctrl", "GamePad");
final CommandXboxController xbox = new CommandXboxController(genericHID.getPort());
Expand Down
19 changes: 7 additions & 12 deletions src/main/java/frc/robot/commands/SetLightstripColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,26 @@
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.subsystems.LightStrip;


public class SetLightstripColor extends Command {
private LightStrip lightStrip;

private int r;
private int g;
private int b;
private double pattern;

/**
* Set the color of the robot's lightstrip
*
* @param lightStrip The lightstrip you want to use (there should only be ONE)
* @param r Red level
* @param g Green level
* @param b Blue level
* @param pattern Pattern
*/
public SetLightstripColor(LightStrip lightStrip, int r, int g, int b) {
public SetLightstripColor(LightStrip lightStrip, double pattern) {
this.lightStrip = lightStrip;
this.r = r;
this.g = g;
this.b = b;
this.pattern = pattern;
}

@Override
public void initialize() {
lightStrip.setColor(r, g, b);
System.out.println("*** Command: Selecting pattern " + pattern);
lightStrip.setPattern(pattern);
}

@Override
Expand Down
53 changes: 35 additions & 18 deletions src/main/java/frc/robot/subsystems/LightStrip.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,51 @@
package frc.robot.subsystems;

import edu.wpi.first.wpilibj.AddressableLED;
import edu.wpi.first.wpilibj.AddressableLEDBuffer;
import edu.wpi.first.wpilibj.motorcontrol.Spark;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.Constants.LightConstants;

public class LightStrip extends SubsystemBase {
private AddressableLED ledStrip;
private AddressableLEDBuffer ledBuffer;
/**
* The LED controller PWM signal from 1000-2000us, which is identical to a Spark
* servo. So, we use the Spark class.
* -1 corresponds to 1000us
* 0 corresponds to 1500us
* +1 corresponds to 2000us
*/
private Spark ledStrip;
private double pattern;

public LightStrip(AddressableLED ledstrip) {
/**
* Creates a new LightStrip subsystem.
*
* @param ledstrip The 'spark' representing the Blinkin
*/
public LightStrip(Spark ledstrip) {
ledStrip = ledstrip;
ledBuffer = new AddressableLEDBuffer(LightConstants.LED_QUANTITY);

// Docs say this is an expensive operation so future maintainers should avoid
// modifying this excessibely
ledStrip.setLength(ledBuffer.getLength());
ledStrip.setData(ledBuffer);
}

ledStrip.start();
/**
* Creates a new LightStrip subsystem.
*
* @param pwmPort The port number for the blinkin
*/
public LightStrip(int pwmPort) {
ledStrip = new Spark(pwmPort);
}

public void setColor(int r, int g, int b) {
for (int i = 0; i < ledBuffer.getLength(); i++) {
ledBuffer.setRGB(i, r, g, b);
}
/**
* Sets the blinkin to a pattern
*
* @param pattern Pattern ID to use. Consult section 5 of the blinkin manual.
* @link https://www.revrobotics.com/content/docs/REV-11-1105-UM.pdf
*/
public void setPattern(double pattern) {
this.pattern = pattern;
}

@Override
public void periodic() {
ledStrip.setData(ledBuffer);
// System.out.println("*** Subsystem setting pattern to pattern number " +
// pattern);
ledStrip.set(pattern);
}
}

0 comments on commit 9b77e94

Please sign in to comment.