Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addressable rgb #176

Merged
merged 37 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ed6ba29
add AddressableLightStrip
quackitsquinn Mar 22, 2024
2490a2d
add some helper methods to AddressableLightStrip
quackitsquinn Mar 22, 2024
d5fea9b
add RobotDisabledLights command
quackitsquinn Mar 22, 2024
6c505c1
Finish RobotDisabledLights
quackitsquinn Mar 22, 2024
186f612
Merge remote-tracking branch 'origin/main' into addressable-rgb
quackitsquinn Mar 22, 2024
d8a707a
typos and bugfix
quackitsquinn Mar 22, 2024
4446c25
Move constants and make the disable lights run
quackitsquinn Mar 22, 2024
887729d
Rename RobotDisabledLights to DisabledLights
quackitsquinn Mar 22, 2024
bdd1c51
thank you vscode for not refactoring
quackitsquinn Mar 22, 2024
25c2535
Merge branch 'main' into addressable-rgb
quackitsquinn Mar 23, 2024
bf9897e
Merge branch 'main' into addressable-rgb
quackitsquinn Mar 27, 2024
84f54c0
update light count
quackitsquinn Mar 27, 2024
089b3ca
add enabled lights and fixed disable lights
quackitsquinn Mar 27, 2024
19d8c2d
add a quick and dirty ish rainbow implementation
quackitsquinn Mar 27, 2024
0364287
Merge remote-tracking branch 'origin/main' into addressable-rgb
quackitsquinn Mar 27, 2024
79383ed
Merge branch 'main' into addressable-rgb
quackitsquinn Mar 29, 2024
805f266
clean up enable light code some
quackitsquinn Mar 30, 2024
6a3dcd9
add color fading
quackitsquinn Apr 1, 2024
189f888
remove weird unicode character that randomly appeared
quackitsquinn Apr 1, 2024
5b63948
led code cleanup
quackitsquinn Apr 1, 2024
c0d5fb1
Remove test thing
quackitsquinn Apr 1, 2024
b0f1604
add getLength to AddressableLightStrip
quackitsquinn Apr 1, 2024
5f67dcc
add boot sequence
quackitsquinn Apr 1, 2024
1eb33f1
refactor constant name
quackitsquinn Apr 1, 2024
03f7409
add setFadeSpeed and resetFadeSpeed
quackitsquinn Apr 1, 2024
0841813
some (hopefully) final tweaks
quackitsquinn Apr 1, 2024
2cc0b8f
fix weird unicode character AGAIN
quackitsquinn Apr 1, 2024
36711af
fix javadoc
quackitsquinn Apr 1, 2024
f9e4935
fix command names
quackitsquinn Apr 1, 2024
7e7d8fc
remove unnecessary thing
quackitsquinn Apr 1, 2024
74c8fc9
fix javadoc pt 2
quackitsquinn Apr 1, 2024
6974d0a
fix javadoc pt 3
quackitsquinn Apr 1, 2024
d1a48e7
small tweaks
quackitsquinn Apr 3, 2024
96c74ba
refactoring
quackitsquinn Apr 3, 2024
f2c6976
more fixes and refactoring
quackitsquinn Apr 3, 2024
754d20a
more fixes and refactoring pt 2
quackitsquinn Apr 4, 2024
a9ab6db
Merge remote-tracking branch 'origin/main' into addressable-rgb
quackitsquinn Apr 4, 2024
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
30 changes: 30 additions & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.pathplanner.lib.util.PIDConstants;
import com.revrobotics.CANSparkBase.IdleMode;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.wpilibj.util.Color;

/**
* The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean
Expand Down Expand Up @@ -234,4 +235,33 @@ public static final class Camera {
/** The camera id for the intake camera. */
public static final int INTAKE_CAMERA_ID = 0;
}

