Skip to content

Commit

Permalink
add boot sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
quackitsquinn committed Apr 1, 2024
1 parent b0f1604 commit 5f67dcc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public static class LightStrips {
public static final int UNDERGLOW_LED_COUNT = 150;

/** The speed of the fade animation. [0, 1] */
public static final double STRIP_FADE_AMOUNT = 0.1;
public static final double STRIP_FADE_AMOUNT = 0.05;

public static final class Colors {
/** The color for the lights when the robot is disabled. */
Expand Down
1 change: 1 addition & 0 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void disabledPeriodic() {}
@Override
public void disabledExit() {
RobotContainer.mailboxPneumatics.retract();
RobotContainer.disabledLights.cancel();
}

@Override
Expand Down
33 changes: 28 additions & 5 deletions src/main/java/frc/robot/commands/lightstrip/DisabledLights.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

package frc.robot.commands.lightstrip;

import edu.wpi.first.wpilibj.util.Color;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.Constants;
import frc.robot.RobotContainer;
Expand All @@ -19,6 +20,9 @@
/** Activates when the robot is disabled. */
public class DisabledLights extends Command {
private AddressableLightStrip robotLights;
private boolean firstStart = true;
private int rainbowTick = 0;
private int ledCount = 1;

/** Creates a new RobotDisabledLights. */
public DisabledLights() {
Expand All @@ -29,18 +33,37 @@ public DisabledLights() {
// Called when the command is initially scheduled.
@Override
public void initialize() {
robotLights.setStripColor(Constants.LightStrips.Colors.DISABLED_COLOR);
robotLights.flush();
if (!firstStart) {
robotLights.setStripColor(Constants.LightStrips.Colors.DISABLED_COLOR);
robotLights.flush();
}
robotLights.startLights();
}

// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {}
public void execute() {
if (firstStart) {
rainbowTick++;
for (int led = 0; led < ledCount; led++) {
robotLights.setColorLight(
led, Color.fromHSV((led + rainbowTick) % 180, 255, rainbowTick - led));
}
robotLights.flush();
if ((rainbowTick >= robotLights.getLength() * 2)) {
firstStart = false;
robotLights.setStripColorRaw(Color.kGhostWhite);
robotLights.setStripColor(Constants.LightStrips.Colors.DISABLED_COLOR);
}
ledCount = Math.min(ledCount + 1, robotLights.getLength());
}
}

// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {}
public void end(boolean interrupted) {
firstStart = false;
}

@Override
public boolean runsWhenDisabled() {
Expand All @@ -50,6 +73,6 @@ public boolean runsWhenDisabled() {
// Returns true when the command should end.
@Override
public boolean isFinished() {
return true;
return false;
}
}
11 changes: 11 additions & 0 deletions src/main/java/frc/robot/subsystems/AddressableLightStrip.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ public void setStripColor(Color color) {
targetStripColor = color;
}

/**
* Directly sets the LED colors with no fade effect.
*
* @param color The color to set the LEDs to.
*/
public void setStripColorRaw(Color color) {
for (int led = 0; led < this.buffer.getLength(); led++) {
this.buffer.setLED(led, color);
}
}

private static double lerp(double v0, double v1, double amount) {
if (v0 == v1) {
return v0;
Expand Down

0 comments on commit 5f67dcc

Please sign in to comment.