Skip to content

Commit

Permalink
added a ledSubsystem
Browse files Browse the repository at this point in the history
and made robotState
use it
  • Loading branch information
PotatoBoyH4 committed Mar 12, 2024
1 parent f15ed0c commit d02feeb
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import frc.robot.subsystems.elbow.ElbowSubsystem;
import frc.robot.subsystems.intake.IntakeIOFX;
import frc.robot.subsystems.intake.IntakeSubsystem;
import frc.robot.subsystems.led.LedSubsystem;
import frc.robot.subsystems.magazine.MagazineIOFX;
import frc.robot.subsystems.magazine.MagazineSubsystem;
import frc.robot.subsystems.robotState.RobotStateSubsystem;
Expand Down Expand Up @@ -118,6 +119,7 @@ public class RobotContainer {
private final ElbowSubsystem elbowSubsystem;
private final ShooterSubsystem shooterSubsystem;
private final ClimbSubsystem climbSubsystem;
private final LedSubsystem ledSubsystem;
private final AutoSwitch autoSwitch;

private final XboxController xboxController = new XboxController(1);
Expand Down Expand Up @@ -171,6 +173,7 @@ public RobotContainer() {
shooterSubsystem = new ShooterSubsystem(shooterIO);
intakeSubsystem = new IntakeSubsystem(intakeIO);
magazineSubsystem = new MagazineSubsystem(magazineIO);
ledSubsystem = new LedSubsystem();
climbSubsystem =
new ClimbSubsystem(climbIO, new ClimbRatchetIOServo(), new TrapBarIOServo(), forkIO);

Expand All @@ -186,7 +189,8 @@ public RobotContainer() {
intakeSubsystem,
magazineSubsystem,
superStructure,
climbSubsystem);
climbSubsystem,
ledSubsystem);

driveSubsystem.setRobotStateSubsystem(robotStateSubsystem);
autoSwitch =
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/frc/robot/constants/LedConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package frc.robot.constants;

import edu.wpi.first.wpilibj.util.Color;

public class LedConstants {
public static final int kLedPort = 0; //FIXME led port unknown
public static final int kLedLength = 0; //FIXME led length unknown
public static final Color kBlue = new Color(42, 45, 232);
public static final Color kGreen = new Color(0, 255, 0);
}
98 changes: 98 additions & 0 deletions src/main/java/frc/robot/subsystems/led/LedSubsystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package frc.robot.subsystems.led;

import java.util.Random;
import java.util.Set;

import org.strykeforce.telemetry.measurable.MeasurableSubsystem;
import org.strykeforce.telemetry.measurable.Measure;

import edu.wpi.first.wpilibj.AddressableLED;
import edu.wpi.first.wpilibj.AddressableLEDBuffer;
import edu.wpi.first.wpilibj.util.Color;
import frc.robot.constants.LedConstants;

public class LedSubsystem extends MeasurableSubsystem{

private LedState currState = LedState.OFF;
private AddressableLED led = new AddressableLED(LedConstants.kLedPort);
private AddressableLEDBuffer ledBuffer;

public LedSubsystem() {
ledBuffer = new AddressableLEDBuffer(LedConstants.kLedLength);
led.setLength(ledBuffer.getLength());
led.setData(ledBuffer);
led.start();
}

public LedState getState() {
return currState;
}

private void setState(LedState state) {
currState = state;
}

public void setColor(int r, int g, int b) {
setState(LedState.SOLID);
for (var i = 0; i < ledBuffer.getLength(); i++) {
ledBuffer.setRGB(i, r, g, b);
}
}

public void setColor(Color color) {
setState(LedState.SOLID);
for (var i = 0; i < ledBuffer.getLength(); i++) {
ledBuffer.setLED(i, color);
}
}

public void setGreen() {
setColor(LedConstants.kGreen);
}

public void setBlue() {
setColor(LedConstants.kBlue);
}

public void setFlaming() {
setState(LedState.FLAMING);
}

public void setOff() {
setColor(new Color());
currState = LedState.OFF;
}

@Override
public void periodic() {

switch (currState) {
case FLAMING:
for (var i = 0; i < ledBuffer.getLength(); i++) {
ledBuffer.setRGB(i, 250, (int) (Math.random() * 185), 0);
}
break;
case SOLID:
break;
case OFF:
break;
default:
setOff();
break;
}
}

@Override
public Set<Measure> getMeasures() {
return Set.of(
new Measure("State", () -> getState().ordinal())
);
}

public enum LedState {
OFF,
SOLID,
FLAMING
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import edu.wpi.first.wpilibj.DriverStation.Alliance;
import edu.wpi.first.wpilibj.Preferences;
import edu.wpi.first.wpilibj.Timer;
import frc.robot.constants.MagazineConstants;
import frc.robot.constants.RobotStateConstants;
import frc.robot.constants.ShooterConstants;
import frc.robot.subsystems.climb.ClimbSubsystem;
import frc.robot.subsystems.drive.DriveSubsystem;
import frc.robot.subsystems.intake.IntakeSubsystem;
import frc.robot.subsystems.intake.IntakeSubsystem.IntakeState;
import frc.robot.subsystems.led.LedSubsystem;
import frc.robot.subsystems.magazine.MagazineSubsystem;
import frc.robot.subsystems.magazine.MagazineSubsystem.MagazineStates;
import frc.robot.subsystems.superStructure.SuperStructure;
Expand All @@ -35,6 +37,7 @@ public class RobotStateSubsystem extends MeasurableSubsystem {
private MagazineSubsystem magazineSubsystem;
private SuperStructure superStructure;
private ClimbSubsystem climbSubsystem;
private LedSubsystem ledSubsystem;

private RobotStates curState = RobotStates.IDLE;
private RobotStates nextState = RobotStates.IDLE;
Expand Down Expand Up @@ -75,13 +78,15 @@ public RobotStateSubsystem(
IntakeSubsystem intakeSubsystem,
MagazineSubsystem magazineSubsystem,
SuperStructure superStructure,
ClimbSubsystem climbSubsystem) {
ClimbSubsystem climbSubsystem,
LedSubsystem ledSubsystem) {
this.visionSubsystem = visionSubsystem;
this.driveSubsystem = driveSubsystem;
this.intakeSubsystem = intakeSubsystem;
this.magazineSubsystem = magazineSubsystem;
this.superStructure = superStructure;
this.climbSubsystem = climbSubsystem;
this.ledSubsystem = ledSubsystem;
grabElbowOffsetPreferences();
parseLookupTable();
}
Expand Down Expand Up @@ -224,6 +229,7 @@ public void toIntake() {
superStructure.intake();
// magazineSubsystem.toIntaking();
magazineSubsystem.setEmpty();
ledSubsystem.setFlaming();
setState(RobotStates.TO_INTAKING);
}

Expand Down Expand Up @@ -451,6 +457,7 @@ public void periodic() {

intakeSubsystem.setPercent(0);

ledSubsystem.setGreen();
toStow();
}
if (intakeSubsystem.getState() == IntakeState.HAS_PIECE
Expand Down Expand Up @@ -521,6 +528,9 @@ public void periodic() {

curShot += 1;
hasShootBeamUnbroken = false;
if (isAuto) {
ledSubsystem.setBlue();
}

setState(RobotStates.SHOOTING);
}
Expand All @@ -540,6 +550,7 @@ public void periodic() {
magazineSubsystem.setSpeed(0);

superStructure.stopShoot();
ledSubsystem.setOff();
toIntake();
magazineSubsystem.setEmpty();
}
Expand All @@ -551,6 +562,9 @@ public void periodic() {
// superStructure.slowWheelSpin();
superStructure.stopShoot();
}
if (magazineSubsystem.getSpeed() >= MagazineConstants.kPodiumRumbleSpeed) {
ledSubsystem.setBlue();
}
// if (superStructure.isFinished() && magazineSubsystem.getState() ==
// MagazineStates.SHOOT)
// {
Expand All @@ -569,6 +583,7 @@ public void periodic() {
magazineShootDelayTimer.stop();

superStructure.stopPodiumShoot();
ledSubsystem.setOff();
toStow();
}
break;
Expand Down

0 comments on commit d02feeb

Please sign in to comment.