/** The constants for the light strips */
public static class LightStrips {
/** The PWM ID for the underglow light strip */
quackitsquinn marked this conversation as resolved.
Show resolved Hide resolved
public static final int UNDERGLOW_PWM_ID = 0;
quackitsquinn marked this conversation as resolved.
Show resolved Hide resolved

/** The count of LEDs for the underglow light strip. */
quackitsquinn marked this conversation as resolved.
Show resolved Hide resolved
public static final int UNDERGLOW_LED_COUNT = 150;
quackitsquinn marked this conversation as resolved.
Show resolved Hide resolved

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

public static final class Colors {
quackitsquinn marked this conversation as resolved.
Show resolved Hide resolved
/** The color for the lights when the robot is disabled. */
public static final Color DISABLED_COLOR = Color.fromHSV(15, 255, 100);

/** The color for the pulse during the boot sequence. */
public static final Color BOOT_SEQUENCE_PULSE_COLOR = Color.fromHSV(0, 0, 255);
quackitsquinn marked this conversation as resolved.
Show resolved Hide resolved

/** The enable color for when the robot is not on an alliance */
public static final Color ENABLE_COLOR_NO_ALLIANCE = Color.fromHSV(137, 255, 200);

/** The enable color for when the robot is on the blue alliance */
public static final Color ENABLE_COLOR_BLUE_ALLIANCE = Color.fromHSV(120, 255, 200);

/** The enable color for when the robot is on the red alliance */
public static final Color ENABLE_COLOR_RED_ALLIANCE = Color.fromHSV(0, 255, 200);
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void robotPeriodic() {

@Override
public void disabledInit() {
CommandScheduler.getInstance().schedule(RobotContainer.disabledLights);
quackitsquinn marked this conversation as resolved.
Show resolved Hide resolved
RobotContainer.mailboxPneumatics.off();
}

Expand All @@ -44,6 +45,7 @@ public void disabledPeriodic() {}
@Override
public void disabledExit() {
RobotContainer.mailboxPneumatics.retract();
RobotContainer.disabledLights.cancel();
}

@Override
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@
import frc.robot.commands.drive.SetDrivePerspectiveFieldOrientedHeadingSnapping;
import frc.robot.commands.drive.SetDrivePerspectiveRobotOriented;
import frc.robot.commands.drive.ZeroGyro;
import frc.robot.commands.lightstrip.DisabledLight;
import frc.robot.commands.lightstrip.EnabledLight;
import frc.robot.commands.lightstrip.NodeLight;
import frc.robot.commands.mailbox.DeindexNote;
import frc.robot.commands.mailbox.DeployMailbox;
import frc.robot.commands.mailbox.DeployPneumatics;
import frc.robot.commands.mailbox.FireNoteRoutine;
import frc.robot.commands.mailbox.FireNoteRoutineNoLimitSwitch;
import frc.robot.commands.mailbox.RunBelts;
import frc.robot.subsystems.AddressableLightStrip;
import frc.robot.subsystems.Camera;
import frc.robot.subsystems.Climber;
import frc.robot.subsystems.Drive;
Expand Down Expand Up @@ -229,6 +233,11 @@ public class RobotContainer {
public static SetDrivePerspectiveFieldOriented setDrivePerspectiveFieldOriented =
new SetDrivePerspectiveFieldOriented();

/** Singleton instance of {@link AddressableLightStrip} for the whole robot. */
public static AddressableLightStrip robotLights =
new AddressableLightStrip(
Constants.LightStrips.UNDERGLOW_PWM_ID, Constants.LightStrips.UNDERGLOW_LED_COUNT);

/**
* Singleton instance of {@link SetDrivePerspectiveFieldOrientedHeadingSnapping} for the whole
* robot.
Expand Down Expand Up @@ -257,6 +266,15 @@ public class RobotContainer {
/** Singleton instance of {@link ZeroGyro} for the whole robot. */
public static ZeroGyro zeroGyro = new ZeroGyro();

/** Singleton instance of {@link DisabledLight} for the whole robot. */
public static DisabledLight disabledLights = new DisabledLight();

/** Singleton instance of {@link EnableLights} for the whole robot. */
public static EnabledLight enabledLights = new EnabledLight();

/** Singleton instance of {@link NodeLight} for the whole robot. */
public static NodeLight nodeLight = new NodeLight();
quackitsquinn marked this conversation as resolved.
Show resolved Hide resolved
quackitsquinn marked this conversation as resolved.
Show resolved Hide resolved

/*
* ***********************
* * OTHER INSTANCE VARS *
Expand Down Expand Up @@ -286,6 +304,7 @@ public RobotContainer() {
startIntakeCamera.schedule();

drive.setDefaultCommand(driveFieldOrientedHeadingSnapping);
robotLights.setDefaultCommand(enabledLights);
}

private void configureAuto() {
Expand Down
81 changes: 81 additions & 0 deletions src/main/java/frc/robot/commands/lightstrip/DisabledLight.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

/*
* Asimov's Laws:
* The First Law: A robot may not injure a human being or, through inaction, allow a human being to come to harm.
* The Second Law: A robot must obey the orders given it by human beings except where such orders would conflict with the First Law.
* The Third Law: A robot must protect its own existence as long as such protection does not conflict with the First or Second Law.
*/

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;
import frc.robot.subsystems.AddressableLightStrip;

/** Activates the light strip when the robot is disabled. */
public class DisabledLight extends Command {
private AddressableLightStrip robotLights;
private boolean firstStart = true;
private int rainbowTick = 0;
private int ledCount = 1;

/** Creates a new RobotDisabledLights. */
public DisabledLight() {
this.robotLights = RobotContainer.robotLights;
addRequirements(this.robotLights);
}

// Called when the command is initially scheduled.
@Override
public void initialize() {
if (!firstStart) {
robotLights.setStripColor(Constants.LightStrips.Colors.DISABLED_COLOR);
robotLights.flush();
} else {
robotLights.setFadeSpeed(0.01);
}
robotLights.startLights();
}

// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
quackitsquinn marked this conversation as resolved.
Show resolved Hide resolved
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(Constants.LightStrips.Colors.BOOT_SEQUENCE_PULSE_COLOR);
robotLights.setStripColor(Constants.LightStrips.Colors.DISABLED_COLOR);
}
ledCount = Math.min(ledCount + 1, robotLights.getLength());
}
quackitsquinn marked this conversation as resolved.
Show resolved Hide resolved
}

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

@Override
public boolean runsWhenDisabled() {
return true;
}

// Returns true when the command should end.
@Override
public boolean isFinished() {
return false;
}
}
62 changes: 62 additions & 0 deletions src/main/java/frc/robot/commands/lightstrip/EnabledLight.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

/*
* Asimov's Laws:
* The First Law: A robot may not injure a human being or, through inaction, allow a human being to come to harm.
* The Second Law: A robot must obey the orders given it by human beings except where such orders would conflict with the First Law.
* The Third Law: A robot must protect its own existence as long as such protection does not conflict with the First or Second Law.
*/

package frc.robot.commands.lightstrip;

import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.DriverStation.Alliance;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.Constants;
import frc.robot.RobotContainer;
import frc.robot.subsystems.AddressableLightStrip;
import java.util.Optional;

/** Activates the light strip when the robot is enabled. */
public class EnabledLight extends Command {
private AddressableLightStrip robotLights;

/** Creates a new RobotEnabledLights. */
public EnabledLight() {
this.robotLights = RobotContainer.robotLights;
addRequirements(this.robotLights);
}

// Called when the command is initially scheduled.
@Override
public void initialize() {
Optional<Alliance> alliance = DriverStation.getAlliance();
quackitsquinn marked this conversation as resolved.
Show resolved Hide resolved
if (alliance.isPresent()) {
if (alliance.get() == Alliance.Red) {
robotLights.setStripColor(Constants.LightStrips.Colors.ENABLE_COLOR_RED_ALLIANCE);
} else {
robotLights.setStripColor(Constants.LightStrips.Colors.ENABLE_COLOR_BLUE_ALLIANCE);
}
} else {
robotLights.setStripColor(Constants.LightStrips.Colors.ENABLE_COLOR_NO_ALLIANCE);
}
robotLights.flush();
robotLights.startLights();
}

// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {}

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

// Returns true when the command should end.
@Override
public boolean isFinished() {
return true;
}
}
49 changes: 49 additions & 0 deletions src/main/java/frc/robot/commands/lightstrip/NodeLight.java
quackitsquinn marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

/*
* Asimov's Laws:
* The First Law: A robot may not injure a human being or, through inaction, allow a human being to come to harm.
* The Second Law: A robot must obey the orders given it by human beings except where such orders would conflict with the First Law.
* The Third Law: A robot must protect its own existence as long as such protection does not conflict with the First or Second Law.
*/

package frc.robot.commands.lightstrip;

import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.RobotContainer;
import frc.robot.subsystems.AddressableLightStrip;

/** Activates the light strip when the robot has a node. */
public class NodeLight extends Command {
private AddressableLightStrip robotLights;

/** Creates a new RobotNodeLight. */
public NodeLight() {
this.robotLights = RobotContainer.robotLights;
addRequirements(this.robotLights);
}

// Called when the command is initially scheduled.
@Override
public void initialize() {
robotLights.startLights();
}

// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
robotLights.updateRainbow();
}

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

// Returns true when the command should end.
@Override
public boolean isFinished() {
return false;
}
}
Loading
Loading